Skip to content

Commit f12d3d7

Browse files
feat: containerd configuration for mirror registry (#292)
Co-authored-by: Jimmi Dyson <[email protected]>
1 parent 362595f commit f12d3d7

File tree

19 files changed

+1192
-264
lines changed

19 files changed

+1192
-264
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
corev1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/utils/ptr"
1112
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1213

1314
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
@@ -89,6 +90,9 @@ type GenericClusterConfig struct {
8990
// +optional
9091
ImageRegistries ImageRegistries `json:"imageRegistries,omitempty"`
9192

93+
// +optional
94+
GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"`
95+
9296
// +optional
9397
Addons *Addons `json:"addons,omitempty"`
9498
}
@@ -107,7 +111,8 @@ func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //noli
107111
"",
108112
).VariableSchema().
109113
OpenAPIV3Schema,
110-
"imageRegistries": ImageRegistries{}.VariableSchema().OpenAPIV3Schema,
114+
"imageRegistries": ImageRegistries{}.VariableSchema().OpenAPIV3Schema,
115+
"globalImageRegistryMirror": GlobalImageRegistryMirror{}.VariableSchema().OpenAPIV3Schema,
111116
},
112117
},
113118
}
@@ -237,84 +242,111 @@ func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
237242
}
238243
}
239244

240-
type ImageRegistries struct {
245+
type RegistryCredentials struct {
246+
// The Secret containing the registry credentials and optional CA certificate
247+
// using the keys `username`, `password` and `ca.crt`.
248+
// This credentials Secret is not required for some registries, e.g. ECR.
241249
// +optional
242-
ImageRegistryCredentials ImageRegistryCredentials `json:"credentials,omitempty"`
250+
SecretRef *corev1.ObjectReference `json:"secretRef,omitempty"`
243251
}
244252

245-
func (ImageRegistries) VariableSchema() clusterv1.VariableSchema {
253+
func (RegistryCredentials) VariableSchema() clusterv1.VariableSchema {
246254
return clusterv1.VariableSchema{
247255
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
248-
Description: "Configuration for image registries.",
249-
Type: "object",
256+
Type: "object",
250257
Properties: map[string]clusterv1.JSONSchemaProps{
251-
"credentials": ImageRegistryCredentials{}.VariableSchema().OpenAPIV3Schema,
258+
"secretRef": {
259+
Description: "A reference to the Secret containing the registry credentials. " +
260+
"The Secret should have keys 'username', 'password' and optional 'ca.crt'. " +
261+
"This credentials Secret is not required for some registries, e.g. ECR.",
262+
Type: "object",
263+
Properties: map[string]clusterv1.JSONSchemaProps{
264+
"name": {
265+
Description: "The name of the Secret containing the registry credentials.",
266+
Type: "string",
267+
},
268+
"namespace": {
269+
Description: "The namespace of the Secret containing the registry credentials. " +
270+
"Defaults to the namespace of the Cluster. " +
271+
"that reference this variable.",
272+
Type: "string",
273+
},
274+
},
275+
Required: []string{"name"},
276+
},
252277
},
253278
},
254279
}
255280
}
256281

257-
type ImageRegistryCredentials []ImageRegistryCredentialsResource
282+
// GlobalImageRegistryMirror sets default mirror configuration for all the image registries.
283+
type GlobalImageRegistryMirror struct {
284+
// Registry URL.
285+
URL string `json:"url"`
258286

259-
func (ImageRegistryCredentials) VariableSchema() clusterv1.VariableSchema {
260-
resourceSchema := ImageRegistryCredentialsResource{}.VariableSchema().OpenAPIV3Schema
287+
// Credentials and CA certificate for the image registry mirror
288+
// +optional
289+
Credentials *RegistryCredentials `json:"credentials,omitempty"`
290+
}
261291

292+
func (GlobalImageRegistryMirror) VariableSchema() clusterv1.VariableSchema {
262293
return clusterv1.VariableSchema{
263294
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
264-
Description: "Image registry credentials to set up on all Nodes in the cluster. " +
265-
"Enabling this will configure the Kubelets with " +
266-
"https://kubernetes.io/docs/tasks/administer-cluster/kubelet-credential-provider/.",
267-
Type: "array",
268-
Items: &resourceSchema,
295+
Type: "object",
296+
Properties: map[string]clusterv1.JSONSchemaProps{
297+
"url": {
298+
Description: "Registry mirror URL.",
299+
Type: "string",
300+
Format: "uri",
301+
Pattern: "^https?://",
302+
},
303+
"credentials": RegistryCredentials{}.VariableSchema().OpenAPIV3Schema,
304+
},
305+
Required: []string{"url"},
269306
},
270307
}
271308
}
272309

273-
// ImageRegistryCredentialsResource required for providing credentials for an image registry URL.
274-
type ImageRegistryCredentialsResource struct {
310+
type ImageRegistry struct {
275311
// Registry URL.
276312
URL string `json:"url"`
277313

278-
// The Secret containing the registry credentials.
279-
// The Secret should have keys 'username' and 'password'.
280-
// This credentials Secret is not required for some registries, e.g. ECR.
314+
// Credentials and CA certificate for the image registry
281315
// +optional
282-
Secret *corev1.ObjectReference `json:"secretRef,omitempty"`
316+
Credentials *RegistryCredentials `json:"credentials,omitempty"`
283317
}
284318

285-
func (ImageRegistryCredentialsResource) VariableSchema() clusterv1.VariableSchema {
319+
func (ImageRegistry) VariableSchema() clusterv1.VariableSchema {
286320
return clusterv1.VariableSchema{
287321
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
288322
Type: "object",
289323
Properties: map[string]clusterv1.JSONSchemaProps{
290324
"url": {
291325
Description: "Registry URL.",
292326
Type: "string",
327+
Format: "uri",
328+
Pattern: "^https?://",
293329
},
294-
"secretRef": {
295-
Description: "The Secret containing the registry credentials. " +
296-
"The Secret should have keys 'username' and 'password'. " +
297-
"This credentials Secret is not required for some registries, e.g. ECR.",
298-
Type: "object",
299-
Properties: map[string]clusterv1.JSONSchemaProps{
300-
"name": {
301-
Description: "The name of the Secret containing the registry credentials.",
302-
Type: "string",
303-
},
304-
"namespace": {
305-
Description: "The namespace of the Secret containing the registry credentials. " +
306-
"Defaults to the namespace of the KubeadmControlPlaneTemplate and KubeadmConfigTemplate" +
307-
" that reference this variable.",
308-
Type: "string",
309-
},
310-
},
311-
},
330+
"credentials": RegistryCredentials{}.VariableSchema().OpenAPIV3Schema,
312331
},
313332
Required: []string{"url"},
314333
},
315334
}
316335
}
317336

337+
type ImageRegistries []ImageRegistry
338+
339+
func (ImageRegistries) VariableSchema() clusterv1.VariableSchema {
340+
return clusterv1.VariableSchema{
341+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
342+
Description: "Configuration for image registries.",
343+
Type: "array",
344+
Items: ptr.To(ImageRegistry{}.VariableSchema().OpenAPIV3Schema),
345+
MaxItems: ptr.To[int64](1),
346+
},
347+
}
348+
}
349+
318350
func init() {
319351
SchemeBuilder.Register(&ClusterConfig{})
320352
}

api/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)