yannh / kubeconform

A FAST Kubernetes manifests validator, with support for Custom Resources!
Apache License 2.0
2.15k stars 121 forks source link

Validate duplicate evar in deployment, pod, job, cronjob spec #188

Closed suryapandian closed 1 year ago

suryapandian commented 1 year ago

Any kind of kubernetes resource with a container could have environment variables with duplicates. Kubeconform validation on the environment variables, finding duplicates and throwing an error at duplciates would be helpful.

---
apiVersion: batch/v1
kind: Job
metadata:
  name: test-job
  namespace: core-banking
spec:
  backoffLimit: 0
  template:
    metadata:
      name: test-job
      namespace: yallow
    spec:
      imagePullSecrets:
        - name: docker-registry
      containers:
        - image: "postgres:13.3"
          name: job
          command:
            - sh
            - -c
            - . /vault/secrets/db_secrets.env && psql -v ON_ERROR_STOP=1 -a -f /sql/script.sql
          volumeMounts:
            - name: sql
              mountPath: /sql
          env:
            - name: PGHOST
              value: "yallow.cluster-csh2ya74kut3.eu-west-1.rds.amazonaws.com"
            - name: PGDATABASE
              value: "yallow-client-settings"
            - name: PGDATABASE
              value: "yallow-client-settings"

In the yaml example above, env has PGDATABASE duplicated, if kubeconform could detect such duplicate evars and throw an error it would be useful. containers is present in deployment, pod, job and cronjob spec.

If someone could point me to the part of codebase where we could add the validation I am interested in taking this up and working on it.

Thank you for the amazing kubeconform, it is useful to us 🙇‍♀️

yannh commented 1 year ago

Hi @suryapandian , could you give an example of a file where kubeconform should throw an error ? Thanks!

suryapandian commented 1 year ago

Hi @yannh Thank you for quick response. Have updated the issue description with the example, please have a look and let me know if it would be possible for kubeconform to make this validation.

yannh commented 1 year ago

I see, in this case no, kubeconform would not be able to figure this out... Maybe check out conftest ? Sorry!

suryapandian commented 1 year ago

that's alright, thank you, will check out.