Skip to content

Commit 9fe0052

Browse files
committed
fixup! refactor: Use CAAPH templating rather than custom temlating
Use the ControlPlane reference in the CAAPH template and check the annotation for skip kube proxy on the referenced control plane object. As per https://cluster-api.sigs.k8s.io/reference/api/metadata-propagation\#cluster-topology the skip proxy annotation will be propagated to the annotations on the referenced control plane so is safe to check. CAAPH adds the referenced control plane to the variables referencable in the Helm values template.
1 parent 7d79c35 commit 9fe0052

File tree

8 files changed

+25
-70
lines changed

8 files changed

+25
-70
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ socketLB:
3333
envoy:
3434
image:
3535
useDigest: false
36-
{{- if .EnableKubeProxyReplacement }}
37-
kubeProxyReplacement: true
3836
k8sServiceHost: auto
37+
{{- with .ControlPlane }}
38+
{{- range $key, $val := .metadata.annotations }}
39+
{{- if eq $key "controlplane.cluster.x-k8s.io/skip-kube-proxy" }}
40+
kubeProxyReplacement: true{{ break }}
41+
{{- end }}
42+
{{- end }}
3943
{{- end }}

common/pkg/capi/utils/anootations.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ helmCharts:
1919
skipTests: true
2020
namespace: kube-system
2121
kubeVersion: ${E2E_KUBERNETES_VERSION}
22+
# This values file will be created by the update-cilium-manifests.sh script when generating the CRS manifests.
2223
valuesFile: helm-values.yaml
2324
# The CRS manifests are generated from the Cilium Helm chart using Kustomize. The Cilium
2425
# Helm chart uses a Helm hook to generate TLS certificates for Hubble. As the

hack/addons/update-cilium-manifests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ 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-
EnableKubeProxyReplacement: true
27+
ControlPlane:
28+
metadata:
29+
annotations:
30+
controlplane.cluster.x-k8s.io/skip-kube-proxy: ""
2831
EOF
2932
gomplate -f "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/addons/cni/cilium/values-template.yaml" \
3033
--context .="${ASSETS_DIR}/gomplate-context.yaml" \

hack/tools/fetch-images/main.go

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

268268
type input struct {
269-
EnableKubeProxyReplacement bool
269+
ControlPlane map[string]interface{}
270270
}
271271
templateInput := input{
272-
EnableKubeProxyReplacement: true,
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+
},
273279
}
274280

275281
err = template.Must(template.New(defaultHelmAddonFilename).ParseFiles(f)).Execute(tempFile, &templateInput)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ func (c *CiliumCNI) apply(
221221
),
222222
c.client,
223223
helmChart,
224-
).
225-
WithValueTemplater(templateValues)
224+
)
226225
case "":
227226
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
228227
resp.SetMessage("strategy not specified for Cilium CNI addon")

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

Lines changed: 0 additions & 42 deletions
This file was deleted.

pkg/handlers/generic/mutation/kubeproxymode/inject.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
2525
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
2626
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
27-
capiutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/utils"
2827
)
2928

3029
const (
@@ -88,6 +87,11 @@ func (h *kubeProxyMode) Mutate(
8887
return fmt.Errorf("failed to get cluster for kube proxy mode mutation: %w", err)
8988
}
9089

90+
isSkipProxy := false
91+
if cluster.Spec.Topology != nil {
92+
_, isSkipProxy = cluster.Spec.Topology.ControlPlane.Metadata.Annotations[controlplanev1.SkipKubeProxyAnnotation]
93+
}
94+
9195
kubeProxyMode, err := variables.Get[v1alpha1.KubeProxyMode](
9296
vars,
9397
h.variableName,
@@ -106,8 +110,6 @@ func (h *kubeProxyMode) Mutate(
106110
kubeProxyMode,
107111
)
108112

109-
isSkipProxy := capiutils.SkipKubeProxy(cluster)
110-
111113
if kubeProxyMode == "" && !isSkipProxy {
112114
log.V(5).Info("kube proxy mode is not set or skipped, skipping mutation")
113115
return nil

0 commit comments

Comments
 (0)