Skip to content

Commit dca0748

Browse files
committed
feat: auto enable Cilium kube-proxy replacement
1 parent 2c2eebc commit dca0748

File tree

7 files changed

+78
-8
lines changed

7 files changed

+78
-8
lines changed

charts/cluster-api-runtime-extensions-nutanix/addons/cni/cilium/values-template.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ socketLB:
3333
envoy:
3434
image:
3535
useDigest: false
36+
{{- if .EnableKubeProxyReplacement }}
37+
kubeProxyReplacement: true
38+
k8sServiceHost: auto
39+
{{- end }}

charts/cluster-api-runtime-extensions-nutanix/templates/cni/cilium/manifests/cilium-configmap.yaml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

hack/addons/kustomize/cilium/kustomization.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ helmCharts:
1919
skipTests: true
2020
namespace: kube-system
2121
kubeVersion: ${E2E_KUBERNETES_VERSION}
22-
valuesFile: ../../../../charts/cluster-api-runtime-extensions-nutanix/addons/cni/cilium/values-template.yaml
22+
valuesFile: helm-values.yaml
2323
# The CRS manifests are generated from the Cilium Helm chart using Kustomize. The Cilium
2424
# Helm chart uses a Helm hook to generate TLS certificates for Hubble. As the
2525
# CRS manifests are static those Helm hooks don't apply and so for now Hubble is

hack/addons/update-cilium-manifests.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ readonly FILE_NAME="cilium.yaml"
2121

2222
readonly KUSTOMIZE_BASE_DIR="${SCRIPT_DIR}/kustomize/cilium"
2323
mkdir -p "${ASSETS_DIR}/cilium"
24-
envsubst -no-unset <"${KUSTOMIZE_BASE_DIR}/kustomization.yaml.tmpl" >"${KUSTOMIZE_BASE_DIR}/kustomization.yaml"
25-
trap_add "rm -f ${KUSTOMIZE_BASE_DIR}/kustomization.yaml" EXIT
24+
envsubst -no-unset <"${KUSTOMIZE_BASE_DIR}/kustomization.yaml.tmpl" >"${ASSETS_DIR}/kustomization.yaml"
25+
26+
cat <<EOF >"${ASSETS_DIR}/gomplate-context.yaml"
27+
EnableKubeProxyReplacement: true
28+
EOF
29+
gomplate -f "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/addons/cni/cilium/values-template.yaml" \
30+
--context .="${ASSETS_DIR}/gomplate-context.yaml" \
31+
>"${ASSETS_DIR}/helm-values.yaml"
2632

2733
kustomize build \
2834
--load-restrictor LoadRestrictionsNone \
29-
--enable-helm "${KUSTOMIZE_BASE_DIR}/" >"${ASSETS_DIR}/${FILE_NAME}"
30-
trap_add "rm -rf ${KUSTOMIZE_BASE_DIR}/charts/" EXIT
35+
--enable-helm "${ASSETS_DIR}/" >"${ASSETS_DIR}/${FILE_NAME}"
3136

3237
# The operator manifest in YAML format is pretty big. It turns out that much of that is whitespace. Converting the
3338
# manifest to JSON without indentation allows us to remove most of the whitespace, reducing the size by more than half.

hack/tools/fetch-images/main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,25 @@ func getValuesFileForChartIfNeeded(chartName, carenChartDirectory string) (strin
259259
case "snapshot-controller":
260260
return filepath.Join(carenChartDirectory, "addons", "csi", "snapshot-controller", defaultHelmAddonFilename), nil
261261
case "cilium":
262-
return filepath.Join(carenChartDirectory, "addons", "cni", "cilium", defaultHelmAddonFilename), nil
262+
f := filepath.Join(carenChartDirectory, "addons", "cni", "cilium", defaultHelmAddonFilename)
263+
tempFile, err := os.CreateTemp("", "")
264+
if err != nil {
265+
return "", fmt.Errorf("failed to create temp file: %w", err)
266+
}
267+
268+
type input struct {
269+
EnableKubeProxyReplacement bool
270+
}
271+
templateInput := input{
272+
EnableKubeProxyReplacement: true,
273+
}
274+
275+
err = template.Must(template.New(defaultHelmAddonFilename).ParseFiles(f)).Execute(tempFile, &templateInput)
276+
if err != nil {
277+
return "", fmt.Errorf("failed to execute helm values template %w", err)
278+
}
279+
280+
return tempFile.Name(), nil
263281
// Calico values differ slightly per provider, but that does not have a material imapct on the images required
264282
// so we can use the default values file for AWS provider.
265283
case "tigera-operator":

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func (c *CiliumCNI) apply(
221221
),
222222
c.client,
223223
helmChart,
224-
)
224+
).
225+
WithValueTemplater(templateValues)
225226
case "":
226227
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
227228
resp.SetMessage("strategy not specified for Cilium CNI addon")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 Nutanix. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cilium
5+
6+
import (
7+
"bytes"
8+
"fmt"
9+
"text/template"
10+
11+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
12+
13+
capiutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/utils"
14+
)
15+
16+
// templateValues enables kube-proxy replacement when skip kube-proxy annotation is set.
17+
func templateValues(cluster *clusterv1.Cluster, text string) (string, error) {
18+
ciliumTemplate, err := template.New("").Parse(text)
19+
if err != nil {
20+
return "", fmt.Errorf("failed to parse template: %w", err)
21+
}
22+
23+
type input struct {
24+
EnableKubeProxyReplacement bool
25+
}
26+
27+
// Assume when kube-proxy is skipped, we should enable Cilium's kube-proxy replacement feature.
28+
templateInput := input{
29+
EnableKubeProxyReplacement: capiutils.SkipKubeProxy(cluster),
30+
}
31+
32+
var b bytes.Buffer
33+
err = ciliumTemplate.Execute(&b, templateInput)
34+
if err != nil {
35+
return "", fmt.Errorf(
36+
"failed setting target Cluster name and namespace in template: %w",
37+
err,
38+
)
39+
}
40+
41+
return b.String(), nil
42+
}

0 commit comments

Comments
 (0)