This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
/
clusterconfig_types.go
349 lines (300 loc) · 10.1 KB
/
clusterconfig_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// Copyright 2023 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package v1alpha1
import (
"maps"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/openapi/patterns"
)
const (
CNIProviderCalico = "Calico"
CNIProviderCilium = "Cilium"
CSIProviderAWSEBS = "aws-ebs"
CPIProviderAWS = "aws"
)
//+kubebuilder:object:root=true
// ClusterConfig is the Schema for the clusterconfigs API.
type ClusterConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
//+optional
Spec ClusterConfigSpec `json:"spec,omitempty"`
}
// ClusterConfigSpec defines the desired state of ClusterConfig.
type ClusterConfigSpec struct {
// +optional
AWS *AWSSpec `json:"aws,omitempty"`
// +optional
Docker *DockerSpec `json:"docker,omitempty"`
GenericClusterConfig `json:",inline"`
//+optional
ControlPlane *NodeConfigSpec `json:"controlPlane,omitempty"`
}
func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
clusterConfigProps := GenericClusterConfig{}.VariableSchema()
switch {
case s.AWS != nil:
maps.Copy(
clusterConfigProps.OpenAPIV3Schema.Properties,
map[string]clusterv1.JSONSchemaProps{
AWSVariableName: AWSSpec{}.VariableSchema().OpenAPIV3Schema,
"controlPlane": NodeConfigSpec{
AWS: &AWSNodeSpec{},
}.VariableSchema().OpenAPIV3Schema,
},
)
case s.Docker != nil:
maps.Copy(
clusterConfigProps.OpenAPIV3Schema.Properties,
map[string]clusterv1.JSONSchemaProps{
"docker": DockerSpec{}.VariableSchema().OpenAPIV3Schema,
"controlPlane": NodeConfigSpec{
Docker: &DockerNodeSpec{},
}.VariableSchema().OpenAPIV3Schema,
},
)
}
return clusterConfigProps
}
// GenericClusterConfig defines the generic cluster configdesired.
type GenericClusterConfig struct {
// +optional
KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"`
// +optional
Etcd *Etcd `json:"etcd,omitempty"`
// +optional
Proxy *HTTPProxy `json:"proxy,omitempty"`
// +optional
ExtraAPIServerCertSANs ExtraAPIServerCertSANs `json:"extraAPIServerCertSANs,omitempty"`
// +optional
ImageRegistries ImageRegistries `json:"imageRegistries,omitempty"`
// +optional
GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"`
// +optional
Addons *Addons `json:"addons,omitempty"`
}
func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Cluster configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"addons": Addons{}.VariableSchema().OpenAPIV3Schema,
"etcd": Etcd{}.VariableSchema().OpenAPIV3Schema,
"extraAPIServerCertSANs": ExtraAPIServerCertSANs{}.VariableSchema().OpenAPIV3Schema,
"proxy": HTTPProxy{}.VariableSchema().OpenAPIV3Schema,
"kubernetesImageRepository": KubernetesImageRepository(
"",
).VariableSchema().
OpenAPIV3Schema,
"imageRegistries": ImageRegistries{}.VariableSchema().OpenAPIV3Schema,
"globalImageRegistryMirror": GlobalImageRegistryMirror{}.VariableSchema().OpenAPIV3Schema,
},
},
}
}
// KubernetesImageRepository required for overriding Kubernetes image repository.
type KubernetesImageRepository string
func (KubernetesImageRepository) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Sets the Kubernetes image repository used for the KubeadmControlPlane.",
Type: "string",
Pattern: patterns.Anchored(patterns.ImageRepository),
},
}
}
func (v KubernetesImageRepository) String() string {
return string(v)
}
type Image struct {
// Repository is used to override the image repository to pull from.
//+optional
Repository string `json:"repository,omitempty"`
// Tag is used to override the default image tag.
//+optional
Tag string `json:"tag,omitempty"`
}
func (Image) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"repository": {
Description: "Image repository to pull from.",
Type: "string",
Pattern: patterns.Anchored(patterns.ImageRepository),
},
"tag": {
Description: "Image tag to use.",
Type: "string",
Pattern: patterns.Anchored(patterns.ImageTag),
},
},
},
}
}
type Etcd struct {
// Image required for overriding etcd image details.
//+optional
Image *Image `json:"image,omitempty"`
}
func (Etcd) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"image": Image{}.VariableSchema().OpenAPIV3Schema,
},
},
}
}
// HTTPProxy required for providing proxy configuration.
type HTTPProxy struct {
// HTTP proxy.
HTTP string `json:"http,omitempty"`
// HTTPS proxy.
HTTPS string `json:"https,omitempty"`
// 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,<POD_NETWORK>,<SERVICE_NETWORK>,kubernetes
// ,kubernetes.default,.svc,.svc.<SERVICE_DOMAIN>
AdditionalNo []string `json:"additionalNo"`
}
func (HTTPProxy) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"http": {
Description: "HTTP proxy value.",
Type: "string",
},
"https": {
Description: "HTTPS proxy value.",
Type: "string",
},
"additionalNo": {
Description: "Additional No Proxy list that will be added to the automatically calculated " +
"values required for cluster internal network. " +
"Default value: localhost,127.0.0.1,<POD_NETWORK>,<SERVICE_NETWORK>,kubernetes," +
"kubernetes.default,.svc,.svc.<SERVICE_DOMAIN>",
Type: "array",
Items: &clusterv1.JSONSchemaProps{
Type: "string",
},
},
},
},
}
}
// ExtraAPIServerCertSANs required for providing API server cert SANs.
type ExtraAPIServerCertSANs []string
func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Extra Subject Alternative Names for the API Server signing cert",
Type: "array",
UniqueItems: true,
Items: &clusterv1.JSONSchemaProps{
Type: "string",
Pattern: patterns.Anchored(patterns.DNS1123Subdomain),
},
},
}
}
type RegistryCredentials struct {
// 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.
// +optional
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
}
func (RegistryCredentials) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"secretRef": {
Description: "A reference to the Secret containing the registry credentials and optional CA certificate. " +
"The Secret should have keys 'username', 'password' and optional 'ca.crt'. " +
"This credentials Secret is not required for some registries, e.g. ECR.",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Description: "The name of the Secret containing the registry credentials. This Secret must exist in " +
"the same namespace as the Cluster.",
Type: "string",
},
},
Required: []string{"name"},
},
},
},
}
}
// GlobalImageRegistryMirror sets default mirror configuration for all the image registries.
type GlobalImageRegistryMirror struct {
// Registry URL.
URL string `json:"url"`
// Credentials and CA certificate for the image registry mirror
// +optional
Credentials *RegistryCredentials `json:"credentials,omitempty"`
}
func (GlobalImageRegistryMirror) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"url": {
Description: "Registry mirror URL.",
Type: "string",
Format: "uri",
Pattern: "^https?://",
},
"credentials": RegistryCredentials{}.VariableSchema().OpenAPIV3Schema,
},
Required: []string{"url"},
},
}
}
type ImageRegistry struct {
// Registry URL.
URL string `json:"url"`
// Credentials and CA certificate for the image registry
// +optional
Credentials *RegistryCredentials `json:"credentials,omitempty"`
}
func (ImageRegistry) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"url": {
Description: "Registry URL.",
Type: "string",
Format: "uri",
Pattern: "^https?://",
},
"credentials": RegistryCredentials{}.VariableSchema().OpenAPIV3Schema,
},
Required: []string{"url"},
},
}
}
type ImageRegistries []ImageRegistry
func (ImageRegistries) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Configuration for image registries.",
Type: "array",
Items: ptr.To(ImageRegistry{}.VariableSchema().OpenAPIV3Schema),
},
}
}
func init() {
SchemeBuilder.Register(&ClusterConfig{})
}