Skip to content

Commit cf97f16

Browse files
committed
refactor: move kubeadm config out of GenericClusterConfigSpec to a new type
This allows for EKS clusters to reuse the actually generic types.
1 parent 6f519eb commit cf97f16

File tree

9 files changed

+268
-149
lines changed

9 files changed

+268
-149
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 46 additions & 20 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,6 +185,44 @@ type NutanixClusterConfigSpec struct {
177185

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

188+
// KubeadmClusterConfig is the Schema for the kubeadmconfigs API.
189+
type KubeadmClusterConfig struct {
190+
metav1.TypeMeta `json:",inline"`
191+
metav1.ObjectMeta `json:"metadata,omitempty"`
192+
193+
// +kubebuilder:validation:Optional
194+
Spec KubeadmClusterConfigSpec `json:"spec,omitempty"`
195+
}
196+
197+
func (s KubeadmClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
198+
return kubeadmClusterConfigVariableSchema
199+
}
200+
201+
// KubeadmConfigSpec defines configuratiion that can be set when using kubeadm to bootstrap the cluster.
202+
type KubeadmClusterConfigSpec struct {
203+
// Sets the Kubernetes image repository used for the KubeadmControlPlane.
204+
// +kubebuilder:validation:Optional
205+
// +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]+)*)*$`
206+
// +kubebuilder:validation:MinLength=1
207+
// +kubebuilder:validation:MaxLength=2048
208+
KubernetesImageRepository string `json:"kubernetesImageRepository,omitempty"`
209+
210+
// +kubebuilder:validation:Optional
211+
Etcd *Etcd `json:"etcd,omitempty"`
212+
213+
// +kubebuilder:validation:Optional
214+
EncryptionAtRest *EncryptionAtRest `json:"encryptionAtRest,omitempty"`
215+
216+
// +kubebuilder:validation:Optional
217+
DNS *DNS `json:"dns,omitempty"`
218+
219+
// KubeProxy defines the configuration for kube-proxy.
220+
// +kubebuilder:validation:Optional
221+
KubeProxy *KubeProxy `json:"kubeProxy,omitempty"`
222+
}
223+
224+
// +kubebuilder:object:root=true
225+
180226
// GenericClusterConfig is the Schema for the genericclusterconfigs API.
181227
type GenericClusterConfig struct {
182228
metav1.TypeMeta `json:",inline"`
@@ -200,16 +246,6 @@ func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //noli
200246

201247
// GenericClusterConfigSpec defines the desired state of GenericClusterConfig.
202248
type GenericClusterConfigSpec struct {
203-
// Sets the Kubernetes image repository used for the KubeadmControlPlane.
204-
// +kubebuilder:validation:Optional
205-
// +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]+)*)*$`
206-
// +kubebuilder:validation:MinLength=1
207-
// +kubebuilder:validation:MaxLength=2048
208-
KubernetesImageRepository string `json:"kubernetesImageRepository,omitempty"`
209-
210-
// +kubebuilder:validation:Optional
211-
Etcd *Etcd `json:"etcd,omitempty"`
212-
213249
// +kubebuilder:validation:Optional
214250
Proxy *HTTPProxy `json:"proxy,omitempty"`
215251

@@ -224,16 +260,6 @@ type GenericClusterConfigSpec struct {
224260
// +kubebuilder:validation:MaxItems=32
225261
Users []User `json:"users,omitempty"`
226262

227-
// +kubebuilder:validation:Optional
228-
EncryptionAtRest *EncryptionAtRest `json:"encryptionAtRest,omitempty"`
229-
230-
// +kubebuilder:validation:Optional
231-
DNS *DNS `json:"dns,omitempty"`
232-
233-
// KubeProxy defines the configuration for kube-proxy.
234-
// +kubebuilder:validation:Optional
235-
KubeProxy *KubeProxy `json:"kubeProxy,omitempty"`
236-
237263
// NTP defines the NTP configuration for the cluster.
238264
// +kubebuilder:validation:Optional
239265
NTP *NTP `json:"ntp,omitempty"`

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

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -52,76 +52,6 @@ spec:
5252
spec:
5353
description: GenericClusterConfigSpec defines the desired state of GenericClusterConfig.
5454
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
12555
globalImageRegistryMirror:
12656
description: GlobalImageRegistryMirror sets default mirror configuration
12757
for all the image registries.
@@ -188,28 +118,6 @@ spec:
188118
type: object
189119
maxItems: 32
190120
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
213121
ntp:
214122
description: NTP defines the NTP configuration for the cluster.
215123
properties:
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Copyright 2024 Nutanix. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
---
4+
apiVersion: apiextensions.k8s.io/v1
5+
kind: CustomResourceDefinition
6+
metadata:
7+
annotations:
8+
controller-gen.kubebuilder.io/version: v0.18.0
9+
name: kubeadmclusterconfigs.caren.nutanix.com
10+
spec:
11+
group: caren.nutanix.com
12+
names:
13+
kind: KubeadmClusterConfig
14+
listKind: KubeadmClusterConfigList
15+
plural: kubeadmclusterconfigs
16+
singular: kubeadmclusterconfig
17+
scope: Namespaced
18+
versions:
19+
- name: v1alpha1
20+
schema:
21+
openAPIV3Schema:
22+
description: KubeadmClusterConfig is the Schema for the kubeadmconfigs API.
23+
properties:
24+
apiVersion:
25+
description: |-
26+
APIVersion defines the versioned schema of this representation of an object.
27+
Servers should convert recognized schemas to the latest internal value, and
28+
may reject unrecognized values.
29+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
30+
type: string
31+
kind:
32+
description: |-
33+
Kind is a string value representing the REST resource this object represents.
34+
Servers may infer this from the endpoint the client submits requests to.
35+
Cannot be updated.
36+
In CamelCase.
37+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
38+
type: string
39+
metadata:
40+
type: object
41+
spec:
42+
description: KubeadmConfigSpec defines configuratiion that can be set
43+
when using kubeadm to bootstrap the cluster.
44+
properties:
45+
dns:
46+
description: DNS defines the DNS configuration for the cluster.
47+
properties:
48+
coreDNS:
49+
description: CoreDNS defines the CoreDNS configuration for the
50+
cluster.
51+
properties:
52+
image:
53+
description: |-
54+
Image required for overriding Kubernetes DNS image details.
55+
If the image version is not specified,
56+
the default version based on the cluster's Kubernetes version will be used.
57+
properties:
58+
repository:
59+
description: Repository is used to override the image
60+
repository to pull from.
61+
maxLength: 2048
62+
minLength: 1
63+
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]+)*)*$
64+
type: string
65+
tag:
66+
description: Tag is used to override the default image
67+
tag.
68+
maxLength: 128
69+
minLength: 1
70+
pattern: ^[\w][\w.-]{0,127}$
71+
type: string
72+
type: object
73+
type: object
74+
type: object
75+
encryptionAtRest:
76+
description: |-
77+
EncryptionAtRest defines the configuration to enable encryption at REST
78+
This configuration is used by API server to encrypt data before storing it in ETCD.
79+
Currently the encryption only enabled for secrets and configmaps.
80+
properties:
81+
providers:
82+
default:
83+
- aescbc: {}
84+
description: Encryption providers
85+
items:
86+
properties:
87+
aescbc:
88+
type: object
89+
secretbox:
90+
type: object
91+
type: object
92+
maxItems: 1
93+
type: array
94+
type: object
95+
etcd:
96+
properties:
97+
image:
98+
description: Image required for overriding etcd image details.
99+
properties:
100+
repository:
101+
description: Repository is used to override the image repository
102+
to pull from.
103+
maxLength: 2048
104+
minLength: 1
105+
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]+)*)*$
106+
type: string
107+
tag:
108+
description: Tag is used to override the default image tag.
109+
maxLength: 128
110+
minLength: 1
111+
pattern: ^[\w][\w.-]{0,127}$
112+
type: string
113+
type: object
114+
type: object
115+
kubeProxy:
116+
description: KubeProxy defines the configuration for kube-proxy.
117+
properties:
118+
mode:
119+
description: |-
120+
Mode specifies the mode for kube-proxy:
121+
- iptables means that kube-proxy is installed in iptables mode.
122+
- nftables means that kube-proxy is installed in nftables mode.
123+
enum:
124+
- iptables
125+
- nftables
126+
type: string
127+
x-kubernetes-validations:
128+
- message: Value cannot be changed after cluster creation
129+
rule: self == oldSelf
130+
type: object
131+
kubernetesImageRepository:
132+
description: Sets the Kubernetes image repository used for the KubeadmControlPlane.
133+
maxLength: 2048
134+
minLength: 1
135+
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]+)*)*$
136+
type: string
137+
type: object
138+
type: object
139+
served: true
140+
storage: true

0 commit comments

Comments
 (0)