Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 34ab8ec

Browse files
authored
feat: Support HelmAddon strategy to deploy NFD (nutanix-cloud-native#390)
1 parent 41a6cb9 commit 34ab8ec

35 files changed

+498
-118
lines changed

api/v1alpha1/addon_types.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,26 @@ func (CNI) VariableSchema() clusterv1.VariableSchema {
8080
}
8181

8282
// NFD tells us to enable or disable the node feature discovery addon.
83-
type NFD struct{}
83+
type NFD struct {
84+
// +optional
85+
Strategy AddonStrategy `json:"strategy,omitempty"`
86+
}
8487

8588
func (NFD) VariableSchema() clusterv1.VariableSchema {
8689
return clusterv1.VariableSchema{
8790
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
8891
Type: "object",
92+
Properties: map[string]clusterv1.JSONSchemaProps{
93+
"strategy": {
94+
Description: "Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster",
95+
Type: "string",
96+
Enum: variables.MustMarshalValuesToEnumJSON(
97+
AddonStrategyClusterResourceSet,
98+
AddonStrategyHelmAddon,
99+
),
100+
},
101+
},
102+
Required: []string{"strategy"},
89103
},
90104
}
91105
}

api/v1alpha1/constants.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package v1alpha1
55

66
const (
7-
// CNIVariableName is the external patch variable name.
7+
// CNIVariableName is the CNI external patch variable name.
88
CNIVariableName = "cni"
9+
// NFDVariableName is the NFD external patch variable name.
10+
NFDVariableName = "nfd"
911
// AWSVariableName is the AWS config patch variable name.
1012
AWSVariableName = "aws"
1113
)

charts/capi-runtime-extensions/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ A Helm chart for capi-runtime-extensions
4646
| hooks.cni.cilium.crsStrategy.defaultCiliumConfigMap.name | string | `"cilium"` | |
4747
| hooks.cni.cilium.helmAddonStrategy.defaultValueTemplateConfigMap.create | bool | `true` | |
4848
| hooks.cni.cilium.helmAddonStrategy.defaultValueTemplateConfigMap.name | string | `"default-cilium-cni-helm-values-template"` | |
49+
| hooks.nfd.crsStrategy.defaultInstallationConfigMap.name | string | `"node-feature-discovery"` | |
50+
| hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.create | bool | `true` | |
51+
| hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.name | string | `"default-nfd-helm-values-template"` | |
4952
| image.pullPolicy | string | `"IfNotPresent"` | |
5053
| image.repository | string | `"ghcr.io/d2iq-labs/capi-runtime-extensions"` | |
5154
| image.tag | string | `""` | |

charts/capi-runtime-extensions/templates/deployment.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ spec:
3434
- --cni.cilium.crs.defaults-namespace={{ .Release.Namespace }}
3535
- --cni.cilium.helm-addon.defaults-namespace={{ .Release.Namespace }}
3636
- --cni.cilium.helm-addon.default-values-template-configmap-name={{ .Values.hooks.cni.cilium.helmAddonStrategy.defaultValueTemplateConfigMap.name }}
37-
- --nfd.defaults-namespace={{ .Release.Namespace }}
37+
- --nfd.crs.defaults-namespace={{ .Release.Namespace }}
38+
- --nfd.helm-addon.defaults-namespace={{ .Release.Namespace }}
39+
- --nfd.helm-addon.default-values-template-configmap-name={{ .Values.hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.name }}
3840
{{- range $key, $value := .Values.extraArgs }}
3941
- --{{ $key }}={{ $value }}
4042
{{- end }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2024 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{{- if .Values.hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.create }}
5+
apiVersion: v1
6+
kind: ConfigMap
7+
metadata:
8+
name: '{{ .Values.hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.name }}'
9+
data:
10+
values.yaml: |-
11+
master:
12+
extraLabelNs:
13+
- nvidia.com
14+
- beta.amd.com
15+
- amd.com
16+
17+
worker: ### <NFD-WORKER-CONF-START-DO-NOT-REMOVE>
18+
config:
19+
sources:
20+
pci:
21+
deviceLabelFields:
22+
- "class"
23+
- "vendor"
24+
tolerations:
25+
- effect: NoSchedule
26+
key: node-role.kubernetes.io/master
27+
- effect: NoSchedule
28+
key: node-role.kubernetes.io/control-plane
29+
### <NFD-WORKER-CONF-END-DO-NOT-REMOVE>
30+
{{- end -}}

charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,4 +924,4 @@ data:
924924
kind: ConfigMap
925925
metadata:
926926
creationTimestamp: null
927-
name: node-feature-discovery
927+
name: '{{ .Values.hooks.nfd.crsStrategy.defaultInstallationConfigMap.name }}'

charts/capi-runtime-extensions/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ hooks:
3535
defaultValueTemplateConfigMap:
3636
create: true
3737
name: default-cilium-cni-helm-values-template
38+
nfd:
39+
crsStrategy:
40+
defaultInstallationConfigMap:
41+
name: node-feature-discovery
42+
helmAddonStrategy:
43+
defaultValueTemplateConfigMap:
44+
create: true
45+
name: default-nfd-helm-values-template
3846

3947
deployDefaultClusterClasses: true
4048

docs/content/addons/nfd.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ spec:
2525
- name: clusterConfig
2626
value:
2727
addons:
28-
nfd: {}
28+
nfd:
29+
strategy: HelmAddon
2930
```

examples/capi-quick-start/aws-cluster-calico-crs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ spec:
2828
csi:
2929
providers:
3030
- name: aws-ebs
31-
nfd: {}
31+
nfd:
32+
strategy: ClusterResourceSet
3233
aws:
3334
region: us-west-2
3435
version: ${KUBERNETES_VERSION}

examples/capi-quick-start/aws-cluster-calico-helm-addon.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ spec:
2828
csi:
2929
providers:
3030
- name: aws-ebs
31-
nfd: {}
31+
nfd:
32+
strategy: HelmAddon
3233
aws:
3334
region: us-west-2
3435
version: ${KUBERNETES_VERSION}

examples/capi-quick-start/aws-cluster-cilium-crs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ spec:
2828
csi:
2929
providers:
3030
- name: aws-ebs
31-
nfd: {}
31+
nfd:
32+
strategy: ClusterResourceSet
3233
aws:
3334
region: us-west-2
3435
version: ${KUBERNETES_VERSION}

examples/capi-quick-start/aws-cluster-cilium-helm-addon.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ spec:
2828
csi:
2929
providers:
3030
- name: aws-ebs
31-
nfd: {}
31+
nfd:
32+
strategy: HelmAddon
3233
aws:
3334
region: us-west-2
3435
version: ${KUBERNETES_VERSION}

examples/capi-quick-start/docker-cluster-calico-crs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ spec:
2525
cni:
2626
provider: Calico
2727
strategy: ClusterResourceSet
28-
nfd: {}
28+
nfd:
29+
strategy: ClusterResourceSet
2930
docker: {}
3031
version: ${KUBERNETES_VERSION}
3132
workers:

examples/capi-quick-start/docker-cluster-calico-helm-addon.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ spec:
2525
cni:
2626
provider: Calico
2727
strategy: HelmAddon
28-
nfd: {}
28+
nfd:
29+
strategy: HelmAddon
2930
docker: {}
3031
version: ${KUBERNETES_VERSION}
3132
workers:

examples/capi-quick-start/docker-cluster-cilium-crs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ spec:
2525
cni:
2626
provider: Cilium
2727
strategy: ClusterResourceSet
28-
nfd: {}
28+
nfd:
29+
strategy: ClusterResourceSet
2930
docker: {}
3031
version: ${KUBERNETES_VERSION}
3132
workers:

examples/capi-quick-start/docker-cluster-cilium-helm-addon.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ spec:
2525
cni:
2626
provider: Cilium
2727
strategy: HelmAddon
28-
nfd: {}
28+
nfd:
29+
strategy: HelmAddon
2930
docker: {}
3031
version: ${KUBERNETES_VERSION}
3132
workers:

hack/addons/update-node-feature-discovery-manifests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ envsubst -no-unset <"${KUSTOMIZE_BASE_DIR}/kustomization.yaml.tmpl" >"${ASSETS_D
2424
cp "${KUSTOMIZE_BASE_DIR}"/*.yaml "${ASSETS_DIR}"
2525
kustomize build --enable-helm "${ASSETS_DIR}" >"${ASSETS_DIR}/${FILE_NAME}"
2626

27-
kubectl create configmap node-feature-discovery --dry-run=client --output yaml \
27+
kubectl create configmap "{{ .Values.hooks.nfd.crsStrategy.defaultInstallationConfigMap.name }}" --dry-run=client --output yaml \
2828
--from-file "${ASSETS_DIR}/${FILE_NAME}" \
2929
>"${ASSETS_DIR}/node-feature-discovery-configmap.yaml"
3030

hack/examples/bases/aws/calico/crs/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ patches:
2424
cni:
2525
provider: Calico
2626
strategy: ClusterResourceSet
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: ClusterResourceSet
2731

2832
# Delete all ClusterClass related resources to prevent duplicate resources because we use the same resources definition
2933
# above- we only actually want the Cluster resource to mutate here.

hack/examples/bases/aws/calico/helm-addon/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ patches:
2424
cni:
2525
provider: Calico
2626
strategy: HelmAddon
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: HelmAddon

hack/examples/bases/aws/cilium/crs/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ patches:
2424
cni:
2525
provider: Cilium
2626
strategy: ClusterResourceSet
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: ClusterResourceSet
2731

2832
# Delete all ClusterClass related resources to prevent duplicate resources because we use the same resources definition
2933
# above- we only actually want the Cluster resource to mutate here.

hack/examples/bases/aws/cilium/helm-addon/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ patches:
2424
cni:
2525
provider: Cilium
2626
strategy: HelmAddon
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: HelmAddon
2731

2832
# Delete all ClusterClass related resources to prevent duplicate resources because we use the same resources definition
2933
# above- we only actually want the Cluster resource to mutate here.

hack/examples/bases/aws/kustomization.yaml.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ patches:
3232
path: "/spec/topology/variables/0/value/aws"
3333
value:
3434
region: us-west-2
35-
- op: "add"
36-
path: "/spec/topology/variables/0/value/addons/nfd"
37-
value: {}
3835
- op: "add"
3936
path: "/spec/topology/variables/0/value/addons/cpi"
4037
value: {}

hack/examples/bases/docker/calico/crs/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ patches:
2424
cni:
2525
provider: Calico
2626
strategy: ClusterResourceSet
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: ClusterResourceSet

hack/examples/bases/docker/calico/helm-addon/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ patches:
2424
cni:
2525
provider: Calico
2626
strategy: HelmAddon
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: HelmAddon

hack/examples/bases/docker/cilium/crs/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ patches:
2424
cni:
2525
provider: Cilium
2626
strategy: ClusterResourceSet
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: ClusterResourceSet

hack/examples/bases/docker/cilium/helm-addon/kustomization.yaml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ patches:
2424
cni:
2525
provider: Cilium
2626
strategy: HelmAddon
27+
- op: "add"
28+
path: "/spec/topology/variables/0/value/addons/nfd"
29+
value:
30+
strategy: HelmAddon

hack/examples/bases/docker/kustomization.yaml.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ patches:
3131
- op: "add"
3232
path: "/spec/topology/variables/0/value/docker"
3333
value: {}
34-
- op: "add"
35-
path: "/spec/topology/variables/0/value/addons/nfd"
36-
value: {}
3734
- op: "remove"
3835
path: "/spec/topology/workers/machinePools"
3936
- target:

make/addons.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
export CALICO_VERSION := $(shell goprintconst -file pkg/handlers/generic/lifecycle/cni/calico/strategy_helmaddon.go -name defaultCalicoHelmChartVersion)
55
export CILIUM_VERSION := $(shell goprintconst -file pkg/handlers/generic/lifecycle/cni/cilium/strategy_helmaddon.go -name defaultCiliumHelmChartVersion)
6-
export NODE_FEATURE_DISCOVERY_VERSION := 0.14.1
6+
export NODE_FEATURE_DISCOVERY_VERSION := $(shell goprintconst -file pkg/handlers/generic/lifecycle/nfd/strategy_helmaddon.go -name defaultHelmChartVersion)
77
export AWS_CSI_SNAPSHOT_CONTROLLER_VERSION := v6.3.0
88
export AWS_EBS_CSI_VERSION := v1.25.0
99
# a map of AWS CPI versions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cilium
66
import (
77
"context"
88
"fmt"
9-
"maps"
109

1110
"github.com/go-logr/logr"
1211
"github.com/spf13/pflag"
@@ -85,8 +84,9 @@ func (s crsStrategy) apply(
8584
Namespace: cluster.Namespace,
8685
Name: "cilium-cni-installation-" + cluster.Name,
8786
},
87+
Data: defaultCiliumConfigMap.Data,
88+
BinaryData: defaultCiliumConfigMap.BinaryData,
8889
}
89-
cm.Data = maps.Clone(defaultCiliumConfigMap.Data)
9090

9191
if err := client.ServerSideApply(ctx, s.client, cm); err != nil {
9292
return fmt.Errorf(
@@ -95,7 +95,7 @@ func (s crsStrategy) apply(
9595
)
9696
}
9797

98-
if err := utils.EnsureCRSForClusterFromConfigMaps(ctx, cm.Name, s.client, &req.Cluster, cm); err != nil {
98+
if err := utils.EnsureCRSForClusterFromConfigMaps(ctx, cm.Name, s.client, cluster, cm); err != nil {
9999
return fmt.Errorf(
100100
"failed to apply Cilium CNI installation ClusterResourceSet: %w",
101101
err,

pkg/handlers/generic/lifecycle/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
type Handlers struct {
2323
calicoCNIConfig *calico.CNIConfig
2424
ciliumCNIConfig *cilium.CNIConfig
25-
nfdConfig *nfd.NFDConfig
25+
nfdConfig *nfd.Config
2626
ebsConfig *awsebs.AWSEBSConfig
2727
awsCPIConfig *awscpi.AWSCPIConfig
2828
}
@@ -31,7 +31,7 @@ func New() *Handlers {
3131
return &Handlers{
3232
calicoCNIConfig: &calico.CNIConfig{},
3333
ciliumCNIConfig: &cilium.CNIConfig{},
34-
nfdConfig: &nfd.NFDConfig{},
34+
nfdConfig: &nfd.Config{},
3535
ebsConfig: &awsebs.AWSEBSConfig{},
3636
awsCPIConfig: &awscpi.AWSCPIConfig{},
3737
}

0 commit comments

Comments
 (0)