Skip to content

feat: implementation for user defined configmap for cilium addon in cluster creation #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ type AddonValues struct {
// typed referenced object inside the same namespace.
// This is redacted from the upstream https://pkg.go.dev/k8s.io/api/core/v1#TypedLocalObjectReference
type ValuesReference struct {
// Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
// +kubebuilder:validation:Enum=Secret;ConfigMap
// Kind is the type of resource being referenced, valid values are ('ConfigMap').
// +kubebuilder:validation:Enum=ConfigMap
// +kubebuilder:validation:Required
Kind string `json:"kind"`

Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ spec:
which contains inline YAML representing the values for the Helm chart.
properties:
kind:
description: Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
description: Kind is the type of resource being referenced, valid values are ('ConfigMap').
enum:
- Secret
- ConfigMap
type: string
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ spec:
which contains inline YAML representing the values for the Helm chart.
properties:
kind:
description: Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
description: Kind is the type of resource being referenced, valid values are ('ConfigMap').
enum:
- Secret
- ConfigMap
type: string
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ spec:
which contains inline YAML representing the values for the Helm chart.
properties:
kind:
description: Kind is the type of resource being referenced, valid values are ('Secret', 'ConfigMap').
description: Kind is the type of resource being referenced, valid values are ('ConfigMap').
enum:
- Secret
- ConfigMap
type: string
name:
Expand Down
28 changes: 4 additions & 24 deletions docs/content/addons/cni.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ spec:
strategy: HelmAddon
values:
sourceRef:
name: <NAME> #name of ConfigMap/Secret present in same namespace
kind: <ConfigMap/Secret>
name: <NAME> #name of ConfigMap present in same namespace
kind: <ConfigMap>
```

NOTE: Only ConfigMap/Secret kind objects will be allowed to refer helm values from.
NOTE: Only ConfigMap kind objects will be allowed to refer helm values from.

ConfigMap Format -

Expand All @@ -81,27 +81,7 @@ metadata:
namespace: <CLUSTER_NAMESPACE>
```

Secret Format -

```yaml
apiVersion: v1
stringData:
values.yaml: |-
cni:
chainingMode: portmap
exclusive: false
ipam:
mode: kubernetes
kind: Secret
metadata:
labels:
clusterctl.cluster.x-k8s.io/move: ""
name: <CLUSTER_NAME>-cilium-cni-helm-values-template
namespace: <CLUSTER_NAMESPACE>
type: Opaque
```

NOTE: ConfigMap/Secret should contain complete helm values for Cilium as same will be applied
NOTE: ConfigMap should contain complete helm values for Cilium as same will be applied
to Cilium helm chart as it is.

To deploy the addon via `ClusterResourceSet` replace the value of `strategy` with `ClusterResourceSet`.
Expand Down
14 changes: 12 additions & 2 deletions pkg/handlers/generic/lifecycle/cni/cilium/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func (c *CiliumCNI) apply(
return
}

targetNamespace := c.config.DefaultsNamespace()

var strategy addons.Applier
switch ptr.Deref(cniVar.Strategy, "") {
case v1alpha1.AddonStrategyClusterResourceSet:
Expand All @@ -175,9 +177,17 @@ func (c *CiliumCNI) apply(
)
return
}

helmValuesSourceRefName := c.config.helmAddonConfig.defaultValuesTemplateConfigMapName
if cniVar.Values != nil && cniVar.Values.SourceRef != nil {
helmValuesSourceRefName = cniVar.Values.SourceRef.Name
// Use cluster's namespace since Values.SourceRef is always a LocalObjectReference
targetNamespace = cluster.Namespace
}

strategy = addons.NewHelmAddonApplier(
addons.NewHelmAddonConfig(
c.config.helmAddonConfig.defaultValuesTemplateConfigMapName,
helmValuesSourceRefName,
defaultCiliumNamespace,
defaultCiliumReleaseName,
),
Expand All @@ -193,7 +203,7 @@ func (c *CiliumCNI) apply(
return
}

if err := strategy.Apply(ctx, cluster, c.config.DefaultsNamespace(), log); err != nil {
if err := strategy.Apply(ctx, cluster, targetNamespace, log); err != nil {
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
resp.SetMessage(err.Error())
return
Expand Down
20 changes: 20 additions & 0 deletions pkg/handlers/generic/lifecycle/cni/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ var testDefs = []capitest.VariableTestDef{{
},
},
},
}, {
Name: "set with valid provider using HelmAddon strategy and custom helm values",
Vals: apivariables.ClusterConfigSpec{
Addons: &apivariables.Addons{
GenericAddons: v1alpha1.GenericAddons{
CNI: &v1alpha1.CNI{
Provider: v1alpha1.CNIProviderCilium,
Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon),
AddonConfig: v1alpha1.AddonConfig{
Values: &v1alpha1.AddonValues{
SourceRef: &v1alpha1.ValuesReference{
Name: "custom-cilium-cni-helm-values",
Kind: "ConfigMap",
},
},
},
},
},
},
},
}, {
Name: "set with invalid provider",
Vals: apivariables.ClusterConfigSpec{
Expand Down
Loading