Review Helm
Deploys a Helm chart as a GitLab review environment and removes it when the review environment stops.
The component expects a Helm chart artifact under release/charts/ from needs-start, renders any configured values files with environment substitution, and runs helm upgrade --install against the selected namespace. After a successful deploy, it reads the first Ingress host in the namespace and writes it to review.env as CI_ENVIRONMENT_HOST, so GitLab can set the environment URL from the dotenv report.
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/helm@$CI_COMMIT_SHA
inputs:
name: my-app
path: chart
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/review-helm@$CI_COMMIT_SHA
inputs:
release: my-app
namespace: "$CI_ENVIRONMENT_SLUG"
create-namespace: true
value-files:
- chart/values.review.yaml
set-parameters:
- image.tag=$CI_COMMIT_SHA
needs-start:
- job: build:helm:my-app
artifacts: true
Set create-namespace: true when the component should create and delete the namespace for the review release. Keep it false when the namespace lifecycle is managed outside this component.
Helm tests are enabled by default. The component discovers and runs chart resources annotated with helm.sh/hook: test after installation. Set helm-test-enabled: false only when these tests are intentionally managed elsewhere. The start job lists the discovered hooks, captures helm test --logs, and publishes release/review-helm-tests.xml as a GitLab JUnit report. Charts without test hooks produce an empty successful test suite.
Both start and stop jobs capture namespace resources, events, selected workload status fields, Helm release metadata, and the last 300 lines from every pod container under release/review-diagnostics/. The diagnostic status summaries omit workload environment values, command arguments, annotations, release values, rendered manifests, hooks, and release notes. Application logs and events remain unchanged. Start-job failures trigger the same best-effort collection before the job exits, while the stop job records diagnostics before removing the release or namespace.
During installation and upgrade, the start job also polls Pod status and retains current and previous container logs before automatic rollback can remove failed Pods. These files are in start/pre-rollback/. The collector reads only Pods in the selected namespace whose app.kubernetes.io/instance or release label matches the release name. Add one of those labels to Pod templates to retain startup evidence; unlabelled Pods are not included in this early collection.
Early collection retains at most 40 Pod-UID/container pairs, two logs of at most 64 KiB and 300 lines per pair, and one filtered status snapshot. It polls every two seconds between bounded API calls, limits polling to one hour (an in-flight bounded read can finish afterwards), and is stopped and waited for when Helm finishes or the start job exits. Missing Pods and denied diagnostic reads do not change Helm's result. Very short-lived Pods can disappear between polls; this is best-effort evidence retention, not guaranteed audit logging. Automatic rollback and required stop cleanup remain enabled. Logs are application output, not secret-redacted records; do not print credentials from init containers.
Kubernetes service account
The GitLab CI variable KUBECONFIG must point to a service account that can read the target namespace, manage the Helm release resources, and read Ingress resources so the component can discover the review URL.
Raw Helm hook manifests are temporary discovery input only. They are removed before test execution and are not included in the report artifacts. Hook retrieval or parsing failures fail the job instead of reporting an empty successful test suite.
Registry authentication
For private job images and OCI client credentials, follow the central registry authentication guide.
Keep a namespace through delayed tests
When required consumers can outlive the default one-hour namespace TTL, set
create-namespace: true and choose a bounded namespace-lease-minutes value.
Use a catalog release that exposes this input and a namespace unique to the
project and pipeline. With a chart in chart/, for example:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/helm@stable
inputs:
name: my-app
path: chart
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/review-helm@stable
inputs:
release: my-app
namespace: "review-$CI_PROJECT_ID-$CI_PIPELINE_ID"
create-namespace: true
namespace-lease-minutes: 480
needs-start:
- job: build:helm:my-app
artifacts: true
This example gives the namespace an eight-hour TTL. Keep the required stop job after every consumer, including failure paths; the lease is a fallback lifetime, not a replacement for exact cleanup. Match the configured lifetime to the complete deployment, test and scheduling budget. Consumers that have not finished before expiry must fail rather than use a missing environment.
The input accepts whole minutes from 1 to 1440. Its default, 0, retains the
legacy one-hour TTL and namespace reset behavior. A lease records project,
pipeline and expiry metadata atomically at creation. An existing live namespace
owned by the same pipeline is reused without resetting it or extending its
original deadline. A foreign, unowned, expired or malformed existing namespace
is refused without replacement. Namespace read errors also refuse admission.
Leased namespaces set xrow.com/cleanup to false, so older shared janitors
cannot remove them after two hours. The current janitor recognizes their lease
ownership and only collects them after expiry and its existing two-hour age
threshold. Malformed expiry metadata is not collected. The existing TTL
controller still uses ttl-controller.xrow.com/ttl independently; a working TTL
controller is required for the bounded fallback lifetime. Explicit stop cleanup
continues to remove the exact namespace before expiry.
Reclaim a canceled review on the next start
Reclaim runs automatically with create-namespace: true. The default
lease is one hour; use namespace-lease-minutes to change it. Keep the
namespace and environment name stable
across runs of the same review. Use distinct names for different MRs and for
the default branch so they don't contend. Start and stop use the existing
environment name as their shared resource group.
When cancellation skips stop, the next start checks the namespace's owner
and removes it only if the previous pipeline failed or was canceled and
has no live jobs or downstream triggers. Reclaim uses the built-in
CI_JOB_TOKEN; the project must allow it to read pipelines and jobs
(READ_PIPELINES and READ_JOBS with fine-grained permissions). If ownership or pipeline
state can't be verified, start fails without deleting anything. The lease
still handles abandoned namespaces when there is no next start. When available, GITLAB_TOKEN lets
glab add those permissions to an existing fine-grained self entry.
Setup is best effort and does not change default permissions or remove
existing grants. Pipeline reads still use only CI_JOB_TOKEN.
Only namespaces with matching review ownership metadata are reclaimed.
Before upgrading, let older runs and their stop jobs finish; they do not
have the ownership check. Shared namespaces (create-namespace: false) are unchanged. A late
stop from a superseded run leaves the Kubernetes namespace and GitLab
environment alone; GitLab records that stop as a non-blocking warning.
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| context | Kubernetes context to use for the review release. | string | |
| create-namespace | Create and delete the namespace with the Helm test namespace helpers. | false | boolean |
| environment | GitLab environment prefix. | int | string |
| environment-identifier | GitLab environment suffix like `/$CI_PIPELINE_IID-$CI_COMMIT_SHORT_SHA`. CI variables are expanded before use. | string | |
| helm-test-enabled | Run Helm test hooks after the review release is installed and publish their result as JUnit. | true | boolean |
| name | The name prefix for review start and stop jobs. | review-helm | string |
| namespace | Kubernetes namespace for the review release. | $CI_ENVIRONMENT_SLUG | string |
| namespace-lease-minutes | Namespace lease in whole minutes (1–1440). Applies when create-namespace is true. | 60 | number |
| needs-start | Jobs that provide the Helm chart artifact. | [{"job":"build:helm:helm","artifacts":true}] | array |
| needs-stop | Jobs that the stop job depends on. | [] | array |
| release | Helm release name. | $CI_PROJECT_NAME | string |
| rules | The rules to determine when to run the review process. | [{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_COMMIT_TAG =~ $CI_PATTERN_SEMVER","when":"never"},{"when":"always"}] | array |
| set-parameters | Helm --set parameters as key=value entries. | [] | array |
| stage | Pipeline stage for review Helm jobs. | test | string |
| tag | string | ||
| timeout | Timeout for Helm install, upgrade, and stop operations. | 20m | string |
| value-files | Helm values files to pass to the review release. | [] | array |