Skip to content

Commit 42c8c86

Browse files
KRA-1027 - change release name generation to avoid conflicts (#156)
* chore: moved cdc specific functions from runtime to internal library * feat: implement deterministic release name generation to avoid conflicts * chore: update deps * docs: update Helm release name logic to avoid conflicts in different namespaces * feat: enhance release name generation to handle missing UID by generating a random suffix * refactor: remove logging dependency from handler and update context usage in HTTP tracing * chore: update unstructured-runtime dependency to v0.3.0 * fix: update tracer initialization to use verbose mode based on metadata
1 parent 682d6d7 commit 42c8c86

12 files changed

Lines changed: 375 additions & 244 deletions

File tree

README.md

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ The composition-dynamic-controller is an operator that is instantiated by the [c
33

44
## Summary
55

6-
- [Summary](#summary)
7-
- [Architecture](#architecture)
8-
- [Overview](#overview)
9-
- [Examples](#examples)
10-
- [Configuration](#configuration)
6+
- [Composition Dynamic Controller](#composition-dynamic-controller)
7+
- [Summary](#summary)
8+
- [Architecture](#architecture)
9+
- [Workflow](#workflow)
10+
- [Composition Dynamic Controller (CDC) \& Chart Inspector: Secure Helm Lifecycle Management](#composition-dynamic-controller-cdc--chart-inspector-secure-helm-lifecycle-management)
11+
- [Core CDC Workflow (with Chart Inspector Integration)](#core-cdc-workflow-with-chart-inspector-integration)
12+
- [Key Capabilities Enabled by This Collaboration](#key-capabilities-enabled-by-this-collaboration)
13+
- [Why This Architecture Matters](#why-this-architecture-matters)
14+
- [Real-World Example: Handling a Breaking Chart Change](#real-world-example-handling-a-breaking-chart-change)
15+
- [Helm Release Name Logic](#helm-release-name-logic)
16+
- [Prior Versions (\<= 0.19.9)](#prior-versions--0199)
17+
- [Subsequent Versions (\>= 0.20.0)](#subsequent-versions--0200)
18+
- [Composition Dynamic Controller Values Injection](#composition-dynamic-controller-values-injection)
19+
- [About the `gracefullyPaused` value](#about-the-gracefullypaused-value)
20+
- [Configuration](#configuration)
21+
- [Operator Env Vars](#operator-env-vars)
22+
1123

1224

1325
## Architecture
@@ -18,11 +30,11 @@ The composition-dynamic-controller is an operator that is instantiated by the [c
1830

1931
![composition-dynamic-controller State Diagram](_diagrams/composition-dynamic-controller-flow.png "composition-dynamic-controller State Diagram")
2032

21-
### **Composition Dynamic Controller (CDC) & Chart Inspector: Secure Helm Lifecycle Management**
33+
### Composition Dynamic Controller (CDC) & Chart Inspector: Secure Helm Lifecycle Management
2234

2335
The **Composition Dynamic Controller (CDC)** is a specialized Kubernetes operator that orchestrates the end-to-end lifecycle of Krateo compositions. Acting as the reconciliation engine for Composition custom resources, it bridges declarative application definitions with Helm’s packaging system through intelligent automation. The **Chart Inspector** serves as its "safety advisor," enabling proactive decision-making via dry-run analysis.
2436

25-
#### **Core CDC Workflow (with Chart Inspector Integration)**
37+
#### Core CDC Workflow (with Chart Inspector Integration)
2638
1. **Reconciliation Trigger**
2739
- Watches for changes to `Composition` CRs or Helm chart versions.
2840
- Invokes the **Chart Inspector** to simulate installations/upgrades *before* execution.
@@ -43,7 +55,7 @@ The **Composition Dynamic Controller (CDC)** is a specialized Kubernetes operato
4355

4456
---
4557

46-
### **Key Capabilities Enabled by This Collaboration**
58+
### Key Capabilities Enabled by This Collaboration
4759

4860
| **Feature** | **CDC’s Role** | **Chart Inspector’s Contribution** |
4961
|----------------------------|-----------------------------------------|----------------------------------------------------|
@@ -55,7 +67,7 @@ The **Composition Dynamic Controller (CDC)** is a specialized Kubernetes operato
5567

5668
---
5769

58-
### **Why This Architecture Matters**
70+
### Why This Architecture Matters
5971
1. **Safety Net**
6072
- The Chart Inspector’s dry-run prevents "helm surprises" (e.g., undeclared CRD creations or namespace pollution).
6173
- Example: Blocks a chart upgrade if the new version requires a `ClusterRole` the CDC isn’t authorized to manage.
@@ -70,7 +82,7 @@ The **Composition Dynamic Controller (CDC)** is a specialized Kubernetes operato
7082

7183
---
7284

73-
### **Real-World Example: Handling a Breaking Chart Change**
85+
### Real-World Example: Handling a Breaking Chart Change
7486
1. **Scenario**: A Helm chart v1.2.0 introduces a new `CustomResourceDefinition` (CRD).
7587
2. **CDC+Inspector Flow**:
7688
- **Dry-run** detects the new CRD and its required API group permissions.
@@ -79,6 +91,33 @@ The **Composition Dynamic Controller (CDC)** is a specialized Kubernetes operato
7991
3. **Result**: Zero downtime; no "helm upgrade failed: CRD missing" errors.
8092

8193

94+
---
95+
96+
## Helm Release Name Logic
97+
98+
### Prior Versions (<= 0.19.9)
99+
100+
For versions up to 0.19.9, the **`composition-dynamic-controller`** used the following logic to determine the **Helm release name** associated with a composition resource:
101+
102+
1. If the **label** `krateo.io/release-name` is set on the composition resource, its value is used as the Helm release name.
103+
2. Otherwise, the **composition resource name** is used as the Helm release name.
104+
105+
---
106+
107+
### Subsequent Versions (>= 0.20.0)
108+
109+
Starting from version 0.20.0, the **`composition-dynamic-controller`** uses the following logic to determine the Helm release name associated with a composition resource:
110+
111+
1. If the **annotation** `krateo.io/release-name` is set on the composition resource, its value is used as the Helm release name.
112+
2. Otherwise, the release name is composed as follows: **`{composition.metadata.name}-{composition.metadata.uid[:8]}`**.
113+
114+
**N.B.:** From this version onward, the `metadata.name` field of the composition cannot exceed **44 characters**. This is because the UID suffix adds **9 characters** to the release name (the hyphen `-` plus the 8 characters of the UID), and Helm release names cannot exceed **53 characters** in total.
115+
116+
This change was implemented to avoid conflicts when multiple resources belonging to the `composition.krateo.io` group with the same `metadata.name` are created in **different namespaces**.
117+
118+
---
119+
120+
82121
## Composition Dynamic Controller Values Injection
83122

84123
The composition-dynamic-controller inject labels and values into the installed resources and in the helm chart release values. This values contains informations about the composition resource associated with the helm release.

go.mod

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ go 1.25.0
44

55
require (
66
github.com/Masterminds/semver v1.5.0
7-
github.com/Masterminds/semver/v3 v3.3.0
7+
github.com/Masterminds/semver/v3 v3.4.0
88
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
99
github.com/go-logr/logr v1.4.3
1010
github.com/gobuffalo/flect v1.0.3
1111
github.com/golang/mock v1.6.0
1212
github.com/krateoplatformops/plumbing v0.7.2
13-
github.com/krateoplatformops/unstructured-runtime v0.2.8
13+
github.com/krateoplatformops/unstructured-runtime v0.3.0
1414
github.com/pkg/errors v0.9.1
15-
github.com/spf13/pflag v1.0.7
16-
github.com/stretchr/testify v1.10.0
17-
helm.sh/helm/v3 v3.18.6
18-
k8s.io/api v0.34.1
19-
k8s.io/apiextensions-apiserver v0.33.3
20-
k8s.io/apimachinery v0.34.1
21-
k8s.io/cli-runtime v0.34.0
22-
k8s.io/client-go v0.34.1
15+
github.com/spf13/pflag v1.0.10
16+
github.com/stretchr/testify v1.11.1
17+
helm.sh/helm/v3 v3.19.2
18+
k8s.io/api v0.34.2
19+
k8s.io/apiextensions-apiserver v0.34.2
20+
k8s.io/apimachinery v0.34.2
21+
k8s.io/cli-runtime v0.34.2
22+
k8s.io/client-go v0.34.2
2323
sigs.k8s.io/e2e-framework v0.6.0
2424
sigs.k8s.io/kustomize/kyaml v0.20.1
2525
sigs.k8s.io/yaml v1.6.0
@@ -38,17 +38,17 @@ require (
3838
github.com/blang/semver/v4 v4.0.0 // indirect
3939
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4040
github.com/chai2010/gettext-go v1.0.2 // indirect
41-
github.com/containerd/containerd v1.7.27 // indirect
41+
github.com/containerd/containerd v1.7.29 // indirect
4242
github.com/containerd/errdefs v1.0.0 // indirect
4343
github.com/containerd/log v0.1.0 // indirect
4444
github.com/containerd/platforms v0.2.1 // indirect
45-
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
45+
github.com/cyphar/filepath-securejoin v0.6.0 // indirect
4646
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
4747
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
4848
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
4949
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
5050
github.com/fatih/color v1.18.0 // indirect
51-
github.com/fsnotify/fsnotify v1.7.0 // indirect
51+
github.com/fsnotify/fsnotify v1.9.0 // indirect
5252
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
5353
github.com/go-errors/errors v1.5.1 // indirect
5454
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
@@ -106,35 +106,35 @@ require (
106106
github.com/shopspring/decimal v1.4.0 // indirect
107107
github.com/sirupsen/logrus v1.9.3 // indirect
108108
github.com/spf13/cast v1.7.0 // indirect
109-
github.com/spf13/cobra v1.9.1 // indirect
109+
github.com/spf13/cobra v1.10.1 // indirect
110110
github.com/stretchr/objx v0.5.2 // indirect
111111
github.com/twmb/murmur3 v1.1.8 // indirect
112112
github.com/vladimirvivien/gexe v0.4.1 // indirect
113113
github.com/x448/float16 v0.8.4 // indirect
114114
github.com/xlab/treeprint v1.2.0 // indirect
115-
go.opentelemetry.io/otel v1.33.0 // indirect
116-
go.opentelemetry.io/otel/trace v1.33.0 // indirect
115+
go.opentelemetry.io/otel v1.35.0 // indirect
116+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
117117
go.yaml.in/yaml/v2 v2.4.2 // indirect
118118
go.yaml.in/yaml/v3 v3.0.4 // indirect
119-
golang.org/x/crypto v0.40.0 // indirect
120-
golang.org/x/net v0.41.0 // indirect
121-
golang.org/x/oauth2 v0.28.0 // indirect
122-
golang.org/x/sync v0.16.0 // indirect
123-
golang.org/x/sys v0.34.0 // indirect
124-
golang.org/x/term v0.33.0 // indirect
125-
golang.org/x/text v0.27.0 // indirect
126-
golang.org/x/time v0.9.0 // indirect
127-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
128-
google.golang.org/grpc v1.68.1 // indirect
119+
golang.org/x/crypto v0.45.0 // indirect
120+
golang.org/x/net v0.47.0 // indirect
121+
golang.org/x/oauth2 v0.30.0 // indirect
122+
golang.org/x/sync v0.18.0 // indirect
123+
golang.org/x/sys v0.38.0 // indirect
124+
golang.org/x/term v0.37.0 // indirect
125+
golang.org/x/text v0.31.0 // indirect
126+
golang.org/x/time v0.12.0 // indirect
127+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
128+
google.golang.org/grpc v1.72.1 // indirect
129129
google.golang.org/protobuf v1.36.5 // indirect
130130
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
131131
gopkg.in/inf.v0 v0.9.1 // indirect
132132
gopkg.in/yaml.v3 v3.0.1 // indirect
133-
k8s.io/apiserver v0.33.3 // indirect
134-
k8s.io/component-base v0.33.3 // indirect
133+
k8s.io/apiserver v0.34.2 // indirect
134+
k8s.io/component-base v0.34.2 // indirect
135135
k8s.io/klog/v2 v2.130.1 // indirect
136136
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
137-
k8s.io/kubectl v0.33.3 // indirect
137+
k8s.io/kubectl v0.34.0 // indirect
138138
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
139139
oras.land/oras-go/v2 v2.6.0 // indirect
140140
sigs.k8s.io/controller-runtime v0.20.0 // indirect

0 commit comments

Comments
 (0)