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

add warning when kubectl set env from secret leads to uppercase #107934

Merged

Conversation

jlsong01
Copy link
Contributor

@jlsong01 jlsong01 commented Feb 3, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

Show warning when kubectl set env from secret leads to uppercase of the secret keys.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1171

Special notes for your reviewer:

some go format refinement included.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 3, 2022
@fedebongio
Copy link
Contributor

/assign @seans3
/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Feb 3, 2022
@jlsong01
Copy link
Contributor Author

jlsong01 commented Feb 4, 2022

/retest

@jlsong01
Copy link
Contributor Author

jlsong01 commented Feb 5, 2022

@seans3 Hey Sean, could you please take a look? Thanks

Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

The concept of adding a warning in kubectl when the environment variable is upper-cased is a good idea. As mentioned in the code, it is cleaner to pull this validation code into its own function. Importantly, you should add a unit test to prove the code works. Since the code outside kubectl that you've modified is only formatting changes, you may want to remove those changes so you won't have to get reviewers from other SIG's involved.

Thanks for taking the initiative on this.

staging/src/k8s.io/kubectl/pkg/cmd/set/set_env.go Outdated Show resolved Hide resolved
@seans3
Copy link
Contributor

seans3 commented Feb 7, 2022

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 7, 2022
@seans3
Copy link
Contributor

seans3 commented Feb 7, 2022

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 7, 2022
@jlsong01 jlsong01 force-pushed the add_lowercase_secret_key_warning branch from f9edb26 to a3122c9 Compare February 8, 2022 10:03
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 8, 2022
@jlsong01 jlsong01 force-pushed the add_lowercase_secret_key_warning branch 2 times, most recently from 48cc18c to 6d514d1 Compare February 8, 2022 11:10
Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

Small nit about exporting, and then we can merge. Thanks for adding tests.

@jlsong01 jlsong01 force-pushed the add_lowercase_secret_key_warning branch from 6d514d1 to feb84cc Compare February 14, 2022 11:09
@jlsong01
Copy link
Contributor Author

jlsong01 commented Feb 14, 2022

Small nit about exporting, and then we can merge. Thanks for adding tests.

Sorry, I may not get your point. Do you mean change KeyToEnvName as keyToEnvName, to make it as a non-exported method? I have updated it according to my assumption.

If my assumption is wrong, please let me know and I will rework it :-)

@jlsong01
Copy link
Contributor Author

/retest

Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 16, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jlsong01, seans3

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 16, 2022
@k8s-ci-robot k8s-ci-robot merged commit 400b1de into kubernetes:master Feb 16, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 16, 2022
func (o *EnvOptions) keyToEnvName(key string) string {
envName := strings.ToUpper(validEnvNameRegexp.ReplaceAllString(key, "_"))
if envName != key {
fmt.Fprintf(o.ErrOut, "warning: key %s transferred to %s\n", key, envName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these end up rendered similarly to the way https://kubernetes.io/blog/2020/09/03/warnings/ explains? (colored yellow, and with an initial capital W)?

Copy link
Contributor Author

@jlsong01 jlsong01 Feb 16, 2022

Choose a reason for hiding this comment

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

No, it's just normal font color, without colored yellow and an Initial capital W.

The warning style exists in several places. If you search with fmt.Fprintf(o.ErrOut, "warning: xxxx, you can find them.

Do we need coordinate them to the way as you mentioned? If so, I am glad to issue another PR to do the cleanup

Copy link
Contributor

Choose a reason for hiding this comment

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

[cleanup]

Sounds good to me. How about first filing a kubectl issue to track the work? See https://github.com/kubernetes/kubectl/issues/new/choose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, track issue first :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show warning when kubectl set env from secret leads to uppercase of the secret keys
6 participants