Skip to content

Commit fcd7650

Browse files
committed
fix: gotemplate Cilium HCP
Using builtin topolgy templating results in a deadlock because the .ControlPlane is not updated until after the lifecycle hook returns.
1 parent b327c16 commit fcd7650

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ envoy:
3434
image:
3535
useDigest: false
3636
k8sServiceHost: auto
37-
{{- with .ControlPlane }}
38-
{{- range $key, $val := .metadata.annotations }}
39-
{{- if eq $key "controlplane.cluster.x-k8s.io/skip-kube-proxy" }}
37+
{{- if .EnableKubeProxyReplacement }}
4038
kubeProxyReplacement: true
4139
tunnelProtocol: geneve
4240
loadBalancer:
4341
mode: dsr
44-
dsrDispatch: geneve{{ break }}
45-
{{- end }}
46-
{{- end }}
42+
dsrDispatch: geneve
4743
{{- end }}

hack/addons/update-cilium-manifests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mkdir -p "${ASSETS_DIR}/cilium"
2424
envsubst -no-unset <"${KUSTOMIZE_BASE_DIR}/kustomization.yaml.tmpl" >"${ASSETS_DIR}/kustomization.yaml"
2525

2626
cat <<EOF >"${ASSETS_DIR}/gomplate-context.yaml"
27-
ControlPlane: {}
27+
EnableKubeProxyReplacement: false
2828
EOF
2929
gomplate -f "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/addons/cni/cilium/values-template.yaml" \
3030
--context .="${ASSETS_DIR}/gomplate-context.yaml" \

hack/tools/fetch-images/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,10 @@ func getValuesFileForChartIfNeeded(chartName, carenChartDirectory string) (strin
266266
}
267267

268268
type input struct {
269-
ControlPlane map[string]interface{}
269+
EnableKubeProxyReplacement bool
270270
}
271271
templateInput := input{
272-
ControlPlane: map[string]interface{}{
273-
"metadata": map[string]interface{}{
274-
"annotations": map[string]interface{}{
275-
"controlplane.cluster.x-k8s.io/skip-kube-proxy": "",
276-
},
277-
},
278-
},
272+
EnableKubeProxyReplacement: true,
279273
}
280274

281275
err = template.Must(template.New(defaultHelmAddonFilename).ParseFiles(f)).Execute(tempFile, &templateInput)
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 kube-proxy is disabled.
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.ShouldSkipKubeProxy(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 namespa`ce in template: %w",
37+
err,
38+
)
39+
}
40+
41+
return b.String(), nil
42+
}

0 commit comments

Comments
 (0)