HelmStorage

class phalanx.storage.helm.HelmStorage(config_storage)

Bases: object

Interface to Helm operations.

Provides an interface to use Helm to create and process templates and to use Helm to install charts in a Kubernetes cluster.

Parameters:

config_storage (ConfigStorage) – Storage object for the Phalanx configuration.

Methods Summary

create(application, description, starter)

Use helm create to create a new application chart.

dependency_update(application, *[, quiet])

Download chart dependencies for an application.

lint_application(application, environment, ...)

Lint an application chart with Helm.

lint_environment(environment)

Lint the top-level chart for an environment with Helm.

repo_add(url, *[, quiet])

Add a Helm chart repository to Helm's cache.

repo_update(*[, quiet])

Update Helm's cache of upstream repository indices.

template_application(application, ...)

Expand an application chart into its Kubernetes resources.

template_environment(environment, ...)

Expand the top-level chart into its Kubernetes resources.

upgrade_application(application, ...[, timeout])

Install or upgrade an application using Helm.

Methods Documentation

create(application, description, starter)

Use helm create to create a new application chart.

Parameters:
  • application (str) – Name of the new application.

  • description (str) – Description of the new application.

  • starter (HelmStarter) – Name of the Helm starter template to use.

Raises:

CommandFailedError – Raised if Helm fails.

Return type:

None

dependency_update(application, *, quiet=False)

Download chart dependencies for an application.

Tell Helm to update any third-party chart dependencies for an application and store them in the charts subdirectory. This is a prerequisite for lint_application, template_application, or upgrade_application.

Assumes that remote repositories have already been refreshed with repo_update and tells Helm to skip that.

Parameters:
  • application (str) – Application whose dependencies should be updated.

  • quiet (bool, default: False) – Whether to suppress Helm’s standard output.

Raises:

CommandFailedError – Raised if Helm fails.

Return type:

None

lint_application(application, environment, values)

Lint an application chart with Helm.

Assumes that helm dependency update has already been run to download any third-party charts. Any output is sent to standard output and standard error, and if Helm fails, a failure message will be printed to standard error.

Parameters:
  • application (str) – Name of the application.

  • environment (str) – Name of the environment in which to lint that application chart, used to select the values-environment.yaml file to add.

  • values (dict[str, str]) – Extra key/value pairs to set, reflecting the settings injected by Argo CD.

Returns:

Whether linting passed.

Return type:

bool

lint_environment(environment)

Lint the top-level chart for an environment with Helm.

Any output is sent to standard output and standard error, and if Helm fails, a failure message will be printed to standard error.

Parameters:

environment (str) – Name of the environment.

Returns:

Whether linting passed.

Return type:

bool

repo_add(url, *, quiet=False)

Add a Helm chart repository to Helm’s cache.

Used primarily to enable Helm linting and templating, since both require any third-party chart repositories be added first.

Annoyingly, Helm requires you to name repositories, but chart configurations don’t include repository names. Automating adding Helm repositories therefore requires making up a name. This uses some arbitrary heuristics that produce consistent names and hopefully won’t produce conflicts.

Parameters:
  • url (str) – Chart repository to add.

  • quiet (bool, default: False) – Whether to suppress Helm’s standard output.

Raises:
Return type:

None

repo_update(*, quiet=False)

Update Helm’s cache of upstream repository indices.

Parameters:

quiet (bool, default: False) – Whether to suppress Helm’s standard output.

Raises:

CommandFailedError – Raised if Helm fails.

Return type:

None

template_application(application, environment, values)

Expand an application chart into its Kubernetes resources.

Runs helm template to expand a chart into its Kubernetes resources for a given environment. Assumes that helm dependency update has already been run to download any third-party charts. Any output to standard error is passed along.

Parameters:
  • application (str) – Name of the application.

  • environment (str) – Name of the environment in which to lint that application chart, used to select the values-environment.yaml file to add.

  • values (dict[str, str]) – Extra key/value pairs to set, reflecting the settings injected by Argo CD.

Returns:

Kubernetes resources created by the chart.

Return type:

str

Raises:

CommandFailedError – Raised if Helm fails.

template_environment(environment, app_of_apps_name)

Expand the top-level chart into its Kubernetes resources.

Runs helm template to expand the top-level chart into its Kubernetes resources for a given environment. Any output to standard error is passed along.

Parameters:
  • environment (str) – Name of the environment for which to expand the chart.

  • app_of_apps_name (str) – Name of the app-of-apps for that environment.

Returns:

Kubernetes resources created by the chart.

Return type:

str

Raises:

CommandFailedError – Raised if Helm fails.

upgrade_application(application, environment, values, *, timeout=datetime.timedelta(seconds=120))

Install or upgrade an application using Helm.

Runs helm upgrade --install to install an application chart in the given environment. Assumes that helm dependency update has already been run to download any third-party charts. Any output to standard error is passed along.

This method bypasses Argo CD and should only be used by the installer to bootstrap the environment.

Parameters:
  • application (str) – Name of the application.

  • environment (str) – Name of the environment in which to lint that application chart, used to select the values-environment.yaml file to add.

  • values (dict[str, str]) – Extra key/value pairs to set.

  • timeout (timedelta, default: datetime.timedelta(seconds=120)) – Fail if the operation takes longer than this. The enforced timeout in Python will be one second longer to allow Helm to time out its own command first.

Raises:
  • CommandFailedError – Raised if Helm fails.

  • CommandTimedOutError – Raised if the command timed out. The timeout is also passed to Helm as an option, so normally the command should fail and raise CommandFailedError instead. This exception means the Helm timeout didn’t work for some reason.

Return type:

None