Skip to content

Commit b70ffab

Browse files
authored
fix: include Generic config specs in EKS cluster API (#1298)
**What problem does this PR solve?**: Stacked on #1297 This fixes the generic handlers for EKS clusters by properly exposing the `GenericClusterConfigSpec` API in `EKSClusterConfig`. The following fields are still aspirational and are not properly supported in the handlers for EKS, but they can be. ``` // +kubebuilder:validation:Optional Proxy *HTTPProxy `json:"proxy,omitempty"` // +kubebuilder:validation:Optional // +kubebuilder:validation:MaxItems=32 ImageRegistries []ImageRegistry `json:"imageRegistries,omitempty"` // +kubebuilder:validation:Optional GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"` ``` But these are working and I've added broken tests to verify before fixing the API. ``` // +kubebuilder:validation:Optional // +kubebuilder:validation:MaxItems=32 Users []User `json:"users,omitempty"` // NTP defines the NTP configuration for the cluster. // +kubebuilder:validation:Optional NTP *NTP `json:"ntp,omitempty"` ``` **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. --> **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. -->
1 parent 39e345f commit b70ffab

File tree

8 files changed

+253
-63
lines changed

8 files changed

+253
-63
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,33 @@ type NutanixClusterConfigSpec struct {
185185

186186
// +kubebuilder:object:root=true
187187

188+
// EKSClusterConfig is the Schema for the eksclusterconfigs API.
189+
type EKSClusterConfig struct {
190+
metav1.TypeMeta `json:",inline"`
191+
metav1.ObjectMeta `json:"metadata,omitempty"`
192+
193+
// +kubebuilder:validation:Optional
194+
Spec EKSClusterConfigSpec `json:"spec,omitempty"`
195+
}
196+
197+
func (s EKSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
198+
return eksClusterConfigVariableSchema
199+
}
200+
201+
// EKSClusterConfigSpec defines the desired state of ClusterConfig.
202+
type EKSClusterConfigSpec struct {
203+
// EKS cluster configuration.
204+
// +kubebuilder:validation:Optional
205+
EKS *EKSSpec `json:"eks,omitempty"`
206+
207+
GenericClusterConfigSpec `json:",inline"`
208+
209+
// +kubebuilder:validation:Optional
210+
Addons *AWSAddons `json:"addons,omitempty"`
211+
}
212+
213+
// +kubebuilder:object:root=true
214+
188215
// KubeadmClusterConfig is the Schema for the kubeadmconfigs API.
189216
type KubeadmClusterConfig struct {
190217
metav1.TypeMeta `json:",inline"`
@@ -257,31 +284,6 @@ type GenericClusterConfigSpec struct {
257284
NTP *NTP `json:"ntp,omitempty"`
258285
}
259286

260-
// +kubebuilder:object:root=true
261-
262-
// EKSClusterConfig is the Schema for the eksclusterconfigs API.
263-
type EKSClusterConfig struct {
264-
metav1.TypeMeta `json:",inline"`
265-
metav1.ObjectMeta `json:"metadata,omitempty"`
266-
267-
// +kubebuilder:validation:Optional
268-
Spec EKSClusterConfigSpec `json:"spec,omitempty"`
269-
}
270-
271-
func (s EKSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
272-
return eksClusterConfigVariableSchema
273-
}
274-
275-
// EKSClusterConfigSpec defines the desired state of ClusterConfig.
276-
type EKSClusterConfigSpec struct {
277-
// EKS cluster configuration.
278-
// +kubebuilder:validation:Optional
279-
EKS *EKSSpec `json:"eks,omitempty"`
280-
281-
// +kubebuilder:validation:Optional
282-
Addons *AWSAddons `json:"addons,omitempty"`
283-
}
284-
285287
type Image struct {
286288
// Repository is used to override the image repository to pull from.
287289
// +kubebuilder:validation:Optional
@@ -444,5 +446,6 @@ func init() {
444446
&AWSClusterConfig{},
445447
&DockerClusterConfig{},
446448
&NutanixClusterConfig{},
449+
&EKSClusterConfig{},
447450
)
448451
}

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

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,153 @@ spec:
349349
minLength: 4
350350
type: string
351351
type: object
352+
globalImageRegistryMirror:
353+
description: GlobalImageRegistryMirror sets default mirror configuration
354+
for all the image registries.
355+
properties:
356+
credentials:
357+
description: Credentials and CA certificate for the image registry
358+
mirror
359+
properties:
360+
secretRef:
361+
description: |-
362+
A reference to the Secret containing the registry credentials and optional CA certificate
363+
using the keys `username`, `password` and `ca.crt`.
364+
This credentials Secret is not required for some registries, e.g. ECR.
365+
properties:
366+
name:
367+
description: |-
368+
Name of the referent.
369+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
370+
maxLength: 253
371+
minLength: 1
372+
type: string
373+
required:
374+
- name
375+
type: object
376+
type: object
377+
url:
378+
description: Registry mirror URL.
379+
format: uri
380+
pattern: ^https?://
381+
type: string
382+
required:
383+
- url
384+
type: object
385+
imageRegistries:
386+
items:
387+
properties:
388+
credentials:
389+
description: Credentials and CA certificate for the image registry
390+
properties:
391+
secretRef:
392+
description: |-
393+
A reference to the Secret containing the registry credentials and optional CA certificate
394+
using the keys `username`, `password` and `ca.crt`.
395+
This credentials Secret is not required for some registries, e.g. ECR.
396+
properties:
397+
name:
398+
description: |-
399+
Name of the referent.
400+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
401+
maxLength: 253
402+
minLength: 1
403+
type: string
404+
required:
405+
- name
406+
type: object
407+
type: object
408+
url:
409+
description: Registry URL.
410+
format: uri
411+
pattern: ^https?://
412+
type: string
413+
required:
414+
- url
415+
type: object
416+
maxItems: 32
417+
type: array
418+
ntp:
419+
description: NTP defines the NTP configuration for the cluster.
420+
properties:
421+
servers:
422+
description: Servers is a list of NTP servers to use for time
423+
synchronization.
424+
items:
425+
maxLength: 253
426+
type: string
427+
maxItems: 16
428+
minItems: 1
429+
type: array
430+
required:
431+
- servers
432+
type: object
433+
proxy:
434+
description: HTTPProxy required for providing proxy configuration.
435+
properties:
436+
additionalNo:
437+
description: |-
438+
AdditionalNo Proxy list that will be added to the automatically calculated
439+
values that will apply no_proxy configuration for cluster internal network.
440+
Default values: localhost,127.0.0.1,<POD_NETWORK>,<SERVICE_NETWORK>,kubernetes
441+
,kubernetes.default,.svc,.svc.<SERVICE_DOMAIN>
442+
items:
443+
maxLength: 253
444+
minLength: 1
445+
type: string
446+
maxItems: 128
447+
type: array
448+
http:
449+
description: HTTP proxy value.
450+
maxLength: 2048
451+
minLength: 1
452+
type: string
453+
https:
454+
description: HTTPS proxy value.
455+
maxLength: 2048
456+
minLength: 1
457+
type: string
458+
type: object
459+
users:
460+
items:
461+
description: User defines the input for a generated user in cloud-init.
462+
properties:
463+
hashedPassword:
464+
description: |-
465+
HashedPassword is a hashed password for the user, formatted as described
466+
by the crypt(5) man page. See your distribution's documentation for
467+
instructions to create a hashed password.
468+
An empty string is not marshalled, because it is not a valid value.
469+
maxLength: 106
470+
minLength: 1
471+
type: string
472+
name:
473+
description: Name specifies the user name.
474+
maxLength: 256
475+
type: string
476+
sshAuthorizedKeys:
477+
description: |-
478+
SSHAuthorizedKeys is a list of public SSH keys to write to the
479+
machine. Use the corresponding private SSH keys to authenticate. See SSH
480+
documentation for instructions to create a key pair.
481+
items:
482+
maxLength: 256
483+
type: string
484+
maxItems: 32
485+
type: array
486+
sudo:
487+
description: |-
488+
Sudo is a sudo user specification, formatted as described in the sudo
489+
documentation.
490+
An empty string is not marshalled, because it is not a valid value.
491+
maxLength: 1024
492+
minLength: 1
493+
type: string
494+
required:
495+
- name
496+
type: object
497+
maxItems: 32
498+
type: array
352499
type: object
353500
type: object
354501
served: true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ spec:
149149
- effect
150150
- key
151151
type: object
152+
maxItems: 32
152153
type: array
153154
type: object
154155
type: object

api/v1alpha1/nodeconfig_types.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,6 @@ type NutanixWorkerNodeConfigSpec struct {
108108
GenericNodeSpec `json:",inline"`
109109
}
110110

111-
type KubeadmNodeSpec struct {
112-
// NodeRegistration holds fields that relate to registering the new node to the cluster.
113-
// +kubebuilder:validation:Optional
114-
// +kubebuilder:default={}
115-
NodeRegistration *NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
116-
}
117-
118-
type GenericNodeSpec struct {
119-
// Taints specifies the taints the Node API object should be registered with.
120-
// +kubebuilder:validation:Optional
121-
// +kubebuilder:validation:MaxItems=32
122-
Taints []Taint `json:"taints,omitempty"`
123-
}
124-
125111
// +kubebuilder:object:root=true
126112

127113
// EKSWorkerNodeConfig is the Schema for the eksnodeconfigs API.
@@ -144,12 +130,23 @@ type EKSWorkerNodeConfigSpec struct {
144130
// +kubebuilder:validation:Optional
145131
EKS *AWSWorkerNodeSpec `json:"eks,omitempty"`
146132

147-
EKSNodeSpec `json:",inline"`
133+
EKSNodeSpec `json:",inline"`
134+
GenericNodeSpec `json:",inline"`
135+
}
136+
137+
type EKSNodeSpec struct{}
138+
139+
type KubeadmNodeSpec struct {
140+
// NodeRegistration holds fields that relate to registering the new node to the cluster.
141+
// +kubebuilder:validation:Optional
142+
// +kubebuilder:default={}
143+
NodeRegistration *NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
148144
}
149145

150-
type EKSNodeSpec struct {
146+
type GenericNodeSpec struct {
151147
// Taints specifies the taints the Node API object should be registered with.
152148
// +kubebuilder:validation:Optional
149+
// +kubebuilder:validation:MaxItems=32
153150
Taints []Taint `json:"taints,omitempty"`
154151
}
155152

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/handlers/generic/mutation/ntp/variables_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1313
awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig"
1414
dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig"
15+
eksclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/eks/clusterconfig"
1516
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
1617
)
1718

@@ -74,3 +75,14 @@ func TestVariableValidation_Nutanix(t *testing.T) {
7475
testDefs...,
7576
)
7677
}
78+
79+
func TestVariableValidation_EKS(t *testing.T) {
80+
capitest.ValidateDiscoverVariables(
81+
t,
82+
v1alpha1.ClusterConfigVariableName,
83+
ptr.To(v1alpha1.EKSClusterConfig{}.VariableSchema()),
84+
true,
85+
eksclusterconfig.NewVariable,
86+
testDefs...,
87+
)
88+
}

pkg/handlers/generic/mutation/taints/variables_test.go

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,48 @@ import (
1010

1111
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1212
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
13-
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
13+
eksworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/eks/workerconfig"
14+
nutanixworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/workerconfig"
1415
)
1516

16-
func TestVariableValidation(t *testing.T) {
17+
func TestVariableValidation_Nutanix(t *testing.T) {
1718
capitest.ValidateDiscoverVariables(
1819
t,
19-
v1alpha1.ClusterConfigVariableName,
20-
ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()),
21-
true,
22-
nutanixclusterconfig.NewVariable,
20+
v1alpha1.WorkerConfigVariableName,
21+
ptr.To(v1alpha1.NutanixWorkerNodeConfig{}.VariableSchema()),
22+
false,
23+
nutanixworkerconfig.NewVariable,
2324
capitest.VariableTestDef{
24-
Name: "specified instance type",
25-
Vals: v1alpha1.NutanixClusterConfigSpec{
26-
ControlPlane: &v1alpha1.NutanixControlPlaneSpec{
27-
GenericNodeSpec: v1alpha1.GenericNodeSpec{
28-
Taints: []v1alpha1.Taint{{
29-
Key: "key",
30-
Effect: v1alpha1.TaintEffectNoExecute,
31-
Value: "value",
32-
}},
33-
},
25+
Name: "specified nodepool taints",
26+
Vals: v1alpha1.NutanixWorkerNodeConfigSpec{
27+
GenericNodeSpec: v1alpha1.GenericNodeSpec{
28+
Taints: []v1alpha1.Taint{{
29+
Key: "key",
30+
Effect: v1alpha1.TaintEffectNoExecute,
31+
Value: "value",
32+
}},
33+
},
34+
},
35+
},
36+
)
37+
}
38+
39+
func TestVariableValidation_EKS(t *testing.T) {
40+
capitest.ValidateDiscoverVariables(
41+
t,
42+
v1alpha1.WorkerConfigVariableName,
43+
ptr.To(v1alpha1.EKSWorkerNodeConfig{}.VariableSchema()),
44+
false,
45+
eksworkerconfig.NewVariable,
46+
capitest.VariableTestDef{
47+
Name: "specified nodepool taints",
48+
Vals: v1alpha1.EKSWorkerNodeConfigSpec{
49+
GenericNodeSpec: v1alpha1.GenericNodeSpec{
50+
Taints: []v1alpha1.Taint{{
51+
Key: "key",
52+
Effect: v1alpha1.TaintEffectNoExecute,
53+
Value: "value",
54+
}},
3455
},
3556
},
3657
},

0 commit comments

Comments
 (0)