Skip to content

Commit d962187

Browse files
feat: implementation for user defined configmap for cilium addon in cluster creation (#1033)
**What problem does this PR solve?**: implementation for user defined cilium configmap in cluster creation, current PR's implementation covers only configmap kind and assumes that `clusterctl.cluster.x-k8s.io/move` label is added on configmap by user. pending PRs: 1. Implementation for Secret kind object for user defined cilium spec. **Which issue(s) this PR fixes**: Fixes # [NCN-105148](https://jira.nutanix.com/browse/NCN-105148) **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. --> ``` $ kg cluster NAME CLUSTERCLASS PHASE AGE VERSION nkp-mgmt-cluster nutanix-quick-start Provisioned 15m v1.31.4 $ kg cm custom-cilium-cni-helm-values-template -oyaml apiVersion: v1 data: values.yaml: |- cni: chainingMode: portmap exclusive: false hubble: enabled: true tls: auto: enabled: true # enable automatic TLS certificate generation method: cronJob # auto generate certificates using cronJob method certValidityDuration: 60 # certificates validity duration in days (default 2 months) schedule: "0 0 5 * *" relay: enabled: true image: useDigest: false ipam: mode: kubernetes image: useDigest: false operator: image: useDigest: false certgen: image: useDigest: false socketLB: hostNamespaceOnly: true envoy: image: useDigest: false kind: ConfigMap metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","data":{"values.yaml":"cni:\n chainingMode: portmap\n exclusive: false\nhubble:\n enabled: true\n tls:\n auto:\n enabled: true # enable automatic TLS certificate generation\n method: cronJob # auto generate certificates using cronJob method\n certValidityDuration: 60 # certificates validity duration in days (default 2 months)\n schedule: \"0 0 5 * *\" # schedule on the 1st day regeneration of each month\n relay:\n enabled: true\n image:\n useDigest: false\nipam:\n mode: kubernetes\nimage:\n useDigest: false\noperator:\n image:\n useDigest: false\ncertgen:\n image:\n useDigest: false\nsocketLB:\n hostNamespaceOnly: true\nenvoy:\n image:\n useDigest: false"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"cluster.x-k8s.io/cluster-name":"nkp-mgmt-cluster","clusterctl.cluster.x-k8s.io/move":""},"name":"custom-cilium-cni-helm-values-template","namespace":"default"}} creationTimestamp: "2025-02-04T14:55:33Z" labels: cluster.x-k8s.io/cluster-name: nkp-mgmt-cluster clusterctl.cluster.x-k8s.io/move: "" name: custom-cilium-cni-helm-values-template namespace: default resourceVersion: "23373" uid: 943620cd-a1a0-4d99-8383-d68e4329d029 $ kg hcp cilium-0194d059-494c-7879-a6bd-fe281ba362d9 -oyaml apiVersion: addons.cluster.x-k8s.io/v1alpha1 kind: HelmChartProxy metadata: creationTimestamp: "2025-02-04T14:56:33Z" finalizers: - helmchartproxy.addons.cluster.x-k8s.io generation: 1 name: cilium-0194d059-494c-7879-a6bd-fe281ba362d9 namespace: default ownerReferences: - apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster name: nkp-mgmt-cluster uid: 83c0cc69-7100-41f5-a415-ccff87c8d03e resourceVersion: "26337" uid: f70e9e27-45a8-4832-9497-a94306b7ec30 spec: chartName: cilium clusterSelector: matchLabels: cluster.x-k8s.io/cluster-name: nkp-mgmt-cluster namespace: kube-system options: enableClientCache: false install: createNamespace: true timeout: 10m0s upgrade: maxHistory: 10 releaseName: cilium repoURL: oci://helm-repository.default.svc/charts tlsConfig: caSecret: name: helm-repository-tls namespace: default valuesTemplate: |- cni: chainingMode: portmap exclusive: false hubble: enabled: true tls: auto: enabled: true # enable automatic TLS certificate generation method: cronJob # auto generate certificates using cronJob method certValidityDuration: 60 # certificates validity duration in days (default 2 months) schedule: "0 0 5 * *" # schedule on the 1st day regeneration of each month relay: enabled: true image: useDigest: false ipam: mode: kubernetes image: useDigest: false operator: image: useDigest: false certgen: image: useDigest: false socketLB: hostNamespaceOnly: true envoy: image: useDigest: false version: 1.16.4 status: conditions: - lastTransitionTime: "2025-02-04T15:04:13Z" status: "True" type: Ready - lastTransitionTime: "2025-02-04T15:04:13Z" status: "True" type: HelmReleaseProxiesReady - lastTransitionTime: "2025-02-04T15:02:45Z" status: "True" type: HelmReleaseProxySpecsUpToDate matchingClusters: - apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster name: nkp-mgmt-cluster namespace: default observedGeneration: 1 ```
1 parent 683aa47 commit d962187

File tree

7 files changed

+41
-34
lines changed

7 files changed

+41
-34
lines changed

api/v1alpha1/addon_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ type AddonValues struct {
140140
// typed referenced object inside the same namespace.
141141
// This is redacted from the upstream https://pkg.go.dev/k8s.io/api/core/v1#TypedLocalObjectReference
142142
type ValuesReference struct {
143-
// Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
144-
// +kubebuilder:validation:Enum=Secret;ConfigMap
143+
// Kind is the type of resource being referenced, valid values are ('ConfigMap').
144+
// +kubebuilder:validation:Enum=ConfigMap
145145
// +kubebuilder:validation:Required
146146
Kind string `json:"kind"`
147147

api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ spec:
110110
which contains inline YAML representing the values for the Helm chart.
111111
properties:
112112
kind:
113-
description: Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
113+
description: Kind is the type of resource being referenced, valid values are ('ConfigMap').
114114
enum:
115-
- Secret
116115
- ConfigMap
117116
type: string
118117
name:

api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ spec:
110110
which contains inline YAML representing the values for the Helm chart.
111111
properties:
112112
kind:
113-
description: Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
113+
description: Kind is the type of resource being referenced, valid values are ('ConfigMap').
114114
enum:
115-
- Secret
116115
- ConfigMap
117116
type: string
118117
name:

api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ spec:
110110
which contains inline YAML representing the values for the Helm chart.
111111
properties:
112112
kind:
113-
description: Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
113+
description: Kind is the type of resource being referenced, valid values are ('ConfigMap').
114114
enum:
115-
- Secret
116115
- ConfigMap
117116
type: string
118117
name:

docs/content/addons/cni.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ spec:
5656
strategy: HelmAddon
5757
values:
5858
sourceRef:
59-
name: <NAME> #name of ConfigMap/Secret present in same namespace
60-
kind: <ConfigMap/Secret>
59+
name: <NAME> #name of ConfigMap present in same namespace
60+
kind: <ConfigMap>
6161
```
6262
63-
NOTE: Only ConfigMap/Secret kind objects will be allowed to refer helm values from.
63+
NOTE: Only ConfigMap kind objects will be allowed to refer helm values from.
6464
6565
ConfigMap Format -
6666
@@ -81,27 +81,7 @@ metadata:
8181
namespace: <CLUSTER_NAMESPACE>
8282
```
8383
84-
Secret Format -
85-
86-
```yaml
87-
apiVersion: v1
88-
stringData:
89-
values.yaml: |-
90-
cni:
91-
chainingMode: portmap
92-
exclusive: false
93-
ipam:
94-
mode: kubernetes
95-
kind: Secret
96-
metadata:
97-
labels:
98-
clusterctl.cluster.x-k8s.io/move: ""
99-
name: <CLUSTER_NAME>-cilium-cni-helm-values-template
100-
namespace: <CLUSTER_NAMESPACE>
101-
type: Opaque
102-
```
103-
104-
NOTE: ConfigMap/Secret should contain complete helm values for Cilium as same will be applied
84+
NOTE: ConfigMap should contain complete helm values for Cilium as same will be applied
10585
to Cilium helm chart as it is.
10686
10787
To deploy the addon via `ClusterResourceSet` replace the value of `strategy` with `ClusterResourceSet`.

pkg/handlers/generic/lifecycle/cni/cilium/handler.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ func (c *CiliumCNI) apply(
153153
return
154154
}
155155

156+
targetNamespace := c.config.DefaultsNamespace()
157+
156158
var strategy addons.Applier
157159
switch ptr.Deref(cniVar.Strategy, "") {
158160
case v1alpha1.AddonStrategyClusterResourceSet:
@@ -175,9 +177,17 @@ func (c *CiliumCNI) apply(
175177
)
176178
return
177179
}
180+
181+
helmValuesSourceRefName := c.config.helmAddonConfig.defaultValuesTemplateConfigMapName
182+
if cniVar.Values != nil && cniVar.Values.SourceRef != nil {
183+
helmValuesSourceRefName = cniVar.Values.SourceRef.Name
184+
// Use cluster's namespace since Values.SourceRef is always a LocalObjectReference
185+
targetNamespace = cluster.Namespace
186+
}
187+
178188
strategy = addons.NewHelmAddonApplier(
179189
addons.NewHelmAddonConfig(
180-
c.config.helmAddonConfig.defaultValuesTemplateConfigMapName,
190+
helmValuesSourceRefName,
181191
defaultCiliumNamespace,
182192
defaultCiliumReleaseName,
183193
),
@@ -193,7 +203,7 @@ func (c *CiliumCNI) apply(
193203
return
194204
}
195205

196-
if err := strategy.Apply(ctx, cluster, c.config.DefaultsNamespace(), log); err != nil {
206+
if err := strategy.Apply(ctx, cluster, targetNamespace, log); err != nil {
197207
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
198208
resp.SetMessage(err.Error())
199209
return

pkg/handlers/generic/lifecycle/cni/variables_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ var testDefs = []capitest.VariableTestDef{{
4040
},
4141
},
4242
},
43+
}, {
44+
Name: "set with valid provider using HelmAddon strategy and custom helm values",
45+
Vals: apivariables.ClusterConfigSpec{
46+
Addons: &apivariables.Addons{
47+
GenericAddons: v1alpha1.GenericAddons{
48+
CNI: &v1alpha1.CNI{
49+
Provider: v1alpha1.CNIProviderCilium,
50+
Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon),
51+
AddonConfig: v1alpha1.AddonConfig{
52+
Values: &v1alpha1.AddonValues{
53+
SourceRef: &v1alpha1.ValuesReference{
54+
Name: "custom-cilium-cni-helm-values",
55+
Kind: "ConfigMap",
56+
},
57+
},
58+
},
59+
},
60+
},
61+
},
62+
},
4363
}, {
4464
Name: "set with invalid provider",
4565
Vals: apivariables.ClusterConfigSpec{

0 commit comments

Comments
 (0)