Namespace Labels
Diverge allows you to apply custom Kubernetes labels to preview namespaces via the namespaceLabels field in your Environment spec. This is particularly useful for enabling service mesh features like Istio Ambient mode.
Use Case: Istio Ambient Mesh
Section titled “Use Case: Istio Ambient Mesh”Istio’s Ambient mode provides zero-trust mTLS without sidecars. To enable it for preview environments, add the required label:
apiVersion: diverge.io/v1alpha1kind: Environmentmetadata: name: preview-mr-42spec: deploy: mode: delta namespaceLabels: istio.io/dataplane-mode: ambientWhen the controller creates or updates the preview namespace, this label is merged into the namespace’s metadata, automatically enrolling it in Istio Ambient mesh.
Label Protection
Section titled “Label Protection”Labels prefixed with diverge.io/ are protected and cannot be overridden by user-specified namespaceLabels. This ensures that Diverge’s internal labels (used for tracking and lifecycle management) remain intact.
# These are protected — user values will be ignoreddiverge.io/environment: preview-mr-42diverge.io/managed-by: diverge
# These are user-controlledistio.io/dataplane-mode: ambientteam: platformValidation
Section titled “Validation”All label keys and values are validated using Kubernetes’ built-in validation utilities (validation.IsQualifiedName for keys, validation.IsValidLabelValue for values) before being applied. Invalid labels will cause the reconciliation to fail with a descriptive error.
How It Works
Section titled “How It Works”The controller uses CreateOrUpdate to idempotently manage the preview namespace:
- Merges user-specified
namespaceLabelsinto the namespace - Skips any labels with the
diverge.io/prefix (protected) - Applies Diverge’s own tracking labels
- Reports
NamespaceReadycondition on success
