Skip to content

Commit 39e345f

Browse files
authored
refactor: keep only common types in Generic config specs (#1297)
**What problem does this PR solve?**: After EKS types were introduced, the fields in `GenericClusterConfigSpec` and `GenericNodeSpec` are no longer all "generic" because some do not apply to EKS clusters, as it does not use kubeadm to create the cluster. This PR attempts to address this by only keeping the fields that can be set for both EKS and all other infra types in `GenericClusterConfigSpec` and moves the rest of the fields to `KubeadmClusterConfigSpec`, and similarly for `GenericNodeSpec`. Because the structs are included `inline` in the individual Cluster types this does not change the external yaml API, only how they are referenced in Go (notice how the CRDs for <aws|docker|nutanix>clusterconfigs did not change). **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> Unit tests. **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. --> If we agree with this approach I will have separate refactor PRs to reorganize the handlers and the public docs.
1 parent 41f63b8 commit 39e345f

18 files changed

+313
-186
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var (
3232
awsClusterConfigCRDDefinition []byte
3333
//go:embed crds/caren.nutanix.com_nutanixclusterconfigs.yaml
3434
nutanixClusterConfigCRDDefinition []byte
35+
//go:embed crds/caren.nutanix.com_kubeadmclusterconfigs.yaml
36+
kubeadmClusterConfigCRDDefinition []byte
3537
//go:embed crds/caren.nutanix.com_genericclusterconfigs.yaml
3638
genericClusterConfigCRDDefinition []byte
3739
//go:embed crds/caren.nutanix.com_eksclusterconfigs.yaml
@@ -46,6 +48,9 @@ var (
4648
nutanixClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML(
4749
nutanixClusterConfigCRDDefinition,
4850
)
51+
kubeadmClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML(
52+
kubeadmClusterConfigCRDDefinition,
53+
)
4954
genericClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML(
5055
genericClusterConfigCRDDefinition,
5156
)
@@ -75,6 +80,7 @@ type AWSClusterConfigSpec struct {
7580
// +kubebuilder:validation:Optional
7681
AWS *AWSSpec `json:"aws,omitempty"`
7782

83+
KubeadmClusterConfigSpec `json:",inline"`
7884
GenericClusterConfigSpec `json:",inline"`
7985

8086
// +kubebuilder:validation:Optional
@@ -112,6 +118,7 @@ type DockerClusterConfigSpec struct {
112118
// +kubebuilder:validation:Optional
113119
Docker *DockerSpec `json:"docker,omitempty"`
114120

121+
KubeadmClusterConfigSpec `json:",inline"`
115122
GenericClusterConfigSpec `json:",inline"`
116123

117124
// +kubebuilder:validation:Optional
@@ -154,6 +161,7 @@ type NutanixClusterConfigSpec struct {
154161
// +kubebuilder:validation:Optional
155162
Nutanix *NutanixSpec `json:"nutanix,omitempty"`
156163

164+
KubeadmClusterConfigSpec `json:",inline"`
157165
GenericClusterConfigSpec `json:",inline"`
158166

159167
// +kubebuilder:validation:Optional
@@ -177,29 +185,21 @@ type NutanixClusterConfigSpec struct {
177185

178186
// +kubebuilder:object:root=true
179187

180-
// GenericClusterConfig is the Schema for the genericclusterconfigs API.
181-
type GenericClusterConfig struct {
188+
// KubeadmClusterConfig is the Schema for the kubeadmconfigs API.
189+
type KubeadmClusterConfig struct {
182190
metav1.TypeMeta `json:",inline"`
183191
metav1.ObjectMeta `json:"metadata,omitempty"`
184192

185193
// +kubebuilder:validation:Optional
186-
Spec *GenericClusterConfigSpec `json:"spec,omitempty"`
187-
188-
// Extra Subject Alternative Names for the API Server signing cert.
189-
// +kubebuilder:validation:UniqueItems=true
190-
// +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
191-
// +kubebuilder:validation:Optional
192-
// +kubebuilder:validation:MaxItems=100
193-
// +kubebuilder:validation:items:MaxLength=253
194-
ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"`
194+
Spec KubeadmClusterConfigSpec `json:"spec,omitempty"`
195195
}
196196

197-
func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
198-
return genericClusterConfigVariableSchema
197+
func (s KubeadmClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
198+
return kubeadmClusterConfigVariableSchema
199199
}
200200

201-
// GenericClusterConfigSpec defines the desired state of GenericClusterConfig.
202-
type GenericClusterConfigSpec struct {
201+
// KubeadmConfigSpec defines configuration that can be set when using kubeadm to bootstrap the cluster.
202+
type KubeadmClusterConfigSpec struct {
203203
// Sets the Kubernetes image repository used for the KubeadmControlPlane.
204204
// +kubebuilder:validation:Optional
205205
// +kubebuilder:validation:Pattern=`^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$`
@@ -211,28 +211,46 @@ type GenericClusterConfigSpec struct {
211211
Etcd *Etcd `json:"etcd,omitempty"`
212212

213213
// +kubebuilder:validation:Optional
214-
Proxy *HTTPProxy `json:"proxy,omitempty"`
214+
EncryptionAtRest *EncryptionAtRest `json:"encryptionAtRest,omitempty"`
215215

216216
// +kubebuilder:validation:Optional
217-
// +kubebuilder:validation:MaxItems=32
218-
ImageRegistries []ImageRegistry `json:"imageRegistries,omitempty"`
217+
DNS *DNS `json:"dns,omitempty"`
219218

219+
// KubeProxy defines the configuration for kube-proxy.
220220
// +kubebuilder:validation:Optional
221-
GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"`
221+
KubeProxy *KubeProxy `json:"kubeProxy,omitempty"`
222+
}
223+
224+
// +kubebuilder:object:root=true
225+
226+
// GenericClusterConfig is the Schema for the genericclusterconfigs API.
227+
type GenericClusterConfig struct {
228+
metav1.TypeMeta `json:",inline"`
229+
metav1.ObjectMeta `json:"metadata,omitempty"`
222230

223231
// +kubebuilder:validation:Optional
224-
// +kubebuilder:validation:MaxItems=32
225-
Users []User `json:"users,omitempty"`
232+
Spec *GenericClusterConfigSpec `json:"spec,omitempty"`
233+
}
226234

235+
func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
236+
return genericClusterConfigVariableSchema
237+
}
238+
239+
// GenericClusterConfigSpec defines the desired state of GenericClusterConfig.
240+
type GenericClusterConfigSpec struct {
227241
// +kubebuilder:validation:Optional
228-
EncryptionAtRest *EncryptionAtRest `json:"encryptionAtRest,omitempty"`
242+
Proxy *HTTPProxy `json:"proxy,omitempty"`
229243

230244
// +kubebuilder:validation:Optional
231-
DNS *DNS `json:"dns,omitempty"`
245+
// +kubebuilder:validation:MaxItems=32
246+
ImageRegistries []ImageRegistry `json:"imageRegistries,omitempty"`
232247

233-
// KubeProxy defines the configuration for kube-proxy.
234248
// +kubebuilder:validation:Optional
235-
KubeProxy *KubeProxy `json:"kubeProxy,omitempty"`
249+
GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"`
250+
251+
// +kubebuilder:validation:Optional
252+
// +kubebuilder:validation:MaxItems=32
253+
Users []User `json:"users,omitempty"`
236254

237255
// NTP defines the NTP configuration for the cluster.
238256
// +kubebuilder:validation:Optional

api/v1alpha1/controlplane_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type DockerControlPlaneSpec struct {
2626

2727
GenericControlPlaneSpec `json:",inline"`
2828

29+
KubeadmNodeSpec `json:",inline"`
2930
GenericNodeSpec `json:",inline"`
3031
}
3132

@@ -36,6 +37,7 @@ type NutanixControlPlaneSpec struct {
3637

3738
GenericControlPlaneSpec `json:",inline"`
3839

40+
KubeadmNodeSpec `json:",inline"`
3941
GenericNodeSpec `json:",inline"`
4042
}
4143

@@ -46,5 +48,6 @@ type AWSControlPlaneSpec struct {
4648

4749
GenericControlPlaneSpec `json:",inline"`
4850

51+
KubeadmNodeSpec `json:",inline"`
4952
GenericNodeSpec `json:",inline"`
5053
}

api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ spec:
427427
type: object
428428
nodeRegistration:
429429
default: {}
430-
description: NodeRegistration holds fields that relate to registering the new control-plane node to the cluster.
430+
description: NodeRegistration holds fields that relate to registering the new node to the cluster.
431431
properties:
432432
ignorePreflightErrors:
433433
default:

api/v1alpha1/crds/caren.nutanix.com_awsworkernodeconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ spec:
121121
nodeRegistration:
122122
default: {}
123123
description: NodeRegistration holds fields that relate to registering
124-
the new control-plane node to the cluster.
124+
the new node to the cluster.
125125
properties:
126126
ignorePreflightErrors:
127127
default:

api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ spec:
328328
type: object
329329
nodeRegistration:
330330
default: {}
331-
description: NodeRegistration holds fields that relate to registering the new control-plane node to the cluster.
331+
description: NodeRegistration holds fields that relate to registering the new node to the cluster.
332332
properties:
333333
ignorePreflightErrors:
334334
default:

api/v1alpha1/crds/caren.nutanix.com_dockerworkernodeconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ spec:
7373
nodeRegistration:
7474
default: {}
7575
description: NodeRegistration holds fields that relate to registering
76-
the new control-plane node to the cluster.
76+
the new node to the cluster.
7777
properties:
7878
ignorePreflightErrors:
7979
default:

api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ spec:
2929
may reject unrecognized values.
3030
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
3131
type: string
32-
extraAPIServerCertSANs:
33-
description: Extra Subject Alternative Names for the API Server signing
34-
cert.
35-
items:
36-
maxLength: 253
37-
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
38-
type: string
39-
maxItems: 100
40-
type: array
41-
uniqueItems: true
4232
kind:
4333
description: |-
4434
Kind is a string value representing the REST resource this object represents.
@@ -52,76 +42,6 @@ spec:
5242
spec:
5343
description: GenericClusterConfigSpec defines the desired state of GenericClusterConfig.
5444
properties:
55-
dns:
56-
description: DNS defines the DNS configuration for the cluster.
57-
properties:
58-
coreDNS:
59-
description: CoreDNS defines the CoreDNS configuration for the
60-
cluster.
61-
properties:
62-
image:
63-
description: |-
64-
Image required for overriding Kubernetes DNS image details.
65-
If the image version is not specified,
66-
the default version based on the cluster's Kubernetes version will be used.
67-
properties:
68-
repository:
69-
description: Repository is used to override the image
70-
repository to pull from.
71-
maxLength: 2048
72-
minLength: 1
73-
pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$
74-
type: string
75-
tag:
76-
description: Tag is used to override the default image
77-
tag.
78-
maxLength: 128
79-
minLength: 1
80-
pattern: ^[\w][\w.-]{0,127}$
81-
type: string
82-
type: object
83-
type: object
84-
type: object
85-
encryptionAtRest:
86-
description: |-
87-
EncryptionAtRest defines the configuration to enable encryption at REST
88-
This configuration is used by API server to encrypt data before storing it in ETCD.
89-
Currently the encryption only enabled for secrets and configmaps.
90-
properties:
91-
providers:
92-
default:
93-
- aescbc: {}
94-
description: Encryption providers
95-
items:
96-
properties:
97-
aescbc:
98-
type: object
99-
secretbox:
100-
type: object
101-
type: object
102-
maxItems: 1
103-
type: array
104-
type: object
105-
etcd:
106-
properties:
107-
image:
108-
description: Image required for overriding etcd image details.
109-
properties:
110-
repository:
111-
description: Repository is used to override the image repository
112-
to pull from.
113-
maxLength: 2048
114-
minLength: 1
115-
pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$
116-
type: string
117-
tag:
118-
description: Tag is used to override the default image tag.
119-
maxLength: 128
120-
minLength: 1
121-
pattern: ^[\w][\w.-]{0,127}$
122-
type: string
123-
type: object
124-
type: object
12545
globalImageRegistryMirror:
12646
description: GlobalImageRegistryMirror sets default mirror configuration
12747
for all the image registries.
@@ -188,28 +108,6 @@ spec:
188108
type: object
189109
maxItems: 32
190110
type: array
191-
kubeProxy:
192-
description: KubeProxy defines the configuration for kube-proxy.
193-
properties:
194-
mode:
195-
description: |-
196-
Mode specifies the mode for kube-proxy:
197-
- iptables means that kube-proxy is installed in iptables mode.
198-
- nftables means that kube-proxy is installed in nftables mode.
199-
enum:
200-
- iptables
201-
- nftables
202-
type: string
203-
x-kubernetes-validations:
204-
- message: Value cannot be changed after cluster creation
205-
rule: self == oldSelf
206-
type: object
207-
kubernetesImageRepository:
208-
description: Sets the Kubernetes image repository used for the KubeadmControlPlane.
209-
maxLength: 2048
210-
minLength: 1
211-
pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$
212-
type: string
213111
ntp:
214112
description: NTP defines the NTP configuration for the cluster.
215113
properties:

0 commit comments

Comments
 (0)