Kustomize: configMapGenerator does not generate hash in deployment

Created on 17 Apr 2019  路  2Comments  路  Source: kubernetes-sigs/kustomize

Hi,

Try to add configMapGenerator to my deployment. Read in manuals that: "For a patch to work, the names in the metadata/name fields must match.". Add metadata/name. Check on simple deployment - everything is Ok. But in my one - does not work.

deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitoring
spec:
  replicas: 2
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      serviceAccountName: grafana
      containers:
      - name: grafana
        image: grafana:latest
        resources:
          limits:
            cpu: 500m
            memory: 512Mi
          requests:
            cpu: 200m
            memory: 512Mi
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /login
            port: 3000
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        ports:
          - containerPort: 3000
        env:
          # Only put environment related config here. Generic Istio config
          # should go in addons/grafana/grafana.ini.
        - name: GF_PATHS_DATA
          value: /data/grafana
        volumeMounts:
        - mountPath: /data/grafana
          name: grafana-data
        - name: grafana-proxy-volume
          mountPath: /var/lib/grafana/plugins/proxy-datasource/plugin.json
          subPath: plugin.json
      priorityClassName: high-priority
      volumes:
      - name: "grafana-proxy-volume"
        configMap:
          name: "grafana-proxy"
          defaultMode: 420
      - name: grafana-data
        emptyDir: {}

and kustomization.yaml:

resources:
- grafana.yaml
configMapGenerator:
- name: grafana-proxy
  files:
    - plugin.json

Looks quite simple, but in result I have:

apiVersion: v1
data:
  plugin.json: |
    {
      "type": "datasource",
      "name": "Proxy",
      "id": "proxy-datasource",
................
    }
kind: ConfigMap
metadata:
  name: grafana-proxy-5fmh2ktd8c
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitoring
spec:
  replicas: 2
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        app: grafana
    spec:
..........
        volumeMounts:
        - mountPath: /data/grafana
          name: grafana-data
        - mountPath: /var/lib/grafana/plugins/proxy-datasource/plugin.json
          name: grafana-proxy-volume
          subPath: plugin.json
      priorityClassName: high-priority
      serviceAccountName: grafana
      volumes:
      - configMap:
          defaultMode: 420
          name: grafana-proxy
        name: grafana-proxy-volume
      - emptyDir: {}
        name: grafana-data

$> kustomize version
Version: {KustomizeVersion:2.0.3 GitCommit:a6f65144121d1955266b0cd836ce954c04122dc8 BuildDate:2019-03-05T20:37:42Z GoOs:linux GoArch:amd64}

Could look at this issue? How could I debug it?

Most helpful comment

Used namespace: monitoring in kustomization.yaml and everything work as expected.

All 2 comments

Reproduce this issue on test configuration:

$> head deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  namespace: monitoring
spec:
  replicas: 3
  template:
    metadata:
      labels:
$> kustomize build .
.....
kind: ConfigMap
metadata:
  name: hello-configmap-97c5gkb7bc
.......
      volumes:
      - configMap:
          name: hello-configmap
        name: configmap-volume

$> head deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  replicas: 3
  template:
    metadata:
      labels:
        deployment: hello
$> kustomize build .
.......
kind: ConfigMap
metadata:
  name: hello-configmap-97c5gkb7bc
........
      volumes:
      - configMap:
          name: hello-configmap-97c5gkb7bc
        name: configmap-volume

As you can see delete namespace from deployment and hash successfully added to manifest.

Used namespace: monitoring in kustomization.yaml and everything work as expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drekle picture drekle  路  4Comments

nabadger picture nabadger  路  4Comments

TechnicalMercenary picture TechnicalMercenary  路  3Comments

davidknezic picture davidknezic  路  3Comments

pst picture pst  路  4Comments