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

[Address #3937] Add labels to template/metadata if includeTemplates is true #4209

Merged
merged 8 commits into from May 5, 2022

Conversation

aibarbetta
Copy link
Contributor

@aibarbetta aibarbetta commented Sep 27, 2021

Fix #3937

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 27, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @aibarbetta. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 27, 2021
@aibarbetta
Copy link
Contributor Author

/retitle [Fix #3937] Add labels to template/metadata if includeSelectors is false

@k8s-ci-robot
Copy link
Contributor

@aibarbetta: Re-titling can only be requested by trusted users, like repository collaborators.

In response to this:

/retitle [Fix #3937] Add labels to template/metadata if includeSelectors is false

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.

@aibarbetta aibarbetta changed the title [Fixes #3937] Add labels to template/metadata if includeSelectors is false [Fix #3937] Add labels to template/metadata if includeSelectors is false Sep 27, 2021
@aibarbetta aibarbetta changed the title [Fix #3937] Add labels to template/metadata if includeSelectors is false [Address #3937] Add labels to template/metadata if includeSelectors is false Sep 27, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Sep 27, 2021
@natasha41575
Copy link
Contributor

/ok-to-test
/lgtm

@k8s-ci-robot k8s-ci-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 Nov 1, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 1, 2021
@natasha41575
Copy link
Contributor

/test all

@natasha41575 natasha41575 removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 1, 2021
@@ -70,6 +70,7 @@ spec:
metadata:
labels:
a: b
c: d
Copy link
Contributor

Choose a reason for hiding this comment

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

why does foo: bar not show up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this test, /app/deployment.yaml is:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  template:
    spec:
      containers:
      - name: my-deployment
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
---
apiVersion: example.dev/v1
kind: MyCRD
metadata:
  name: crd

^here the pod template has no metadata section. But apparently when kustomize runs and adds the a: b label, it creates the pod template metadata section. (a: b pair is configured with includeSelectors: true)

- pairs:
    a: b
  includeSelectors: true

After that, the rest of the labels are applied in metadata and template/metadata as expected. The pair foo: bar is declared before a: b therefore it never gets added to template/metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@natasha41575 I fixed the test by completing the initial deployment.yaml, as I believe selector and template/metadata are both required fields of the Deployment kind. Let me know if this is correct

@k8s-ci-robot
Copy link
Contributor

@aibarbetta: This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

@natasha41575 natasha41575 added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 8, 2021
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 15, 2021

CLA Signed

The committers are authorized under a signed CLA.

@natasha41575
Copy link
Contributor

natasha41575 commented Jan 21, 2022

Giving this a little more thought, and though I agree that this is desired behavior, it is a backwards incompatible change and I'm not sure what we can do that at the moment.

To maintain backwards compatibility, I think it would be best to include only metadata/labels by default when includeSelectors is false as it currently does, and perhaps add a new field includeTemplate that is false by default, but when set will also apply labels to spec/template/metadata/labels.

@aibarbetta aibarbetta changed the title [Address #3937] Add labels to template/metadata if includeSelectors is false [Address #3937] Add labels to template/metadata if includeTemplates is true Jan 31, 2022
@aibarbetta
Copy link
Contributor Author

Giving this a little more thought, and though I agree that this is desired behavior, it is a backwards incompatible change and I'm not sure what we can do that at the moment.

To maintain backwards compatibility, I think it would be best to include only metadata/labels by default when includeSelectors is false as it currently does, and perhaps add a new field includeTemplate that is false by default, but when set will also apply labels to spec/template/metadata/labels.

thanks for the review @natasha41575, I added the includeTemplates flag, let me know if it looks good

@aibarbetta
Copy link
Contributor Author

@natasha41575 @monopole changes done, can you please review? 🙏

@aibarbetta
Copy link
Contributor Author

@natasha41575 can you review please? 🙏

Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Just a question about why we are changing a test.

Also, it would be good to get @KnVerey's input on the syntax. @KnVerey this PR proposes

labels:
- pairs:
    a: b
  includeSelectors: true # this already exists, and adds all the fieldSpecs from commonLabels
- pairs
    c: d
  includeTemplates: true # new field which will add the label to pod specs, but not matchLabels

@natasha41575
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 14, 2022
if err != nil {
return nil, err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It won't let me comment on it, but the linter is complaining about line 292 below. You can either wrap the error or add //nolint:wrapcheck to the end of the line.

It would probably be better to use errors.Wrap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrap added

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems there was also a failure downloading a module here, can we re-run?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why the line number is wrong, but I think it is actually complaining about L249. It shouldn't complain about existing code, and the signature of the error in question is func (sigs.k8s.io/kustomize/api/types.FsSlice).MergeOne(x sigs.k8s.io/kustomize/api/types.FieldSpec) (sigs.k8s.io/kustomize/api/types.FsSlice, error).

Regardless, please rebase the PR. We've made major improvements to the linter config since the commit it is current based on, and I'd like to make sure this runs with the latest config before merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR is rebased, I wrapped the error in that line and ran the unit tests locally, can we re-run? 🙏

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 14, 2022
@natasha41575
Copy link
Contributor

Rerunning the tests!

@natasha41575
Copy link
Contributor

/lgtm

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

Rerunning the tests!

@natasha41575 this is weird, it failed with the same lint error https://github.com/kubernetes-sigs/kustomize/pull/4209/files#annotation_3280759392 did I wrap it correctly?

@@ -281,7 +289,7 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func(
p := f()
err = kt.configureBuiltinPlugin(p, c, bpt)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to configure transformer")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add // nolint:wrapcheck to the end of this line to bypass the lint error. I'm not sure why it's still failing.

@KnVerey
Copy link
Contributor

KnVerey commented May 4, 2022

Also, it would be good to get @KnVerey's input on the syntax. @KnVerey this PR proposes

The syntax makes sense to me. 👍
Can you please update the docs as well?

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 5, 2022
aibarbetta added a commit to aibarbetta/cli-experimental that referenced this pull request May 5, 2022
@aibarbetta
Copy link
Contributor Author

Also, it would be good to get @KnVerey's input on the syntax. @KnVerey this PR proposes

The syntax makes sense to me. 👍 Can you please update the docs as well?

I opened a PR to add doc here: kubernetes-sigs/cli-experimental#268

@natasha41575
Copy link
Contributor

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aibarbetta, natasha41575

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 May 5, 2022
@k8s-ci-robot k8s-ci-robot merged commit 5948f6a into kubernetes-sigs:master May 5, 2022
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

labels' includeSelectors doesn't do what it implies
4 participants