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

includeTemplates doesn't work #4717

Closed
TobiasWillig opened this issue Jul 20, 2022 · 3 comments · Fixed by #4751 or #4805
Closed

includeTemplates doesn't work #4717

TobiasWillig opened this issue Jul 20, 2022 · 3 comments · Fixed by #4751 or #4805
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@TobiasWillig
Copy link

Describe the bug

Labels aren't added to the pod metadata and the Deployment spec. includeTemplates has no effect.

Files that can reproduce the issue

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
  name: base-kustomization

commonLabels:
  app: test-server

labels:
  - pairs:
      app.kubernetes.io/name: test-server
      app.kubernetes.io/instance: test-server
      app.kubernetes.io/version: ${SERVER_VERSION}
      app.kubernetes.io/component: test
      app.kubernetes.io/part-of: test
      app.kubernetes.io/managed-by: test
      app.kubernetes.io/created-by: test
    includeTemplates: true

resources:
  - deployment.yaml

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-server
spec:
  replicas: 1
  template:
    metadata:
      name: test-server
    spec:
      restartPolicy: Always
      containers:
        - name: test-server
          image: test-server
          ports:
            - containerPort: 8080

Expected output

The Pod should have all defined labels from (commonLabels and labels).

Actual output

The Pod has only the labels from commonLabels.

Kustomize version

{Version:kustomize/v4.5.5 GitCommit:daa3e5e2c2d3a4b8c94021a7384bfb06734bcd26 BuildDate:2022-05-20T20:25:40Z GoOs:linux GoArch:amd64}

Platform

Ubuntu 20.04 LTS inside WSL

@TobiasWillig TobiasWillig added the kind/bug Categorizes issue or PR as related to a bug. label Jul 20, 2022
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jul 20, 2022
@KnVerey
Copy link
Contributor

KnVerey commented Jul 29, 2022

/triage accepted

As a workaround, the bug only seems to occur if the spec.template.metadata.labels does not exist in the first place. Even labels: {} will generate the expected behaviour (this is likely a clue as to what the fix needs to be).

@aibarbetta as the author of this feature, would you be able to look into this bug?

@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 Jul 29, 2022
@aibarbetta
Copy link
Contributor

/assign

@wolfmah
Copy link

wolfmah commented Aug 8, 2022

The culprit is found here:

// merge spec/template/metadata fieldSpec if includeTemplate flag is true
if label.IncludeTemplates {
fss, err = fss.MergeOne(types.FieldSpec{Path: "spec/template/metadata/labels", CreateIfNotPresent: false})
if err != nil {

The CreateIfNotPresent should be true. Though, I don't know if this would make side effect elsewhere. But, if we go by the logic found within commonLabels, it shouldn't be a problem:

- path: spec/template/metadata/labels
create: true
kind: Deployment

As a bonus, the flag shouldn't be hardcoded to only spec/template/metadata/labels, but should include everything that is create: true from the commonLabels field specs: api/konfig/builtinpluginconsts/commonlabels.go

k8s-ci-robot added a commit that referenced this issue Aug 10, 2022
[address #4717] create template/metadata when using includeTemplates if not present
KnVerey added a commit that referenced this issue Aug 10, 2022
@KnVerey KnVerey reopened this Aug 10, 2022
KnVerey added a commit that referenced this issue Aug 10, 2022
Revert "[address #4717] create template/metadata when using includeTemplates if not present"
k8s-ci-robot added a commit that referenced this issue Oct 11, 2022
[address #4717] Re-do create template/metadata when using includeTemplates if not present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
5 participants