-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring corev1.EnvVar Flag using pflag.Value #69
Refactoring corev1.EnvVar Flag using pflag.Value #69
Conversation
/assign @coreydaley @SaschaSchwarze0 |
e8a6eef
to
e1035d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
Adding mainly style improvements/suggestions. Othwise signaling that this is a good improvement and can be LGTM-ed by another member of the community.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: adambkaplan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
0d3561e
to
116a375
Compare
Thanks! |
pkg/shp/flags/csv.go
Outdated
// splitKeyValue splits a key-value string with the format "key=value". Returns the key, value, and | ||
// an error if the string is not formatted correctly. | ||
func splitKeyValue(value string) (string, string, error) { | ||
s := strings.Split(value, "=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's is some encoding here? Or should it be SplitN(value, "=", 2) to allow "=" to be on values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Definitely we need to allow a single equal (=
) sign to define the variables. I've updated this part with your suggestion, and included a extra test case to cover the specific scenario. Please consider :-)
62129f3
to
0471db5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting change.
pkg/shp/flags/core_envvar_value.go
Outdated
|
||
// Set receives a string with key-value pairs comma separated. | ||
func (c *CoreEnvVarSliceValue) Set(value string) error { | ||
values, err := readAsCSV(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo we should generally not do this. For multi-value fields we should only support the way where the argument is provided multiple times:
-env key1=value1 -env key2=value2
The reason is that this allows to support ,
in the value without the need for any escaping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @SaschaSchwarze0, indeed we need to handle each entry without having to parse CSV. I've changed the implementation to use stringArray
instead of stringSlice
, so we have have the desired behavior you explained, please consider.
@@ -0,0 +1,35 @@ | |||
package flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the file name, you have three subsequent v
s where I think only two are desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I renamed in the latest set of changes. Thanks!
@@ -0,0 +1,61 @@ | |||
package flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright header missing, though I just notice that many existing files also do not contain one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need to bring some tools from the build-controller to this repository as well 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, opened Ensure files have copyright headers #73.
Implementing pflag.Value interface to represent corev1.EnvVar used in both Build and BuildRun. Co-authored-by: Adam Kaplan <[email protected]>
0471db5
to
1a1d2d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
@@ -0,0 +1,61 @@ | |||
package flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, opened Ensure files have copyright headers #73.
Changes
Implementing
pflag.Value
interface to representcorev1.EnvVar
slice, used in bothBuild
andBuildRun
instances.The objective is to avoid any side effects of using
BuildSpecFromFlags
andBuildRunSpecFromFlags
, those methods should provide a ready-to-useBuildSpec
/BuildRunSPec
instance, so consumers won't need to complete them outside of theflags
package scope.Submitter Checklist
Includes docs if changes are user-facingRelease Notes