Skip to content

Commit d16bfc7

Browse files
authored
feat: Extract CAAPH values templates to files (#896)
This simplifies the Helm templating directives by not requiring inception-style escaping of templating braces, e.g. `{{ "{{" }}`` which are very hard to read and can introduce bugs. This PR also removes the duplicate helm values files currently being used to generate the CRS configmaps, and instead references the helm values that are in the charts directory, which ends up with a reduction in LOC in the project to maintain. I feel this is a simpler way to achieve the same goals as #819 but without duplicating files and keeping all chart source files in the charts directory. Blocked by #895.
1 parent de57106 commit d16bfc7

File tree

50 files changed

+296
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+296
-405
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ repos:
7070
- id: check-yaml
7171
args: ["-m", "--unsafe"]
7272
stages: [commit]
73-
exclude: ^charts/.+/templates/
73+
exclude: ^charts/.+/(templates|addons)/.+\.ya?ml$
7474
- id: mixed-line-ending
7575
args: ["-f", "lf"]
7676
exclude: \.bat$
@@ -140,7 +140,7 @@ repos:
140140
name: License headers - YAML and Makefiles
141141
stages: [commit]
142142
files: (^Makefile|\.(ya?ml|mk))$
143-
exclude: ^(internal/test|pkg/handlers/.+/embedded|examples|charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses)/.+\.ya?ml|docs/static/helm/index\.yaml|charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml$
143+
exclude: ^(internal/test|pkg/handlers/.+/embedded|examples|charts/cluster-api-runtime-extensions-nutanix/(defaultclusterclasses|addons))/.+\.ya?ml|docs/static/helm/index\.yaml|charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml$
144144
args:
145145
- --license-filepath
146146
- hack/license-header.txt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{ $clusterSemver := semver .Cluster.spec.topology.version }}
2+
{{ $ccmVersion := get $k8sMinorVersionToCCMVersion ( print $clusterSemver.Major "." $clusterSemver.Minor ) }}
3+
image:
4+
tag: "{{ $ccmVersion }}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$k8sMinorVersionToCCMVersion := dict
2+
{{ range $k8sVersion, $ccmVersion := .Values.hooks.ccm.aws.k8sMinorVersionToCCMVersion -}}
3+
"{{ $k8sVersion }}" "{{ $ccmVersion }}"
4+
{{ end -}}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Copyright 2024 Nutanix. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
4-
---
51
# Starting in Kubernetes v1.29 the Kubelet no longer adds temporary addresses to the Node.
62
# See https://github.com/kubernetes/kubernetes/pull/121028
73
# This causes a deadlock with the AWS CCM and some CNI providers including Calico.
@@ -17,8 +13,8 @@ args:
1713
- --configure-cloud-routes=false
1814

1915
tolerations:
20-
- key: node.cloudprovider.kubernetes.io/uninitialized
21-
value: "true"
22-
effect: NoSchedule
23-
- key: node-role.kubernetes.io/control-plane
24-
effect: NoSchedule
16+
- key: node.cloudprovider.kubernetes.io/uninitialized
17+
value: "true"
18+
effect: NoSchedule
19+
- key: node-role.kubernetes.io/control-plane
20+
effect: NoSchedule
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
prismCentralEndPoint: {{ .PrismCentralHost }}
2+
prismCentralPort: {{ .PrismCentralPort }}
3+
prismCentralInsecure: {{ .PrismCentralInsecure }}
4+
{{- with .PrismCentralAdditionalTrustBundle }}
5+
prismCentralAdditionalTrustBundle: "{{ . }}"
6+
{{- end }}
7+
{{- with .ControlPlaneEndpointHost }}
8+
ignoredNodeIPs: [ {{ printf "%q" . }} ]
9+
{{- end }}
10+
11+
# The Secret containing the credentials will be created by the handler.
12+
createSecret: false
13+
secretName: nutanix-ccm-credentials

hack/addons/kustomize/cluster-autoscaler/helm-values.yaml renamed to charts/cluster-api-runtime-extensions-nutanix/addons/cluster-autoscaler/values-template.yaml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
# Copyright 2023 Nutanix. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
4-
---
5-
# This is a hack, but because a single cluster-autoscaler deployment can only monitor a single Kubernetes cluster
6-
# we expect 'tmpl-clustername-tmpl' and 'tmpl-clusternamespace-tmpl'
7-
# to be replaced with the Cluster's name and namespace.
8-
fullnameOverride: cluster-autoscaler-tmpl-clusteruuid-tmpl
1+
fullnameOverride: "cluster-autoscaler-{{ index .Cluster.Annotations "caren.nutanix.com/cluster-uuid" }}"
92

103
cloudProvider: clusterapi
114

@@ -20,18 +13,18 @@ tolerations:
2013

2114
# Limit a single cluster-autoscaler Deployment to a single Cluster.
2215
autoDiscovery:
23-
clusterName: tmpl-clustername-tmpl
16+
clusterName: "{{ .Cluster.Name }}"
2417
# The controller failed with an RBAC error trying to watch CAPI objects at the cluster scope without this.
2518
labels:
26-
- namespace: tmpl-clusternamespace-tmpl
19+
- namespace: "{{ .Cluster.Namespace }}"
2720

2821
# For workload clusters it is not possible to use the in-cluster client.
2922
# To simplify the configuration, use the admin kubeconfig generated by CAPI for all clusters.
3023
clusterAPIMode: kubeconfig-incluster
3124
clusterAPIWorkloadKubeconfigPath: /cluster/kubeconfig
3225
extraVolumeSecrets:
3326
kubeconfig:
34-
name: tmpl-clustername-tmpl-kubeconfig
27+
name: "{{ .Cluster.Name }}-kubeconfig"
3528
mountPath: /cluster
3629
readOnly: true
3730
items:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
installation:
2+
cni:
3+
type: Calico
4+
calicoNetwork:
5+
bgp: Enabled
6+
ipPools: {{ range $cidr := .Cluster.spec.clusterNetwork.pods.cidrBlocks }}
7+
- cidr: "{{ $cidr }}"
8+
encapsulation: None
9+
natOutgoing: Enabled
10+
nodeSelector: all(){{ end }}
11+
nodeMetricsPort: 9091
12+
typhaMetricsPort: 9093
13+
registry: quay.io/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
installation:
2+
cni:
3+
type: Calico
4+
calicoNetwork:
5+
ipPools:{{ range $cidr := .Cluster.spec.clusterNetwork.pods.cidrBlocks }}
6+
- cidr: "{{ $cidr }}"
7+
encapsulation: None
8+
natOutgoing: Enabled
9+
nodeSelector: all(){{ end }}
10+
nodeMetricsPort: 9091
11+
typhaMetricsPort: 9093
12+
registry: quay.io/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
installation:
2+
cni:
3+
type: Calico
4+
calicoNetwork:
5+
bgp: Enabled
6+
ipPools:{{ range $cidr := .Cluster.spec.clusterNetwork.pods.cidrBlocks }}
7+
- cidr: "{{ $cidr }}"
8+
encapsulation: None
9+
natOutgoing: Enabled
10+
nodeSelector: all(){{ end }}
11+
nodeMetricsPort: 9091
12+
typhaMetricsPort: 9093
13+
registry: quay.io/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cni:
2+
chainingMode: portmap
3+
exclusive: false
4+
hubble:
5+
enabled: true
6+
tls:
7+
auto:
8+
enabled: true # enable automatic TLS certificate generation
9+
method: cronJob # auto generate certificates using cronJob method
10+
certValidityDuration: 60 # certificates validity duration in days (default 2 months)
11+
schedule: "0 0 1 * *" # schedule on the 1st day regeneration of each month
12+
relay:
13+
enabled: true
14+
image:
15+
useDigest: false
16+
ipam:
17+
mode: kubernetes
18+
image:
19+
useDigest: false
20+
operator:
21+
image:
22+
useDigest: false
23+
certgen:
24+
image:
25+
useDigest: false
26+
socketLB:
27+
hostNamespaceOnly: true

hack/addons/kustomize/aws-ebs-csi/helm-values.yaml renamed to charts/cluster-api-runtime-extensions-nutanix/addons/csi/aws-ebs/values-template.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Copyright 2024 Nutanix. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
4-
---
51
controller:
62
affinity:
73
nodeAffinity:

hack/addons/kustomize/local-path-provisioner-csi/helm-values.yaml renamed to charts/cluster-api-runtime-extensions-nutanix/addons/csi/local-path/values-template.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Copyright 2024 Nutanix. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
4-
---
51
storageClass:
62
create: false
73
provisionerName: rancher.io/local-path
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Disable creating the Prism Central credentials Secret, the Secret will be created by the handler.
2+
createPrismCentralSecret: false
3+
# Disable creating the Prism Element credentials Secret, it won't be used the CSI driver as configured here.
4+
createSecret: false
5+
pcSecretName: nutanix-csi-credentials
6+
7+
tolerations:
8+
- key: CriticalAddonsOnly
9+
operator: Exists
10+
- effect: NoExecute
11+
operator: Exists
12+
tolerationSeconds: 300
13+
- effect: NoSchedule
14+
key: node-role.kubernetes.io/control-plane
15+
operator: Exists

hack/addons/kustomize/snapshot-controller/helm-values.yaml renamed to charts/cluster-api-runtime-extensions-nutanix/addons/csi/snapshot-controller/values-template.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Copyright 2024 Nutanix. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
41
controller:
52
priorityClassName: system-cluster-critical
63
tolerations:
@@ -9,9 +6,6 @@ controller:
96
- effect: NoExecute
107
operator: Exists
118
tolerationSeconds: 300
12-
- effect: NoSchedule
13-
key: node-role.kubernetes.io/master
14-
operator: Exists
159
- effect: NoSchedule
1610
key: node-role.kubernetes.io/control-plane
1711
operator: Exists

hack/addons/kustomize/nfd/helm-values.yaml renamed to charts/cluster-api-runtime-extensions-nutanix/addons/nfd/values-template.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# Copyright 2023 Nutanix. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
4-
---
51
master:
62
extraLabelNs:
73
- nvidia.com
84
- beta.amd.com
95
- amd.com
6+
tolerations:
7+
- key: "node-role.kubernetes.io/control-plane"
8+
operator: "Equal"
9+
value: ""
10+
effect: "NoSchedule"
1011
affinity:
1112
nodeAffinity:
1213
preferredDuringSchedulingIgnoredDuringExecution:
@@ -27,7 +28,6 @@ worker: ### <NFD-WORKER-CONF-START-DO-NOT-REMOVE>
2728
tolerations:
2829
- effect: NoSchedule
2930
key: node-role.kubernetes.io/control-plane
30-
### <NFD-WORKER-CONF-END-DO-NOT-REMOVE>
3131

3232
gc:
3333
tolerations:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
controller:
2+
tolerations:
3+
- key: node-role.kubernetes.io/control-plane
4+
effect: NoSchedule
5+
operator: Exists
6+
- key: CriticalAddonsOnly
7+
operator: Exists
8+
- effect: NoExecute
9+
operator: Exists
10+
tolerationSeconds: 300
11+
speaker:
12+
tolerations:
13+
- key: node-role.kubernetes.io/control-plane
14+
effect: NoSchedule
15+
operator: Exists
16+
- key: CriticalAddonsOnly
17+
operator: Exists
18+
- effect: NoExecute
19+
operator: Exists
20+
tolerationSeconds: 300

charts/cluster-api-runtime-extensions-nutanix/templates/ccm/aws/manifests/helm-addon-installation.yaml

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,13 @@ kind: ConfigMap
77
metadata:
88
name: '{{ .Values.hooks.ccm.aws.helmAddonStrategy.defaultValueTemplateConfigMap.name }}'
99
data:
10+
# These values are a combination of a Helm template to create the dict for the k8s version to
11+
# CCM version map, and then including the non-templated values from the values-template.yaml.
12+
# This simplifies the templating required in the values-template.yaml.
1013
values.yaml: |-
11-
# Starting in Kubernetes v1.29 the Kubelet no longer adds temporary addresses to the Node.
12-
# See https://github.com/kubernetes/kubernetes/pull/121028
13-
# This causes a deadlock with the AWS CCM and some CNI providers including Calico.
14-
# The Calico Pods won't start until some addresses are assigned,
15-
# but the AWS CCM that adds the addresses can't start until the Calico Pods are running.
16-
# Using hostNetworking allows the AWS CCM to start before the Calico Pods.
17-
# The upstream CAPA templates are also already using hostNetworking for the CCM Pods.
18-
hostNetworking: true
19-
20-
args:
21-
- --v=2
22-
- --cloud-provider=aws
23-
- --configure-cloud-routes=false
24-
25-
{{ "{{" }} $k8sMinorVersionToCCMVersion := dict
26-
{{ range $k8sVersion, $ccmVersion := .Values.hooks.ccm.aws.k8sMinorVersionToCCMVersion -}}
27-
"{{ $k8sVersion }}" "{{ $ccmVersion }}"
28-
{{ end -}}
14+
{{ "{{" }}
15+
{{- tpl (.Files.Get "addons/ccm/aws/map-template.yaml") . | nindent 4 -}}
2916
{{ "}}" }}
30-
{{ "{{" }}$clusterSemver := semver .Cluster.spec.topology.version {{ "}}" }}
31-
{{ "{{" }}$ccmVersion := get $k8sMinorVersionToCCMVersion ( print $clusterSemver.Major "." $clusterSemver.Minor ) {{ "}}" }}
32-
image:
33-
tag: {{ "{{ " }} $ccmVersion {{ "}}" }}
34-
35-
tolerations:
36-
- key: node.cloudprovider.kubernetes.io/uninitialized
37-
value: "true"
38-
effect: NoSchedule
39-
- key: node-role.kubernetes.io/control-plane
40-
effect: NoSchedule
41-
42-
17+
{{- .Files.Get "addons/ccm/aws/image-selection.yaml" | nindent 4 -}}
18+
{{- .Files.Get "addons/ccm/aws/values-template.yaml" | nindent 4 -}}
4319
{{- end -}}

charts/cluster-api-runtime-extensions-nutanix/templates/ccm/nutanix/manifests/helm-addon-installation.yaml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,5 @@ metadata:
88
name: '{{ .Values.hooks.ccm.nutanix.helmAddonStrategy.defaultValueTemplateConfigMap.name }}'
99
data:
1010
values.yaml: |-
11-
---
12-
prismCentralEndPoint: {{ `{{ .PrismCentralHost }}` }}
13-
prismCentralPort: {{ `{{ .PrismCentralPort }}` }}
14-
prismCentralInsecure: {{ `{{ .PrismCentralInsecure }}` }}
15-
{{ `{{- with .PrismCentralAdditionalTrustBundle }}` }}
16-
prismCentralAdditionalTrustBundle: {{ `{{ printf "%q" . }}` }}
17-
{{ `{{- end }}` }}
18-
{{ `{{- with .ControlPlaneEndpointHost }}` }}
19-
ignoredNodeIPs: [ {{ `{{ printf "%q" . }}` }} ]
20-
{{ `{{- end }}` }}
21-
22-
# The Secret containing the credentials will be created by the handler.
23-
createSecret: false
24-
secretName: nutanix-ccm-credentials
11+
{{- .Files.Get "addons/ccm/nutanix/values-template.yaml" | nindent 4 }}
2512
{{- end -}}

charts/cluster-api-runtime-extensions-nutanix/templates/cluster-autoscaler/manifests/helm-addon-installation.yaml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,5 @@ metadata:
88
name: '{{ .Values.hooks.clusterAutoscaler.helmAddonStrategy.defaultValueTemplateConfigMap.name }}'
99
data:
1010
values.yaml: |-
11-
---
12-
fullnameOverride: "cluster-autoscaler-{{ `{{ index .Cluster.Annotations "caren.nutanix.com/cluster-uuid" }}` }}"
13-
14-
cloudProvider: clusterapi
15-
16-
# Always trigger a scale-out if replicas are less than the min.
17-
extraArgs:
18-
enforce-node-group-min-size: true
19-
20-
# Enable it to run in a 1 Node cluster.
21-
tolerations:
22-
- effect: NoSchedule
23-
key: node-role.kubernetes.io/control-plane
24-
25-
# Limit a single cluster-autoscaler Deployment to a single Cluster.
26-
autoDiscovery:
27-
clusterName: "{{ `{{ .Cluster.Name }}` }}"
28-
# The controller failed with an RBAC error trying to watch CAPI objects at the cluster scope without this.
29-
labels:
30-
- namespace: "{{ `{{ .Cluster.Namespace }}` }}"
31-
32-
# For workload clusters it is not possible to use the in-cluster client.
33-
# To simplify the configuration, use the admin kubeconfig generated by CAPI for all clusters.
34-
clusterAPIMode: kubeconfig-incluster
35-
clusterAPIWorkloadKubeconfigPath: /cluster/kubeconfig
36-
extraVolumeSecrets:
37-
kubeconfig:
38-
name: "{{ `{{ .Cluster.Name }}` }}-kubeconfig"
39-
mountPath: /cluster
40-
readOnly: true
41-
items:
42-
- key: value
43-
path: kubeconfig
44-
rbac:
45-
# Create a Role instead of a ClusterRoles to update cluster-api objects
46-
clusterScoped: false
11+
{{- .Files.Get "addons/cluster-autoscaler/values-template.yaml" | nindent 4 }}
4712
{{- end -}}

charts/cluster-api-runtime-extensions-nutanix/templates/cni/calico/manifests/aws/helm-addon-installation.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,5 @@ metadata:
88
name: '{{ .Values.hooks.cni.calico.helmAddonStrategy.defaultValueTemplatesConfigMaps.AWSCluster.name }}'
99
data:
1010
values.yaml: |-
11-
installation:
12-
cni:
13-
type: Calico
14-
calicoNetwork:
15-
bgp: Enabled
16-
ipPools:{{ printf "{{ range $cidr := .Cluster.spec.clusterNetwork.pods.cidrBlocks }}" }}
17-
- cidr: {{ printf "{{ $cidr }}" }}
18-
encapsulation: None
19-
natOutgoing: Enabled
20-
nodeSelector: all(){{ printf "{{ end }}" }}
21-
nodeMetricsPort: 9091
22-
typhaMetricsPort: 9093
23-
registry: quay.io/
11+
{{- .Files.Get "addons/cni/calico/aws/values-template.yaml" | nindent 4 }}
2412
{{- end -}}

0 commit comments

Comments
 (0)