stackrox / kube-linter

KubeLinter is a static analysis tool that checks Kubernetes YAML files and Helm charts to ensure the applications represented in them adhere to best practices.
https://docs.kubelinter.io/
Apache License 2.0
2.98k stars 234 forks source link

[FEATURE_REQUEST] How to define Environment variables in YAML configuration file #476

Open jeraldsm opened 1 year ago

jeraldsm commented 1 year ago

Description of the problem/feature request It would be nice to have an option in the kube-linter YAML configuration to accept environment variables.

Description of the existing behavior vs. expected behavior In order to define values specific to an application or an environment in the kube-linter YAML configuration file. I need to create separate kube-linter configuration file with the values specific for that use case.

If we can use the YAML configuration as a template with environment variables defined. It would be much easier to pass the variables to the configuration file

  - name: required-label-env
    template: required-label
    params:
      key: ENV
      value: $ENV
    scope:
      objectKinds:
        - DeploymentLike
    remediation: Please set the label ENV in deployment objects

  - name: required-label-app
    template: required-label
    params:
      key: APP
      value: $APP
    scope:
      objectKinds:
        - DeploymentLike
    remediation: Please set the label ENV in deployment objects

Example: kube-linter lint --config .kube-linter.yaml --env APP=EXAMPLEAPP --env ENV=dev

janisz commented 1 year ago

It's a good idea! Although I'm afraid it's quite big as we need to parse yaml and then post process it and keep backward compatibility. Do you know any options that we can use? Maybe there's already a lib that can do that or language we can use (e.g. https://dhall-lang.org/ or https://cuelang.org/)