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

Service and Revision labels #342

Merged
merged 19 commits into from
Aug 14, 2019

Conversation

aaron-lerner
Copy link
Contributor

@aaron-lerner aaron-lerner commented Aug 6, 2019

Fixes #328

Proposed Changes

  • Adds a --label (alias -l) flag to set service and revision template labels
  • Allow unsetting env vars and labels

Release Note

Added --label (alias -l) on `kn service create` and `kn service update` commands to set service and revision template labels.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 6, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@aaron-lerner: 1 warning.

In response to this:

Partially addresses #328

Proposed Changes

  • Adds a --label flag to set service-level labels

Release Note

Add --label (alias -l) on `kn service create` and `kn service update` commands to set service-level labels.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/serving/config_changes.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 6, 2019
@knative-prow-robot
Copy link
Contributor

Hi @aaron-lerner. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 6, 2019
@sixolet
Copy link
Contributor

sixolet commented Aug 6, 2019

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 6, 2019
Copy link
Contributor

@sixolet sixolet left a comment

Choose a reason for hiding this comment

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

Looking promising, just a few small suggestions.

pkg/kn/commands/service/configuration_edit_flags.go Outdated Show resolved Hide resolved
pkg/serving/config_changes.go Show resolved Hide resolved
@duglin
Copy link
Contributor

duglin commented Aug 6, 2019

overall looks good. Did you want to support unsetting a label too?

@mattmoor mattmoor removed their request for review August 7, 2019 00:43
@aaron-lerner
Copy link
Contributor Author

Added support for unsetting by passing an empty value, ie --label foo= will remove the label named foo.

@rhuss
Copy link
Contributor

rhuss commented Aug 7, 2019

Added support for unsetting by passing an empty value, ie --label foo= will remove the label named foo.

Does the env var support this, too ? It should be treated the same imo. AFAIK, empty label values, are allowed, too, so not sure how this could be achieved if an empty value means to remove a label.

@rhuss
Copy link
Contributor

rhuss commented Aug 7, 2019

I'm also wondering whether how we could allow setting labels on services, but also on the pod templates. I think both might be useful, and I wonder how the UX for this would look like.

  • --labels for service labels
  • --pod-labels (?) for labels on pods

Or should --labels set the label on both ? Would be the simplest and maybe that's already good enough ?

@rhuss
Copy link
Contributor

rhuss commented Aug 7, 2019

I see service labels are already applied to the generated pods (if I understand that correctly :). So then please forget my last comment :)

Nope, doesn't seem so. So my last question still holds: Apply the label to service itself or the contained the revision template ? I would argue for the latter or both

@rhuss
Copy link
Contributor

rhuss commented Aug 7, 2019

BTW, you see how a revision get the labels from the template, not the sevice itself here: https://github.com/knative/serving/blob/c6860bf7c0663ddbf71d8fa3b48cbfbd9b54c205/pkg/reconciler/configuration/resources/revision.go#L30-L33

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 7, 2019
@aaron-lerner
Copy link
Contributor Author

Changed the unset behavior to match kubectl. So pass the name/key of the environment variable followed by - to unset, e.g. --env NAME- unsets the environment variable with name NAME, same behavior for --label. Let me know if you'd like the changes to --env to be moved out into another PR, I don't think all the changes necessarily need to be entangled in this one, although they are heavily related.

With this, you can now set a label with an empty string and the already existing behavior of setting an environment variable with no value still works.

@rhuss
Copy link
Contributor

rhuss commented Aug 8, 2019

  • --env KEY=value sets EnvVar{Name: "KEY", Value: "value"} (current behavior)

👍

  • --env KEY= sets EnvVar{Name: "KEY"} (current behavior)
  • --env KEY invalid

I would treat both variants as the same, no need to make --env KEY invalid imo.

  • --env KEY- removes the env var matching EnvVar{Name: "KEY", ...}

👍 as this is similar to the the kubectl behaviour.

  • --env KEY-= sets EnvVar{Name: "KEY-"} (current behavior)

This is an invalid env var name, an env var can't end with a -. I would just treat it the same as above, i.e. deleting the env variable.

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

thanks a lot, very nice PR, love it :)

'happy to update the env handling in one sweep here, too.

See some comments inline, the biggest thing that we still have to decide which label to update (i opt for both locations).

pkg/kn/commands/parsing_helper.go Outdated Show resolved Hide resolved
pkg/kn/commands/parsing_helper_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/parsing_helper_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/service_create_test.go Outdated Show resolved Hide resolved
// UpdateServiceLabels updates the labels on a service
func UpdateServiceLabels(service *servingv1alpha1.Service, vars map[string]string) error {
if service.ObjectMeta.Labels == nil {
service.ObjectMeta.Labels = make(map[string]string)
Copy link
Contributor

@rhuss rhuss Aug 8, 2019

Choose a reason for hiding this comment

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

It seems at that point there might as well be separate --revision-label, --service-label , and --label flags. It would be much more explicit both in the documentation and I think code that way. Plus, special characters change (slightly) across different shell environments and if this list is any indication, it may not be worth the time and effort to find and confirm which characters are valid in a reasonable number of shell environments.

This is always a tradeoff between options bloat and being too obfuscated. Currently, there is a tendency to add 1-5 new options per new features, and I'm doing my best to fight against the bloat. At least asking, whether there could be a compromise and whether all those options are needed (e.g. see #345 (comment) or #326 (review) or #282 (review) how to reduce the UX surface and so the cognitive load).

Of course, we should no go over the top, and using special chars like that might be the case here (although ^ and : are safe shell chars so no need to escape).

What's about that compromise: Let's implement --label to label both, service and template and wait on feedback if the other use cases (individual labelling of serving/template) are actually requested ?


From a single feature's PR POV adding 3 new options might not be a big deal, but its the sum which might lead to multi page help outputs which are really overwhelming (especially when alphabetically ordered, and --revision-label, --sevice-label and --label will apear on totally different positions in a list of 50+ options)

pkg/serving/config_changes.go Show resolved Hide resolved
pkg/serving/config_changes_test.go Outdated Show resolved Hide resolved
@navidshaikh
Copy link
Collaborator

--env KEY=value sets EnvVar{Name: "KEY", Value: "value"} (current behavior)
--env KEY= sets EnvVar{Name: "KEY"} (current behavior)
--env KEY- removes the env var matching EnvVar{Name: "KEY", ...}

+1 for support these operations.

--env KEY invalid

We should treat this same as --env KEY=. I agree with @rhuss .

@aaron-lerner
Copy link
Contributor Author

This is an invalid env var name, an env var can't end with a -. I would just treat it the same as above, i.e. deleting the env variable.

I assumed the lack of validation client-side on names and values meant this was being done server-side. However, I am allowed to set an environment variable with a name ending in -. Are you suggesting adding client-side validation to names in this PR? I'm afraid something like that starts to bloat it a bit too much.

@rhuss
Copy link
Contributor

rhuss commented Aug 8, 2019

I assumed the lack of validation client-side on names and values meant this was being done server-side. However, I am allowed to set an environment variable with a name ending in -. Are you suggesting adding client-side validation to names in this PR? I'm afraid something like that starts to bloat it a bit too much.

I just meant that --env VAR- and --env VAR-= should be treated the same, i.e. deleting the variable. No need to do further validation: If the var ends with - then delete it (if present, otherwise ignore)

@aaron-lerner
Copy link
Contributor Author

Updated to have env and label keys passed without values map to empty values rather than throw an error. Additionally, keys that indicate deletion (- suffix) will always attempt to remove the associated env/label, regardless of whether or not a value is included with them.

@aaron-lerner aaron-lerner changed the title Service labels Service and Revision labels Aug 9, 2019
@maximilien
Copy link
Contributor

/retest

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/configuration_edit_flags.go 77.5% 79.5% 2.1
pkg/serving/config_changes.go 75.8% 81.0% 5.2
pkg/util/parsing_helper.go Do not exist 100.0%

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aaron-lerner, maximilien, sixolet

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

@sixolet
Copy link
Contributor

sixolet commented Aug 13, 2019

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2019
@knative-prow-robot knative-prow-robot merged commit 27d8f43 into knative:master Aug 14, 2019
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
* Fix backup Makefile and auth

Apparently "works on my machine" isn't enough.

1. The Makefile was broken, use the current directory for the build
context.
2. Activate the service account (not necessary for gcrane, but necessary
for gsutil).

* Get service account key from env

* For backup image, pass keyfile as first argument
dsimansk added a commit to dsimansk/client that referenced this pull request Feb 6, 2024
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding label
10 participants