yogeshkk / K8sPurger

Hunt Unused Resources In Kubernetes
Apache License 2.0
254 stars 27 forks source link

Add container environment variables use case #4

Closed kk2526 closed 3 years ago

kk2526 commented 3 years ago

https://kubernetes.io/docs/concepts/configuration/secret/#use-cases

Need to take into account below scenario and have it append to UsedSecret/UsedConfigMap function.

    spec:
      containers:
      - env:
        envFrom:
        - configMapRef:
            name: configmap-test
        - secretRef:
            name: secrets-test

below is the block that will get you all the names of those secrets

                if item.env_from is not None:
                    for envfrom in item.env_from:
                        if envfrom.secret_ref is not None:
                            UsedSecret.append(
                                    [envfrom.secret_ref.name, i.metadata.namespace])
yogeshkk commented 3 years ago

@kk2526 That code is to handle below and it handle both configmap and secret

        - name: my_env
           valueFrom:
             secretKeyRef:
                name: secret1
                key: my_env

The link you provided have different way to defining env(refer below). look like it handled different internally in k8s. I will visit that and make modification in script.

      envFrom:
      - secretRef:
          name: mysecret
yogeshkk commented 3 years ago

Hello @kk2526

As thought env and envfrom are handled differently In K8S. I have identified and fixed the issue in the new release v.31. You can try the new version and let me know it goes.

Details about release v.31

yogeshkk commented 3 years ago

I did few test and it work as expected hence closing the issue.