Skip to content

Commit 0b54c5b

Browse files
committed
feat: Add ClusterResourceSet strategy for CNI installation
Allows for further strategies to be added later, e.g. CAAPH.
1 parent cf711e5 commit 0b54c5b

File tree

16 files changed

+537
-440
lines changed

16 files changed

+537
-440
lines changed

api/v1alpha1/addon_types.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright 2024 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8+
9+
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
10+
)
11+
12+
type Addons struct {
13+
// +optional
14+
CNI *CNI `json:"cni,omitempty"`
15+
16+
// +optional
17+
NFD *NFD `json:"nfd,omitempty"`
18+
19+
// +optional
20+
CPI *CPI `json:"cpi,omitempty"`
21+
22+
// +optional
23+
CSIProviders *CSIProviders `json:"csi,omitempty"`
24+
}
25+
26+
func (Addons) VariableSchema() clusterv1.VariableSchema {
27+
return clusterv1.VariableSchema{
28+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
29+
Description: "Cluster configuration",
30+
Type: "object",
31+
Properties: map[string]clusterv1.JSONSchemaProps{
32+
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
33+
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
34+
"csi": CSIProviders{}.VariableSchema().OpenAPIV3Schema,
35+
"cpi": CPI{}.VariableSchema().OpenAPIV3Schema,
36+
},
37+
},
38+
}
39+
}
40+
41+
type AddonStrategy string
42+
43+
const (
44+
AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
45+
)
46+
47+
// CNI required for providing CNI configuration.
48+
type CNI struct {
49+
// +optional
50+
Provider string `json:"provider,omitempty"`
51+
// +optional
52+
Strategy AddonStrategy `json:"strategy,omitempty"`
53+
}
54+
55+
func (CNI) VariableSchema() clusterv1.VariableSchema {
56+
supportedCNIProviders := []string{CNIProviderCalico}
57+
58+
return clusterv1.VariableSchema{
59+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
60+
Type: "object",
61+
Properties: map[string]clusterv1.JSONSchemaProps{
62+
"provider": {
63+
Description: "CNI provider to deploy",
64+
Type: "string",
65+
Enum: variables.MustMarshalValuesToEnumJSON(supportedCNIProviders...),
66+
},
67+
"strategy": {
68+
Description: "Addon strategy used to deploy the CNI provider to the workload cluster",
69+
Type: "string",
70+
Enum: variables.MustMarshalValuesToEnumJSON(
71+
AddonStrategyClusterResourceSet,
72+
),
73+
},
74+
},
75+
Required: []string{"provider", "strategy"},
76+
},
77+
}
78+
}
79+
80+
// NFD tells us to enable or disable the node feature discovery addon.
81+
type NFD struct{}
82+
83+
func (NFD) VariableSchema() clusterv1.VariableSchema {
84+
return clusterv1.VariableSchema{
85+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
86+
Type: "object",
87+
},
88+
}
89+
}
90+
91+
type CSIProviders struct {
92+
// +optional
93+
Providers []CSIProvider `json:"providers,omitempty"`
94+
// +optional
95+
DefaultClassName string `json:"defaultClassName,omitempty"`
96+
}
97+
98+
type CSIProvider struct {
99+
Name string `json:"name,omitempty"`
100+
}
101+
102+
func (CSIProviders) VariableSchema() clusterv1.VariableSchema {
103+
supportedCSIProviders := []string{CSIProviderAWSEBS}
104+
return clusterv1.VariableSchema{
105+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
106+
Type: "object",
107+
Properties: map[string]clusterv1.JSONSchemaProps{
108+
"providers": {
109+
Type: "array",
110+
Items: &clusterv1.JSONSchemaProps{
111+
Type: "object",
112+
Properties: map[string]clusterv1.JSONSchemaProps{
113+
"name": {
114+
Type: "string",
115+
Enum: variables.MustMarshalValuesToEnumJSON(
116+
supportedCSIProviders...),
117+
},
118+
},
119+
},
120+
},
121+
"defaultClassName": {
122+
Type: "string",
123+
Enum: variables.MustMarshalValuesToEnumJSON(supportedCSIProviders...),
124+
},
125+
},
126+
},
127+
}
128+
}
129+
130+
// CPI tells us to enable or disable the cloud provider interface.
131+
type CPI struct{}
132+
133+
func (CPI) VariableSchema() clusterv1.VariableSchema {
134+
return clusterv1.VariableSchema{
135+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
136+
Type: "object",
137+
},
138+
}
139+
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1212

13-
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
1413
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
1514
)
1615

@@ -316,119 +315,6 @@ func (ImageRegistryCredentialsResource) VariableSchema() clusterv1.VariableSchem
316315
}
317316
}
318317

319-
type Addons struct {
320-
// +optional
321-
CNI *CNI `json:"cni,omitempty"`
322-
323-
// +optional
324-
NFD *NFD `json:"nfd,omitempty"`
325-
326-
// +optional
327-
CPI *CPI `json:"cpi,omitempty"`
328-
329-
// +optional
330-
CSIProviders *CSIProviders `json:"csi,omitempty"`
331-
}
332-
333-
func (Addons) VariableSchema() clusterv1.VariableSchema {
334-
return clusterv1.VariableSchema{
335-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
336-
Description: "Cluster configuration",
337-
Type: "object",
338-
Properties: map[string]clusterv1.JSONSchemaProps{
339-
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
340-
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
341-
"csi": CSIProviders{}.VariableSchema().OpenAPIV3Schema,
342-
"cpi": CPI{}.VariableSchema().OpenAPIV3Schema,
343-
},
344-
},
345-
}
346-
}
347-
348-
// CNI required for providing CNI configuration.
349-
type CNI struct {
350-
Provider string `json:"provider,omitempty"`
351-
}
352-
353-
func (CNI) VariableSchema() clusterv1.VariableSchema {
354-
supportedCNIProviders := []string{CNIProviderCalico}
355-
356-
return clusterv1.VariableSchema{
357-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
358-
Type: "object",
359-
Properties: map[string]clusterv1.JSONSchemaProps{
360-
"provider": {
361-
Description: "CNI provider to deploy",
362-
Type: "string",
363-
Enum: variables.MustMarshalValuesToEnumJSON(supportedCNIProviders...),
364-
},
365-
},
366-
Required: []string{"provider"},
367-
},
368-
}
369-
}
370-
371-
// NFD tells us to enable or disable the node feature discovery addon.
372-
type NFD struct{}
373-
374-
func (NFD) VariableSchema() clusterv1.VariableSchema {
375-
return clusterv1.VariableSchema{
376-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
377-
Type: "object",
378-
},
379-
}
380-
}
381-
382-
type CSIProviders struct {
383-
// +optional
384-
Providers []CSIProvider `json:"providers,omitempty"`
385-
// +optional
386-
DefaultClassName string `json:"defaultClassName,omitempty"`
387-
}
388-
389-
type CSIProvider struct {
390-
Name string `json:"name,omitempty"`
391-
}
392-
393-
func (CSIProviders) VariableSchema() clusterv1.VariableSchema {
394-
supportedCSIProviders := []string{CSIProviderAWSEBS}
395-
return clusterv1.VariableSchema{
396-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
397-
Type: "object",
398-
Properties: map[string]clusterv1.JSONSchemaProps{
399-
"providers": {
400-
Type: "array",
401-
Items: &clusterv1.JSONSchemaProps{
402-
Type: "object",
403-
Properties: map[string]clusterv1.JSONSchemaProps{
404-
"name": {
405-
Type: "string",
406-
Enum: variables.MustMarshalValuesToEnumJSON(
407-
supportedCSIProviders...),
408-
},
409-
},
410-
},
411-
},
412-
"defaultClassName": {
413-
Type: "string",
414-
Enum: variables.MustMarshalValuesToEnumJSON(supportedCSIProviders...),
415-
},
416-
},
417-
},
418-
}
419-
}
420-
421-
// CPI tells us to enable or disable the cloud provider interface.
422-
type CPI struct{}
423-
424-
func (CPI) VariableSchema() clusterv1.VariableSchema {
425-
return clusterv1.VariableSchema{
426-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
427-
Type: "object",
428-
},
429-
}
430-
}
431-
432318
func init() {
433319
SchemeBuilder.Register(&ClusterConfig{})
434320
}

charts/capi-runtime-extensions/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ A Helm chart for capi-runtime-extensions
3131
| deployDefaultClusterClasses | bool | `true` | |
3232
| deployment.replicas | int | `1` | |
3333
| env | object | `{}` | |
34-
| hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.content | string | `""` | |
35-
| hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.name | string | `"calico-cni-installation-awscluster"` | |
36-
| hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.create | bool | `true` | |
37-
| hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content | string | `""` | |
38-
| hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.name | string | `"calico-cni-installation-dockercluster"` | |
39-
| hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.create | bool | `true` | |
34+
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.content | string | `""` | |
35+
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.name | string | `"calico-cni-installation-awscluster"` | |
36+
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.create | bool | `true` | |
37+
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.content | string | `""` | |
38+
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.name | string | `"calico-cni-installation-dockercluster"` | |
39+
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.create | bool | `true` | |
40+
| hooks.CalicoCNI.crsStrategy.defaultTigeraOperatorConfigMap.name | string | `"tigera-operator"` | |
4041
| hooks.CalicoCNI.defaultPodSubnet | string | `"192.168.0.0/16"` | |
41-
| hooks.CalicoCNI.defaultTigeraOperatorConfigMap.name | string | `"tigera-operator"` | |
4242
| image.pullPolicy | string | `"IfNotPresent"` | |
4343
| image.repository | string | `"ghcr.io/d2iq-labs/capi-runtime-extensions"` | |
4444
| image.tag | string | `""` | |

charts/capi-runtime-extensions/templates/cni/calico/manifests/aws/installation.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Copyright 2023 D2iQ, Inc. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.create }}
4+
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.create }}
55
apiVersion: v1
66
kind: ConfigMap
77
metadata:
8-
name: '{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.name }}'
8+
name: '{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.name }}'
99
data:
1010
calico-installation: |
11-
{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.content -}}
12-
{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.content | nindent 4}}
11+
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.content -}}
12+
{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.content | nindent 4 }}
1313
{{- else -}}
1414
# This section includes base Calico installation configuration.
1515
# For more information, see: https://docs.projectcalico.org/reference/installation/api

charts/capi-runtime-extensions/templates/cni/calico/manifests/docker/installation.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Copyright 2023 D2iQ, Inc. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.create }}
4+
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.create }}
55
apiVersion: v1
66
kind: ConfigMap
77
metadata:
8-
name: '{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.name }}'
8+
name: '{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.name }}'
99
data:
1010
calico-installation: |
11-
{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content -}}
12-
{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content | nindent 4}}
11+
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.content -}}
12+
{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.content | nindent 4 }}
1313
{{- else -}}
1414
# This section includes base Calico installation configuration.
1515
# For more information, see: https://docs.projectcalico.org/reference/installation/api

charts/capi-runtime-extensions/templates/cni/calico/manifests/tigera-operator-configmap.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ data:
1212
kind: ConfigMap
1313
metadata:
1414
creationTimestamp: null
15-
name: '{{ .Values.hooks.CalicoCNI.defaultTigeraOperatorConfigMap.name }}'
15+
name: '{{ .Values.hooks.CalicoCNI.crsStrategy.defaultTigeraOperatorConfigMap.name
16+
}}'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ spec:
2929
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
3030
args:
3131
- --webhook-cert-dir=/runtimehooks-certs/
32-
- --calicocni.defaultsNamespace={{ .Release.Namespace }}
32+
- --calicocni.crs.defaultsNamespace={{ .Release.Namespace }}
3333
- --nfd.defaultsNamespace={{ .Release.Namespace }}
3434
{{- range $key, $value := .Values.extraArgs }}
3535
- --{{ $key }}={{ $value }}

charts/capi-runtime-extensions/values.yaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
hooks:
55
CalicoCNI:
66
defaultPodSubnet: 192.168.0.0/16
7-
defaultTigeraOperatorConfigMap:
8-
name: tigera-operator
9-
defaultInstallationConfigMaps:
10-
DockerCluster:
11-
create: true
12-
configMap:
13-
name: calico-cni-installation-dockercluster
14-
content: ""
15-
AWSCluster:
16-
create: true
17-
configMap:
18-
name: calico-cni-installation-awscluster
19-
content: ""
7+
crsStrategy:
8+
defaultTigeraOperatorConfigMap:
9+
name: tigera-operator
10+
defaultInstallationConfigMaps:
11+
DockerCluster:
12+
create: true
13+
configMap:
14+
name: calico-cni-installation-dockercluster
15+
content: ""
16+
AWSCluster:
17+
create: true
18+
configMap:
19+
name: calico-cni-installation-awscluster
20+
content: ""
2021

2122
deployDefaultClusterClasses: true
2223

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ spec:
2323
addons:
2424
cni:
2525
provider: calico
26+
strategy: ClusterResourceSet
2627
cpi: {}
2728
csi:
2829
providers:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spec:
2424
addons:
2525
cni:
2626
provider: calico
27+
strategy: ClusterResourceSet
2728
nfd: {}
2829
docker: {}
2930
version: v1.27.5

0 commit comments

Comments
 (0)