zegl / kube-score

Kubernetes object analysis with recommendations for improved reliability and security. kube-score actively prevents downtime and bugs in your Kubernetes YAML and Charts. Static code analysis for Kubernetes.
https://kube-score.com
MIT License
2.72k stars 174 forks source link

Feature request: Detect duplicate environment variables defined #448

Closed ryo-yamaoka closed 2 years ago

ryo-yamaoka commented 2 years ago

Duplicate definitions of environment variables result in unexpected behavior, which we would like to discover. This issue is reported in the Kubernetes repo but has not yet been fixed. https://github.com/kubernetes/kubernetes/issues/58477

Propose behavior

# manifest.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: envvars-deployment
  labels:
    app: envvars
  annotations:
    kube-score/ignore: pod-networkpolicy,container-resources,container-image-pull-policy,container-security-context-privileged,container-security-context-user-group-id,container-security-context-readonlyrootfilesystem,container-ephemeral-storage-request-and-limit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: envvars
  template:
    metadata:
      labels:
        app: envvars
    spec:
      containers:
      - name: envvars
        image: busybox:1.34
        command:
        - /bin/sh
        - -c
        - date; env; tail -f /dev/null
        env:
        - name: SAMPLE_ENV_VAR1
          value: sample1
        - name: SAMPLE_ENV_VAR2
          value: sample2
        - name: SAMPLE_ENV_VAR2 # WANT TO DETECT THIS
          value: sample2-duplicated
$ kube-score score manifest.yaml
apps/v1/Deployment envvars-deployment                                         💥
    [CRITICAL] Pod EnvironmentVariable
        · The pod has duplicated environment variables
            bla bla bla ...
ryo-yamaoka commented 2 years ago

If don't mind, I'd like to implement it myself.

zegl commented 2 years ago

@ryo-yamaoka Not at all, I'll assign this issue to you! :-)