Kustomize: envFrom not replaced with the generated name of configMapGenerator

Created on 16 Nov 2018  路  8Comments  路  Source: kubernetes-sigs/kustomize

Hi, I have a problem with the configMapGenerator that create a resource name with a Hash suffix that is not replaced in my deployment envFrom value.

I have this kustomization.yaml

resources:
  - servicetest.deploy.yaml
  - servicetest.svc.yaml

commonLabels:
  release: test

configMapGenerator:
  - name: myconfigmap
    literals:
      - ENV=dev
      - HOSTNAME=sandox-dev

I have this servicetest.deploy.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: servicetest
spec:
  replicas: 1
  selector:
    matchLabels:
      app: servicetest
  template:
    metadata:
      labels:
        app: servicetest
    spec:
      containers:
        - name: sandbox
          image: "xxx.amazonaws.com/servicetest:latest"
          envFrom:
            - configMapRef:
                name: myconfigmap
          imagePullPolicy: Always

That results in (after kustomize build) :

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    release: test
  name: servicetest
spec:
  replicas: 1
  selector:
    matchLabels:
      app: servicetest
      release: test
  template:
    metadata:
      labels:
        app: servicetest
        release: test
    spec:
      containers:
      - envFrom:
        - configMapRef:
            name: myconfigmap
        image: xxx.amazonaws.com/servicefrom:latest
        imagePullPolicy: Always
        name: sandbox

The envFrom.configMapRef.name is still set to myconfigmap and has not been replaced with the generated name on the configmap (myconfigmap-xxxxxxx in may case)

Do I miss something?

kinbug

Most helpful comment

@nixsticks This is because of namespace added in the metadata. You can remove namespace: kafkastreams from Deployment and add it to kustomization.yaml

All 8 comments

I have the same issue and couldn't get it to work. Ended up doing this for now:

generatorOptions:
  disableHash: true
configMapGenerator:
- name: configmap-zookeeper
  env: ../../../../env/config/kafka-zookeeper/kafka-zookeeper.env

This functionality seems to have changed when I updated the latest kustomize. Maybe something changed?

This was due to a typo in the name reference transformer configs, which was fixed by #529
The fix is currently available from head. We will release a new version soon.

Awesome thanks, @Liujingfang1

Hi @Liujingfang1, just looking at the PR you reference (#529) it doesn't seem like that fixes the issue shown here -- it seems that the PR fixes a typo for CronJobs but there was no typo for Deployment, which is the type shown here in the example?

I have not had time to get familiar with the Kustomize code, unfortunately, so it's very possible I'm wrong, in which case I am sorry for wasting your time! However, I am commenting because I updated to v1.0.11, which has #529 included, and I am still not seeing the generated hash appended to the configMapRef name. In addition, if I use namePrefix, that is not prepended to the configMapRef name either.

My example is very similar to the one provided above with the addition of a namePrefix.

@nixsticks Can you paste your yaml files here?

base kustomize:

commonLabels:
  env: development

resources:
  - ../../../templates/deployment.yaml

configMapGenerator:
  - name: ks-env
    files:
      - ../common.env

base deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ks-app
  namespace: kafkastreams
spec:
  serviceName: "kafkastreams"
  replicas: 6
  podManagementPolicy: "Parallel"
  template:
    spec:
      containers:
        - envFrom:
          - configMapRef:
              name: ks-env
          name: ks-app

app-specific kustomize:

namePrefix: prism-

commonLabels:
  app: prism

bases:
  - ../../../environments/development/stateless

output:

apiVersion: v1
data:
  common.env: |-
    <redacted>
kind: ConfigMap
metadata:
  labels:
    app: prism
    env: development
  name: prism-ks-env-ff6hm27m2h
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: prism
    env: development
  name: prism-ks-app
  namespace: kafkastreams
spec:
  podManagementPolicy: Parallel
  replicas: 6
  selector:
    matchLabels:
      app: prism
      env: development
  serviceName: kafkastreams
  template:
    metadata:
      labels:
        app: prism
        env: development
    spec:
      containers:
      - envFrom:
        - configMapRef:
            name: prism-ks-env
        image: <redacted>
        name: ks-app

Sorry, I was actually wrong about the namePrefix because it works (at least in 1.0.11), but the hash is still not appended.

@nixsticks This is because of namespace added in the metadata. You can remove namespace: kafkastreams from Deployment and add it to kustomization.yaml

Thank you, @Liujingfang1, I'll try that!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yujunz picture yujunz  路  5Comments

davidsbond picture davidsbond  路  3Comments

bcbrockway picture bcbrockway  路  5Comments

pst picture pst  路  4Comments

bugbuilder picture bugbuilder  路  3Comments