kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
11.05k stars 2.25k forks source link

ConfigMap generated hashes don't get replaced when using replacements #4475

Open Shalucik opened 2 years ago

Shalucik commented 2 years ago

Describe the bug

I'm trying to replace vars with replacements. I have a var that is used to give an Deployments env value the name of a ConfigMap created by a configMapGenerator

When using replacements for this, the env value is replaced without the generated hash suffix

Files that can reproduce the issue

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml

configMapGenerator:
  - name: test

replacements:
  - source:
      kind: ConfigMap
      name: test
      fieldPath: metadata.name
    targets:
      - select:
          kind: Deployment
          name: test
        fieldPaths:
          - spec.template.spec.containers.[name=test].env.[name=test].value

deployment.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: test
spec:
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
        - name: test
          env:
            - name: test
              value: REPLACE

Expected output

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-6ct58987ht
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - env:
        - name: test
          value: test-6ct58987ht
        name: test

Actual output

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-6ct58987ht
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - env:
        - name: test
          value: test
        name: test

Kustomize version

4.5.2

Platform

Linux

Additional context

natasha41575 commented 2 years ago

Went to add a test for this, and realized one already exists! There is an older issue that ended up not getting addressed due to lack of bandwidth (https://github.com/kubernetes-sigs/kustomize/issues/4034). In general, I agree that replacements would ideally keep track of name references. I will see if I have the bandwidth to work on this in the next few weeks.

/triage accepted

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

natasha41575 commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

sallylyen commented 2 years ago

hi, I was wondering if anyone was working on this issue?

natasha41575 commented 1 year ago

We had a discussion quite a while ago discussing name references in replacements, and concluded that with the current implementation of name references, doing this in replacements is impractical. I think we need to think more about this, as this ties in with some discussion about rewriting the way we do name references and fieldspecs.

Using the name reference transformer directly as suggested here may help.

/triage under-consideration

dornimaug commented 1 year ago

What's the status? Kustomize v5.0.0 was released in February officially deprecating vars, but replacements still lack this essential functionality.

barakatintel commented 1 year ago

facing the same issue kustomize replaces config map generator hashes for cronjob, but does not do that for deployment

k8s-triage-robot commented 7 months ago

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

purvaldur commented 2 months ago

Is any work being done on this? If not, is anything planned at all to address this?

I'd like to avoid using vars which is deprecated but replacements which was supposed to "replace" it doesn't have nearly the same functionality.

solteranis commented 2 months ago

+1 for this. We too experience the same issues, and will prevent us from upgrading kustomize at this point. Is there any accepted/documented work arounds?

sandeeprudraraju commented 2 months ago

How is this implemented using vars?

replacements: