Skip to navigation

Environments and state

View as MarkdownOpen in Claude

Use this page to select an environment and a cluster, understand how state files layer and add an environment of your own. It also explains what each state key controls. To create your first state file, follow Write your state file in the Shared K8s quick start.

Environments

An environment is a named Helmfile profile selected with -e. A state file supplies settings for one installation, such as its namespace and image. Helmfile combines these inputs and maps them to chart values, the settings each chart accepts. A release is one named installation of a chart; this stack contains several releases. The stack reference lists them.

An environment is required. Running without -e fails. The module supplies two example environments, local and dev. You can reuse dev with your own state file or declare your own environment, such as staging (Add your own environment). The supplied examples have these defaults:

Supplied example defaultslocaldev
Clusterkind cluster remediation-orchestrator, through a pinned kube context (below)the current kubectl context, or the one you select
State filenonerequired, one small file
Namespaceremediation-orchestratorfrom the state file
Imageremediation-orchestrator:local, pullPolicy: Neverfrom the state file
CNPG operatorinstalledstate file chooses: install or verify an existing one
Authnone (developmentNone, isolated development only)Dex by default; nvproxy, teleport or oidcProxy through state
ExtrasTemporal UInone by default

Every environment other than local requires authentication and rejects the development settings that local allows.

-e local ignores your current kubectl context. It pins the Helmfile kubeContext, which its presync gates also use, to kind-remediation-orchestrator, because it installs an unauthenticated NRO and a cluster-wide operator. Only --kube-context or the HELMFILE_KUBE_CONTEXT environment variable overrides the pin. A shell prepared for dev with HELMFILE_KUBE_CONTEXT set would send the local stack to that cluster, so unset the variable before you run -e local. Select the cluster covers the other environments and the commands the pin does not reach.

Set the NRO namespace through the top-level state key namespace and the operator namespace through cnpg.operatorNamespace. The stack rejects Helmfile’s --namespace and HELMFILE_NAMESPACE overrides, because they would override both namespaces and break namespace-dependent wiring.

Select the cluster

Plain kubectl and helm commands use the current context of your kubeconfig. For dev and any environment declared without a kubeContext, Helmfile and its presync gates use the current kubectl context too, unless you set an override. Helmfile accepts --kube-context NAME or HELMFILE_KUBE_CONTEXT. When no Helmfile context is set, the presync gates honor Helm’s HELM_KUBECONTEXT.

The guides select the context once with kubectl config use-context and clear both variables, so Helmfile, Helm and kubectl target the same cluster:

# Make the target cluster the current context for kubectl and helm.
kubectl config use-context CONTEXT
# Clear overrides that would send Helmfile or Helm to another cluster.
unset HELMFILE_KUBE_CONTEXT HELM_KUBECONTEXT
# Confirm the selected context.
kubectl config current-context

use-context updates the selected kubeconfig file. Other terminals using that file also switch to the selected cluster. The change is not limited to this shell. To use a different existing kubeconfig file, export KUBECONFIG=/path/to/config before selecting the context. Export it in every other terminal you use as well, including one running a port-forward. Helm and the presync gates both read KUBECONFIG. Native Helmfile’s --kubeconfig reaches only Helm. The gates still inherit KUBECONFIG and inspect the cluster it selects.

The local pin does not change your current context, so plain kubectl and helm commands still need the target cluster selected as the current context. To run local on another local cluster, such as k3d or minikube, pass its context explicitly on every Helmfile command (Use another local cluster).

Where to keep your state file

Keep your state file outside version control, wherever you manage deployment configuration, and pass its path with --state-values-file. The examples use an external location, "$HOME/.config/remediation-orchestrator/dev.yaml". Helmfile resolves a relative --state-values-file from the selected helmfile/ directory, not from your shell, so pass a quoted absolute path. For a file relative to your current directory, write "$PWD/config/dev.yaml". To run from any directory, or to return after an image build, name the Helm module root once while you are in it:

# Record the Helm module root while you are in it.
nro_helm_dir="$PWD"
# Check the dev state from any directory.
helmfile -f "$nro_helm_dir/helmfile" -e dev \
--state-values-file "$HOME/.config/remediation-orchestrator/dev.yaml" build

These are ordinary shell variables. Helmfile does not discover them.

To keep the file in the checkout, use helmfile/state-values/<name>.local.yaml, which Git ignores. Pass it as --state-values-file state-values/<name>.local.yaml, which resolves from helmfile/. With directory-form -f ./helmfile, Helmfile loads every YAML file directly in helmfile/ as a Helmfile, so never save operator YAML directly in that directory. The state-values/ directory and other subdirectories are not scanned.

State layers

The layers merge in this order, and a later layer wins. Maps merge key by key, and lists replace. To find which layer sets a value, read the table from the bottom up:

OrderLayerNotes
1helmfile/environments/defaults.yamlCore defaults, commented
2Environment files listed in the selected declarationThe files the selected environment’s declaration lists: local.yaml or dev.yaml for the supplied examples, or your own (Declare a named environment)
3Each --state-values-file, in command orderRequired for dev; optional for local
4--state-values-set and --state-values-set-stringEach flag takes key=value, or several pairs separated by commas, and applies after every file wherever it appears on the command line. A value that must stay a string, such as a number used as bootstrap.runToken, needs --state-values-set-string

A passthrough is a state map for chart-specific settings, such as remediation-orchestrator.ingress. It supplies chart values rather than adding a state layer. Each passthrough is its release’s last chart-values layer, applied after the values the stack derives from state, and it rejects the keys the stack wires (Tune the charts through passthroughs). For the NRO chart, values apply in this order: the chart’s base values, the values derived from state, then the remediation-orchestrator passthrough.

Add your own environment

local and dev are supplied examples, and dev does not have to be the permanent name of your environment. Each additional installation, such as staging, needs its own state file. The choice is which environment profile that state file builds on:

  • Reuse -e dev when the supplied shared-cluster profile fits and only the installation’s own values differ. This needs no change to the checkout. Each Helmfile command must use the installation’s state file and Kubernetes context.
  • Declare a named environment when you want to select the installation by its own -e name, keep profile defaults in its own environment file, or pin it to one kube context. This edits your copy of the Helm module, which you then maintain.

Reuse dev with its own state file

Each installation can use -e dev with its own state file. Copy the example to "$HOME/.config/remediation-orchestrator/staging.yaml" and fill it in as in Write your state file. Use this installation’s namespace, publicUrl, Temporal namespace and other values, and set environmentId: staging. The state file applies after environments/dev.yaml, so its environmentId overrides the profile’s value:

# Check the staging state against the dev profile.
helmfile -f ./helmfile -e dev --kube-context staging-cluster \
--state-values-file "$HOME/.config/remediation-orchestrator/staging.yaml" build

This approach needs no change to the checkout. Repeat --kube-context staging-cluster and the same state file on every Helmfile command for this installation. Plain kubectl and helm do not read Helmfile’s context flag. Pass kubectl --context staging-cluster and helm --kube-context staging-cluster to them, or first select the context with kubectl config use-context staging-cluster and clear Helm’s override with unset HELM_KUBECONTEXT.

Declare a named environment

A named environment lets you select the installation with -e staging. It can carry its own profile defaults and an optional kube context pin. Helmfile recognizes only the environments that helmfile/helmfile.yaml.gotmpl declares. Adding environments/staging.yaml alone does not register the environment, and -e with an undeclared name fails. Helmfile then reports no releases found that matches specified selector() and environment(<name>).

  1. Declare the environment next to local and dev in the environments: block of helmfile/helmfile.yaml.gotmpl. Keeping environments/dev.yaml in the chain keeps the shared-cluster profile as its base:

    environments:
    # local and dev stay as they are.
    staging:
    # Optional: pin the environment to one kube context.
    # kubeContext: staging-cluster
    values:
    - environments/defaults.yaml
    - environments/dev.yaml
    - environments/staging.yaml
  2. Create helmfile/environments/staging.yaml with the profile’s own values, at least:

    environmentId: staging

    Keep installation-specific values and Secret names in the state file, not the profile.

  3. Write the state file as in Write your state file, outside helmfile/, and pass it as a quoted absolute path:

    # Check the staging state, then render it for review.
    helmfile -f ./helmfile -e staging \
    --state-values-file "$HOME/.config/remediation-orchestrator/staging.yaml" build
    helmfile -f ./helmfile -e staging \
    --state-values-file "$HOME/.config/remediation-orchestrator/staging.yaml" \
    template > /tmp/remediation-orchestrator-staging.yaml
  4. Select the target cluster for plain kubectl and helm, even if you declared a kubeContext pin. That pin affects Helmfile and its presync gates, not those commands. For the example pin above:

    # Match kubectl and Helm to the environment's target cluster.
    kubectl config use-context staging-cluster
    # Clear overrides that could send Helmfile or Helm elsewhere.
    unset HELMFILE_KUBE_CONTEXT HELM_KUBECONTEXT

    Without a pin, select the intended context in the same way (Select the cluster). Then deploy and verify as in Render, deploy and verify, with -e staging and this state file on every Helmfile command.

Every environment other than local gets the shared-cluster checks. Authentication is required, development.allowUnauthenticated and development.allowInsecureHttp are rejected, and every REPLACE_ME placeholder must be replaced. The checks follow the environment name given to -e, so setting environmentId: local in state does not relax them. Running without -e still fails. The declaration changes your copy of the Helm module, so keep it under your own version control and carry it across updates.

State keys

dev, the supplied shared-cluster example, fails without a state file, and so does an environment you declare on the same base. Create one from helmfile/state-values/dev.example.yaml by following Write your state file, and keep it outside helmfile/ (Where to keep your state file).

Before rendering releases, Helmfile validates the core state against helmfile/state.schema.json. Unknown core keys and values of the wrong type fail. Chart-specific values, such as the detailed auth, config and passthrough keys, are checked when each chart renders. An NRO chart value written at the top level instead of under remediation-orchestrator counts as an unknown key.

A shared deployment, whether it uses dev or your own environment, sets or decides these keys:

State keyMeaning
namespaceKubernetes namespace of every release except the CNPG operator. Required
publicUrlBrowser-facing origin, scheme://host[:port]. Required (how NRO uses it)
image.repository, and image.tag or image.digestThe NRO image, shared by NRO and the bootstrap migration Job. Write a digest’s hex digits in lowercase: state validation accepts uppercase, and the NRO chart then rejects it
upstreamImages.temporalAdminToolsOptional mirror or override for the Temporal admin-tools image, which runs the bootstrap Temporal Job and, with managed Temporal, the chart’s schema hook. It must meet the bootstrap chart’s image contract
imagePullSecretsPull Secrets for the NRO image and the managed releases in the namespace. The CNPG operator takes its own, cnpg.values.imagePullSecrets
storageClassStorageClass of both managed databases; "" uses the cluster default
cnpg.installtrue installs the CloudNativePG operator; false, the default, verifies an existing cluster-wide one (Use an existing CloudNativePG operator)
cnpg.operatorNamespace, cnpg.operatorDeploymentOperator namespace and Deployment verified by the presync gate; defaults cnpg-system and cnpg-cloudnative-pg. Also used when installing the operator
database.modemanaged, the default, deploys nro-db; external reads a connection string from your Secret (Use existing backing services)
temporal.mode, temporal.namespacemanaged, the default, deploys Temporal; external uses the server at temporal.address. The Temporal namespace is required in every mode and unique per installation
temporal.bootstrapJobtrue, the default, runs the bootstrap Job that verifies or creates the Temporal namespace and search attributes. false is only for an externally prepared Temporal in verify mode (Skip the bootstrap Temporal Job)
auth.mode, auth.dex.existingSecretHow users sign in (Choose an authentication mode). The default mode, dex, reads its client secret from the named Secret. Every mode except developmentNone also requires auth.siteAdminGroups, with two exceptions: auth.allowEmptySiteAdminGroups: true permits an empty list, and auth.authorizationProvider: none requires an empty list (Authorization)
telemetry.collectormanaged, the default, deploys nro-collector; external sends to your OTLP endpoints; none deploys no collector (Use existing backing services)

defaults.yaml defines every other core key with its default and a comment, including the upstream image mirrors, the deadlines and the bootstrap rerun token. Two maps are the exception: the auth keys other than mode and the config keys other than toml. Both pass to the NRO chart in full and use its defaults (values.yaml). The chart checks them on template, diff and sync. The five passthroughs are described in Tune the charts through passthroughs.

Tune the charts through passthroughs

Five state keys, called passthroughs, reach chart values directly. Each map is the last values layer of its release. Maps merge, and lists replace. The stack protects the keys it wires itself. Setting one fails, and the message names the state key that sets it or says why the value is fixed.

State keyReleaseChart values
remediation-orchestratorremediation-orchestratorNRO chart
cnpg.valuescnpg, when cnpg.install: truecnpg/cloudnative-pg
postgresql.valuesnro-db and nro-temporal-db, whichever is managedcnpg/cluster
temporal.valuesnro-temporal, managed Temporal onlytemporal/temporal
telemetry.valuesnro-collector, managed collector onlyopentelemetry/opentelemetry-collector

Each passthrough rejects these wired keys:

  • remediation-orchestrator: the values the stack sets from top-level state, which are image, imagePullSecrets, environmentId, publicUrl, auth, development, config, telemetry, database.existingSecret, database.connectionStringKey, temporal.address, temporal.namespace and temporal.auth. Also database.migrateOnStartup, because the bootstrap Job is the only migrator, and the reserved extensions. fullnameOverride, database.poolMaxConnections, temporal.uiUrl, temporal.ui and temporal.uiProxy pass through.
  • cnpg.values: names, namespace, image, config.clusterWide, the webhook Service name, webhook.mutating.create, webhook.validating.create, crds.create.
  • postgresql.values: names, namespace, image, instances, storage, pull Secrets, initdb, mode, recovery.
  • temporal.values: names, images, web.enabled, server.replicaCount, server.config.persistence.numHistoryShards, defaultStore and visibilityStore, the connection fields, sql.createDatabase, sql.manageSchema, cassandra and elasticsearch under server.config.persistence.datastores.<default|visibility>, TLS (server.tls, server.config.tls), ports, pull Secrets, server.enabled, server.config.namespaces.create, schema.useHelmHooks, schema.enabled, schema.activeDeadlineSeconds, and admintools.additionalEnv entries named SQL_PLUGIN, SQL_HOST, SQL_PORT, SQL_DATABASE, SQL_USER or SQL_PASSWORD.
  • telemetry.values: names, namespace, image and global.imageRegistry, pull Secrets, OTLP receiver and port, alternateConfig, mode, service.enabled, command.

The authoritative list of protected NRO passthrough keys is validate.nroOwned in _validate.tpl; that check reports every hit at once. The list for the upstream charts is passthrough.protected in _passthrough.tpl. Setting any parent of a protected upstream path to null or a scalar also fails. cnpg.values.imagePullSecrets is allowed because the top-level imagePullSecrets does not reach the operator’s namespace.

No key anywhere in temporal.values may start with helm.sh/ or meta.helm.sh/. The stack owns hook ordering, delete policies, resource retention and release ownership, and chart 1.7.0 writes schema.jobAnnotations after its own hook annotations. The checks do not inspect manifest strings in extraObjects. Store tuning such as maxConns, maxIdleConns, maxConnLifetime, connectAttributes and tls stays open under server.config.persistence.datastores.<store>.sql. Keep credentials out of connectAttributes, because the chart renders it into the server ConfigMap.

Passthroughs carry the same trust as the Helmfile itself. The protections catch an accidental override of a key the stack wires. One indirect channel is guarded: temporal.values.admintools.additionalEnv may not name the six SQL_* variables that point the schema hook at nro-temporal-db (Temporal schema migration). The others stay open, such as other additionalEnv entries, additionalInitContainers or extraObjects manifests, and remain the operator’s responsibility.

These open keys reach a setting that a protected key guards, and no check catches them. Leave them unset:

  • A nonzero temporal.values.server.<service>.replicaCount sets that service’s replica count in place of temporal.replicas.
  • temporal.values.server.frontend.enabled: false removes the nro-temporal-frontend Deployment and Service that NRO and bootstrap dial.
  • telemetry.values.configMap.create: false removes the collector’s generated configuration, and with configMap.existingName beside it the collector reads that ConfigMap instead. The protected alternateConfig guards the same configuration.
  • cnpg.values.config.data.WATCH_NAMESPACE writes WATCH_NAMESPACE into the operator’s configuration ConfigMap, which the config.clusterWide check does not inspect.

Helmfile’s own --set and --values flags take a different path. They pass chart values directly to every release the command selects, after the passthrough. Neither the state checks nor the protected paths see them: -l name=nro-db --set fullnameOverride=x renames the cluster that NRO and bootstrap look for. Reserve them for one-off operator experiments, and keep every lasting change in state.

Configure the NRO chart’s optional Ingress, HTTPRoute, ServiceMonitor, PodDisruptionBudget and Temporal UI proxy through the NRO passthrough. When temporal.web and remediation-orchestrator.temporal.uiProxy.enabled are both true, Helmfile sets TEMPORAL_UI_PUBLIC_PATH=/temporal on the managed UI and points the proxy at nro-temporal-web. To target a different UI, set remediation-orchestrator.temporal.ui.service. Lists replace rather than merge, so in that configuration a temporal.values.web.additionalEnv list must keep {name: TEMPORAL_UI_PUBLIC_PATH, value: /temporal}, or the render fails. The check passes when any entry matches, even if another entry sets a different value, so list the variable once.

Typical uses of the upstream passthroughs:

ChangePassthrough keys
CNPG backupspostgresql.values.backups. Each cluster archives under its own name. Supply credentials through a Secret you create, with backups.secret.create: false and backups.secret.name. Keep backups.endpointCA.create false as well: both clusters render the same values, so the chart would create those objects twice
Temporal server resourcestemporal.values.server.resources
A real exporter in place of the collector’s debug exportertelemetry.values.config.exporters and config.service.pipelines

For example, to give both database clusters more resources:

postgresql:
values:
cluster:
resources:
requests: {cpu: "1", memory: 2Gi}
limits: {memory: 2Gi}

Check each change with template before sync, because the upstream chart, not this stack, validates these values. The chart links in the table open the versions that helmfile/locks/upstream.lock.json pins.

To pull the Temporal and collector images from a mirror, set upstreamImages.* in your state file; defaults.yaml documents each key. The CNPG operator and PostgreSQL images are cnpg.expectedImage and postgresql.image, and the helm test image is remediation-orchestrator.tests.image.

Next steps