Skip to content
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

Merged

Conversation

otaviof
Copy link
Member

@otaviof otaviof commented Oct 29, 2021

Changes

Implementing pflag.Value interface to represent corev1.EnvVar slice, used in both Build and BuildRun instances.

The objective is to avoid any side effects of using BuildSpecFromFlags and BuildRunSpecFromFlags, those methods should provide a ready-to-use BuildSpec/BuildRunSPec instance, so consumers won't need to complete them outside of the flags package scope.

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

Release Notes

NONE

@otaviof otaviof added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. hackday labels Oct 29, 2021
@otaviof
Copy link
Member Author

otaviof commented Oct 29, 2021

Copy link
Member

@adambkaplan adambkaplan left a 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.

pkg/shp/flags/csv.go Outdated Show resolved Hide resolved
pkg/shp/flags/csv_test.go Outdated Show resolved Hide resolved
pkg/shp/flags/csv_test.go Outdated Show resolved Hide resolved
pkg/shp/flags/csv_test.go Outdated Show resolved Hide resolved
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 29, 2021

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 29, 2021
@otaviof otaviof force-pushed the hackday-envvar-flag branch from 0d3561e to 116a375 Compare October 29, 2021 14:09
@otaviof
Copy link
Member Author

otaviof commented Oct 29, 2021

/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.

Thanks!

// 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, "=")

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

Copy link
Member Author

@otaviof otaviof Oct 30, 2021

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 :-)

@otaviof otaviof force-pushed the hackday-envvar-flag branch 3 times, most recently from 62129f3 to 0471db5 Compare October 30, 2021 05:08
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting change.


// Set receives a string with key-value pairs comma separated.
func (c *CoreEnvVarSliceValue) Set(value string) error {
values, err := readAsCSV(value)
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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 vs where I think only two are desired.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 1, 2021
Implementing pflag.Value interface to represent corev1.EnvVar used in
both Build and BuildRun.

Co-authored-by: Adam Kaplan <[email protected]>
@otaviof otaviof force-pushed the hackday-envvar-flag branch from 0471db5 to 1a1d2d8 Compare November 2, 2021 07:11
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 2, 2021
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 2, 2021
@openshift-merge-robot openshift-merge-robot merged commit d04b9ea into shipwright-io:main Nov 2, 2021
@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.7.0 milestone Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. hackday kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants