diff --git a/api/v1alpha1/clusterconfig_types.go b/api/v1alpha1/clusterconfig_types.go index d62e558ce..a4b09ba42 100644 --- a/api/v1alpha1/clusterconfig_types.go +++ b/api/v1alpha1/clusterconfig_types.go @@ -185,6 +185,33 @@ type NutanixClusterConfigSpec struct { // +kubebuilder:object:root=true +// EKSClusterConfig is the Schema for the eksclusterconfigs API. +type EKSClusterConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +kubebuilder:validation:Optional + Spec EKSClusterConfigSpec `json:"spec,omitempty"` +} + +func (s EKSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return eksClusterConfigVariableSchema +} + +// EKSClusterConfigSpec defines the desired state of ClusterConfig. +type EKSClusterConfigSpec struct { + // EKS cluster configuration. + // +kubebuilder:validation:Optional + EKS *EKSSpec `json:"eks,omitempty"` + + GenericClusterConfigSpec `json:",inline"` + + // +kubebuilder:validation:Optional + Addons *AWSAddons `json:"addons,omitempty"` +} + +// +kubebuilder:object:root=true + // KubeadmClusterConfig is the Schema for the kubeadmconfigs API. type KubeadmClusterConfig struct { metav1.TypeMeta `json:",inline"` @@ -257,31 +284,6 @@ type GenericClusterConfigSpec struct { NTP *NTP `json:"ntp,omitempty"` } -// +kubebuilder:object:root=true - -// EKSClusterConfig is the Schema for the eksclusterconfigs API. -type EKSClusterConfig struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // +kubebuilder:validation:Optional - Spec EKSClusterConfigSpec `json:"spec,omitempty"` -} - -func (s EKSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. - return eksClusterConfigVariableSchema -} - -// EKSClusterConfigSpec defines the desired state of ClusterConfig. -type EKSClusterConfigSpec struct { - // EKS cluster configuration. - // +kubebuilder:validation:Optional - EKS *EKSSpec `json:"eks,omitempty"` - - // +kubebuilder:validation:Optional - Addons *AWSAddons `json:"addons,omitempty"` -} - type Image struct { // Repository is used to override the image repository to pull from. // +kubebuilder:validation:Optional @@ -444,5 +446,6 @@ func init() { &AWSClusterConfig{}, &DockerClusterConfig{}, &NutanixClusterConfig{}, + &EKSClusterConfig{}, ) } diff --git a/api/v1alpha1/crds/caren.nutanix.com_eksclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_eksclusterconfigs.yaml index 4ed89f8ee..dc15edfa9 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_eksclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_eksclusterconfigs.yaml @@ -349,6 +349,153 @@ spec: minLength: 4 type: string type: object + globalImageRegistryMirror: + description: GlobalImageRegistryMirror sets default mirror configuration + for all the image registries. + properties: + credentials: + description: Credentials and CA certificate for the image registry + mirror + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + maxLength: 253 + minLength: 1 + type: string + required: + - name + type: object + type: object + url: + description: Registry mirror URL. + format: uri + pattern: ^https?:// + type: string + required: + - url + type: object + imageRegistries: + items: + properties: + credentials: + description: Credentials and CA certificate for the image registry + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + maxLength: 253 + minLength: 1 + type: string + required: + - name + type: object + type: object + url: + description: Registry URL. + format: uri + pattern: ^https?:// + type: string + required: + - url + type: object + maxItems: 32 + type: array + ntp: + description: NTP defines the NTP configuration for the cluster. + properties: + servers: + description: Servers is a list of NTP servers to use for time + synchronization. + items: + maxLength: 253 + type: string + maxItems: 16 + minItems: 1 + type: array + required: + - servers + type: object + proxy: + description: HTTPProxy required for providing proxy configuration. + properties: + additionalNo: + description: |- + AdditionalNo Proxy list that will be added to the automatically calculated + values that will apply no_proxy configuration for cluster internal network. + Default values: localhost,127.0.0.1,,,kubernetes + ,kubernetes.default,.svc,.svc. + items: + maxLength: 253 + minLength: 1 + type: string + maxItems: 128 + type: array + http: + description: HTTP proxy value. + maxLength: 2048 + minLength: 1 + type: string + https: + description: HTTPS proxy value. + maxLength: 2048 + minLength: 1 + type: string + type: object + users: + items: + description: User defines the input for a generated user in cloud-init. + properties: + hashedPassword: + description: |- + HashedPassword is a hashed password for the user, formatted as described + by the crypt(5) man page. See your distribution's documentation for + instructions to create a hashed password. + An empty string is not marshalled, because it is not a valid value. + maxLength: 106 + minLength: 1 + type: string + name: + description: Name specifies the user name. + maxLength: 256 + type: string + sshAuthorizedKeys: + description: |- + SSHAuthorizedKeys is a list of public SSH keys to write to the + machine. Use the corresponding private SSH keys to authenticate. See SSH + documentation for instructions to create a key pair. + items: + maxLength: 256 + type: string + maxItems: 32 + type: array + sudo: + description: |- + Sudo is a sudo user specification, formatted as described in the sudo + documentation. + An empty string is not marshalled, because it is not a valid value. + maxLength: 1024 + minLength: 1 + type: string + required: + - name + type: object + maxItems: 32 + type: array type: object type: object served: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_eksworkernodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_eksworkernodeconfigs.yaml index e12f1c437..bb1e0306a 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_eksworkernodeconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_eksworkernodeconfigs.yaml @@ -149,6 +149,7 @@ spec: - effect - key type: object + maxItems: 32 type: array type: object type: object diff --git a/api/v1alpha1/nodeconfig_types.go b/api/v1alpha1/nodeconfig_types.go index 97bd3d392..25a053359 100644 --- a/api/v1alpha1/nodeconfig_types.go +++ b/api/v1alpha1/nodeconfig_types.go @@ -108,20 +108,6 @@ type NutanixWorkerNodeConfigSpec struct { GenericNodeSpec `json:",inline"` } -type KubeadmNodeSpec struct { - // NodeRegistration holds fields that relate to registering the new node to the cluster. - // +kubebuilder:validation:Optional - // +kubebuilder:default={} - NodeRegistration *NodeRegistrationOptions `json:"nodeRegistration,omitempty"` -} - -type GenericNodeSpec struct { - // Taints specifies the taints the Node API object should be registered with. - // +kubebuilder:validation:Optional - // +kubebuilder:validation:MaxItems=32 - Taints []Taint `json:"taints,omitempty"` -} - // +kubebuilder:object:root=true // EKSWorkerNodeConfig is the Schema for the eksnodeconfigs API. @@ -144,12 +130,23 @@ type EKSWorkerNodeConfigSpec struct { // +kubebuilder:validation:Optional EKS *AWSWorkerNodeSpec `json:"eks,omitempty"` - EKSNodeSpec `json:",inline"` + EKSNodeSpec `json:",inline"` + GenericNodeSpec `json:",inline"` +} + +type EKSNodeSpec struct{} + +type KubeadmNodeSpec struct { + // NodeRegistration holds fields that relate to registering the new node to the cluster. + // +kubebuilder:validation:Optional + // +kubebuilder:default={} + NodeRegistration *NodeRegistrationOptions `json:"nodeRegistration,omitempty"` } -type EKSNodeSpec struct { +type GenericNodeSpec struct { // Taints specifies the taints the Node API object should be registered with. // +kubebuilder:validation:Optional + // +kubebuilder:validation:MaxItems=32 Taints []Taint `json:"taints,omitempty"` } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 5092c1fb7..96c2a4c47 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -988,6 +988,7 @@ func (in *EKSClusterConfigSpec) DeepCopyInto(out *EKSClusterConfigSpec) { *out = new(EKSSpec) (*in).DeepCopyInto(*out) } + in.GenericClusterConfigSpec.DeepCopyInto(&out.GenericClusterConfigSpec) if in.Addons != nil { in, out := &in.Addons, &out.Addons *out = new(AWSAddons) @@ -1008,11 +1009,6 @@ func (in *EKSClusterConfigSpec) DeepCopy() *EKSClusterConfigSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EKSNodeSpec) DeepCopyInto(out *EKSNodeSpec) { *out = *in - if in.Taints != nil { - in, out := &in.Taints, &out.Taints - *out = make([]Taint, len(*in)) - copy(*out, *in) - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EKSNodeSpec. @@ -1084,7 +1080,8 @@ func (in *EKSWorkerNodeConfigSpec) DeepCopyInto(out *EKSWorkerNodeConfigSpec) { *out = new(AWSWorkerNodeSpec) (*in).DeepCopyInto(*out) } - in.EKSNodeSpec.DeepCopyInto(&out.EKSNodeSpec) + out.EKSNodeSpec = in.EKSNodeSpec + in.GenericNodeSpec.DeepCopyInto(&out.GenericNodeSpec) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EKSWorkerNodeConfigSpec. diff --git a/pkg/handlers/generic/mutation/ntp/variables_test.go b/pkg/handlers/generic/mutation/ntp/variables_test.go index aa44f9f24..7f150b704 100644 --- a/pkg/handlers/generic/mutation/ntp/variables_test.go +++ b/pkg/handlers/generic/mutation/ntp/variables_test.go @@ -12,6 +12,7 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" + eksclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/eks/clusterconfig" nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) @@ -74,3 +75,14 @@ func TestVariableValidation_Nutanix(t *testing.T) { testDefs..., ) } + +func TestVariableValidation_EKS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + v1alpha1.ClusterConfigVariableName, + ptr.To(v1alpha1.EKSClusterConfig{}.VariableSchema()), + true, + eksclusterconfig.NewVariable, + testDefs..., + ) +} diff --git a/pkg/handlers/generic/mutation/taints/variables_test.go b/pkg/handlers/generic/mutation/taints/variables_test.go index ddd20cacb..d361a585f 100644 --- a/pkg/handlers/generic/mutation/taints/variables_test.go +++ b/pkg/handlers/generic/mutation/taints/variables_test.go @@ -10,27 +10,48 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" - nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" + eksworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/eks/workerconfig" + nutanixworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/workerconfig" ) -func TestVariableValidation(t *testing.T) { +func TestVariableValidation_Nutanix(t *testing.T) { capitest.ValidateDiscoverVariables( t, - v1alpha1.ClusterConfigVariableName, - ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), - true, - nutanixclusterconfig.NewVariable, + v1alpha1.WorkerConfigVariableName, + ptr.To(v1alpha1.NutanixWorkerNodeConfig{}.VariableSchema()), + false, + nutanixworkerconfig.NewVariable, capitest.VariableTestDef{ - Name: "specified instance type", - Vals: v1alpha1.NutanixClusterConfigSpec{ - ControlPlane: &v1alpha1.NutanixControlPlaneSpec{ - GenericNodeSpec: v1alpha1.GenericNodeSpec{ - Taints: []v1alpha1.Taint{{ - Key: "key", - Effect: v1alpha1.TaintEffectNoExecute, - Value: "value", - }}, - }, + Name: "specified nodepool taints", + Vals: v1alpha1.NutanixWorkerNodeConfigSpec{ + GenericNodeSpec: v1alpha1.GenericNodeSpec{ + Taints: []v1alpha1.Taint{{ + Key: "key", + Effect: v1alpha1.TaintEffectNoExecute, + Value: "value", + }}, + }, + }, + }, + ) +} + +func TestVariableValidation_EKS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + v1alpha1.WorkerConfigVariableName, + ptr.To(v1alpha1.EKSWorkerNodeConfig{}.VariableSchema()), + false, + eksworkerconfig.NewVariable, + capitest.VariableTestDef{ + Name: "specified nodepool taints", + Vals: v1alpha1.EKSWorkerNodeConfigSpec{ + GenericNodeSpec: v1alpha1.GenericNodeSpec{ + Taints: []v1alpha1.Taint{{ + Key: "key", + Effect: v1alpha1.TaintEffectNoExecute, + Value: "value", + }}, }, }, }, diff --git a/pkg/handlers/generic/mutation/users/variables_test.go b/pkg/handlers/generic/mutation/users/variables_test.go index c196f1dc6..34b7ff2c7 100644 --- a/pkg/handlers/generic/mutation/users/variables_test.go +++ b/pkg/handlers/generic/mutation/users/variables_test.go @@ -12,6 +12,7 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" + eksclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/eks/clusterconfig" nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) @@ -67,3 +68,14 @@ func TestVariableValidation_Nutanix(t *testing.T) { testDefs..., ) } + +func TestVariableValidation_EKS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + v1alpha1.ClusterConfigVariableName, + ptr.To(v1alpha1.EKSClusterConfig{}.VariableSchema()), + true, + eksclusterconfig.NewVariable, + testDefs..., + ) +}