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 labels field to kustomization #3743

Merged
merged 2 commits into from
Mar 24, 2021

Conversation

Shell32-Natsu
Copy link
Contributor

@Shell32-Natsu Shell32-Natsu commented Mar 23, 2021

close #1009

ALLOW_MODULE_SPAN

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 23, 2021
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 23, 2021
@Shell32-Natsu
Copy link
Contributor Author

/retest

if l := labelFromCommonLabels(k.CommonLabels); l != nil {
k.Labels = append(k.Labels, *l)
k.CommonLabels = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider returning an error if labels collide.

Also, should probably add a note as to why this isn't done in PostUnmarshalling (because the edit commands only work with commonLabels, not labels`).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the check

@Shell32-Natsu Shell32-Natsu requested review from monopole and removed request for mortent March 24, 2021 17:42
Copy link
Contributor

@monopole monopole left a comment

Choose a reason for hiding this comment

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

/lgtm
thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: monopole, Shell32-Natsu

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:
  • OWNERS [Shell32-Natsu,monopole]

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 merged commit b0a40e2 into kubernetes-sigs:master Mar 24, 2021
@Shell32-Natsu Shell32-Natsu deleted the label branch March 24, 2021 19:25
@ChristianCiach
Copy link

ChristianCiach commented May 5, 2021

This seems to be buggy with Kustomize 4.1.2, or I do not understand this correctly.

It seems like it makes no difference weather I specify includeSelectors as true or false.

This is part of my kustomization:

labels:
  - pairs:
      app.kubernetes.io/name: 'foo'
    includeSelectors: false
  - pairs:
      app.kubernetes.io/version: 'bar'
    includeSelectors: true

My service.yaml, which doesn't specify any selectors at all...:

apiVersion: v1
kind: Service
metadata:
  name: dashboard
spec:
  ports:
    - port: 8080
      name: frontend
    - port: 8100
      name: backend

... still receives both labels as selectors after building with Kustomize:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: foo
    app.kubernetes.io/version: bar
  name: dashboard
spec:
  ports:
  - name: frontend
    port: 8080
  - name: backend
    port: 8100
  selector:
    app.kubernetes.io/name: foo
    app.kubernetes.io/version: bar

@Shell32-Natsu
Copy link
Contributor Author

@ChristianCiach Please file an issue for it or a PR to add a test case.

@ChristianCiach
Copy link

I am hesitant to file an issue, because I am not sure if...

  • this is actually an issue or a misunderstanding of the feature.
  • this feature is already available in 4.1.2, because it isn't advertised or documented anywhere.

If you confirm that this does indeed look like an issue (and it is supposed to work in 4.1.2), then I will file an issue.

@ChristianCiach
Copy link

This looks like a bug, because with a minimal example it works like expected. Give me some time to check out what part of my kustomization makes this issue appear, then I will file a bug :)

@Shell32-Natsu
Copy link
Contributor Author

Yes it looks like a bug. A good approach (and it's what we recommend) is creating a PR and add a test case for this situation in api/krusty.

@ChristianCiach
Copy link

Thanks for the pointer. Unfortunately, creating a PR is not so easy for me, because I am a professional Java programmer with almost no experience in Go :)

Please accept my issue posted as YAML examples. I am working on it. Thanks again for your quick reply!

@ChristianCiach
Copy link

So, turns out this is (probably) not an issue, just a little pitfall.

In my base-kustomization I have this:

commonLabels:
  app.kubernetes.io/name: 'dashboard'

In my overlay I have this:

labels:
  - pairs:
      app.kubernetes.io/name: 'foo'
    includeSelectors: false
  - pairs:
      app.kubernetes.io/version: 'bar'
    includeSelectors: true

The result is as shown above:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: foo
    app.kubernetes.io/version: bar
  name: dashboard
spec:
  ports:
  - name: frontend
    port: 8080
  - name: backend
    port: 8100
  selector:
    app.kubernetes.io/name: foo
    app.kubernetes.io/version: bar

So, app.kubernetes.io/name: 'foo' is used as a selector even though I specified includeSelectors: false, because the key app.kubernetes.io/name has been defined as commonLabels in the base.

This is probably working as expected, so I will not file an issue.

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

support for common labels that don't get set on selectors
4 participants