KubeconformStorage#

class phalanx.storage.kubeconform.KubeconformStorage(cache_path, kubernetes_version)#

Bases: object

Storage layer for running kubeconform.

kubeconform validates rendered Kubernetes resources against the schemas of the Kubernetes API. This catches problems that neither helm lint nor kube-linter can see, such as a value of the wrong type (an unquoted true as the value of an environment variable, for example) or a missing required field. Kubernetes, and therefore Argo CD, rejects such resources when they are applied.

kubeconform is not run in strict mode, which would also reject unknown fields and duplicate keys, because some existing charts still have them.

The schemas are downloaded on first use and cached on disk, so that linting every application does not download them again for every chart.

Custom resources are not validated, since kubeconform does not have their schemas. They are skipped explicitly rather than left for kubeconform to look up, because kubeconform does not cache a failed lookup and so would otherwise make a network request for each custom resource every time.

Parameters:
  • cache_path (Path) – Directory in which to cache downloaded schemas. It is created if it does not exist.

  • kubernetes_version (str) – Version of Kubernetes whose schemas to validate against.

Methods Summary

validate_application(application, ...)

Run kubeconform on the resources of an application.

Methods Documentation

validate_application(application, environment, resources)#

Run kubeconform on the resources of an application.

Any validation errors are sent to standard output, and a failure message is printed to standard error.

Parameters:
  • application (str) – Name of the application, used in the failure message.

  • environment (str) – Name of the environment, used in the failure message.

  • resources (str) – Rendered Kubernetes resources for the application in that environment, as produced by helm template.

Returns:

Whether the check passed.

Return type:

bool