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

Generated configmap hash suffix not applied to patched resource when nameSuffix or namePrefix is #2609

Closed
partiallyordered opened this issue Jun 16, 2020 · 4 comments · Fixed by #2847

Comments

@partiallyordered
Copy link
Contributor

partiallyordered commented Jun 16, 2020

Hi all. Firstly and quickly, I'm enjoying kustomize, thank you for your work.

$ kustomize version
Version: {Version:3.3.1 GitCommit:f2ac5a2d0df13c047fb20cbc12ef1a3b41ce2dad BuildDate:unknown GoOs:linux GoArch:amd64}

I also managed to reproduce with a build from master at revision 9b5ce5002a9a183ff77c57fd48b17bd021c2510d.

I'm facing an issue where applying a nameSuffix or namePrefix to an overlay results in a patch not being applied with the configmapKeyRef.name or configMapRef.name I expected.

I reproduce the file structure below, but if you prefer you can obtain the files from: git pull https://github.com/msk-/kustomize-issue
Then

  1. kustomize build in the directory root to see the unexpected output, specifically the absence of a generated suffix on the deployment .spec.template.spec.containers[0].env[0].valueFrom.configMapKeyRef.name and .spec.template.spec.containers[0].envFrom[0].configMapRef.name
  2. modify ./handlers/kustomization.yaml, remove the first line containing the nameSuffix field
  3. kustomize build to see the output I had expected, sans the name nameSuffix

Result of step (1) above:

apiVersion: v1
data:
  MYSQL_DATABASE: db
  MYSQL_USER: user
kind: ConfigMap
metadata:
  annotations: {}
  labels: {}
  name: mysql-h7d4485k9d
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: short-suffix
spec:
  template:
    spec:
      containers:
      - env:
        - valueFrom:
            configMapKeyRef:
              key: MYSQL_DATABASE
              name: mysql
        envFrom:
        - configMapRef:
            name: mysql
        name: handler

Result of step (3) above:

apiVersion: v1
data:
  MYSQL_DATABASE: db
  MYSQL_USER: user
kind: ConfigMap
metadata:
  annotations: {}
  labels: {}
  name: mysql-h7d4485k9d
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: short
spec:
  template:
    spec:
      containers:
      - env:
        - valueFrom:
            configMapKeyRef:
              key: MYSQL_DATABASE
              name: mysql-h7d4485k9d
        envFrom:
        - configMapRef:
            name: mysql-h7d4485k9d
        name: handler

I note that behavior: replace also does not result in the hash suffix being applied. But removing the behavior field (and the "mysql" dependency) does result in a hash suffix on the config map names.

mkdir handlers mysql

cat > handlers/kustomization.yaml << EOF
nameSuffix: -suffix

resources:
  - ./deployment.yaml
EOF

cat > handlers/deployment.yaml << EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: short
spec:
  template:
    spec:
      containers:
      - name: handler
EOF

cat > mysql/kustomization.yaml << EOF
configMapGenerator:
  - name: mysql
    literals:
      - MYSQL_USER=mysql
      - MYSQL_DATABASE=default
EOF

cat > kustomization.yaml << EOF
resources:
  - ./mysql
  - ./handlers

configMapGenerator:
  - name: mysql
    behavior: merge
    literals:
      - MYSQL_DATABASE=db
      - MYSQL_USER=user

patches:
  - target:
      kind: Deployment
      name: s.*
    patch: |-
      kind: Deployment
      metadata:
        name: ignored
      spec:
        template:
          spec:
            containers:
              - name: handler
                envFrom:
                  - configMapRef:
                      name: mysql
                env:
                  - valueFrom:
                      configMapKeyRef:
                        name: mysql
                        key: MYSQL_DATABASE
EOF

Edit: Casting around a little, this may be related: #1301 (comment)

@raynix
Copy link

raynix commented Jun 23, 2020

This still happens as of 3.6.1.

My workaround at the moment is to use a variable to reflect the correct configmap name

@partiallyordered
Copy link
Contributor Author

Thanks for the hint. I'd so happily avoided using any variables so far :(.

@Shell32-Natsu
Copy link
Contributor

Looks like the same as #2717

@monopole
Copy link
Contributor

Thanks to @msk we now have a concrete test for this!

Added to triage at https://github.com/kubernetes-sigs/kustomize/projects/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants