Skip to content

Commit 30ca4ad

Browse files
committed
fix: nest object under imageRegistries.credentials
1 parent 18a4f49 commit 30ca4ad

23 files changed

+225
-121
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ type GenericClusterConfig struct {
2929
// +optional
3030
ExtraAPIServerCertSANs ExtraAPIServerCertSANs `json:"extraAPIServerCertSANs,omitempty"`
3131

32-
// TODO: Add support for multiple registries.
3332
// +optional
34-
ImageRegistryCredentials ImageRegistryCredentials `json:"imageRegistryCredentials,omitempty"`
33+
ImageRegistries ImageRegistries `json:"imageRegistries,omitempty"`
3534

3635
// +optional
3736
Addons *Addons `json:"addons,omitempty"`
@@ -51,7 +50,7 @@ func (GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
5150
"",
5251
).VariableSchema().
5352
OpenAPIV3Schema,
54-
"imageRegistryCredentials": ImageRegistryCredentials{}.VariableSchema().OpenAPIV3Schema,
53+
"imageRegistries": ImageRegistries{}.VariableSchema().OpenAPIV3Schema,
5554
},
5655
},
5756
}
@@ -181,49 +180,85 @@ func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
181180
}
182181
}
183182

184-
// ImageRegistryCredentials required for providing credentials for an image registry URL.
185-
type ImageRegistryCredentials struct {
186-
// Registry URL.
187-
URL string `json:"url"`
188-
189-
// The Secret containing the registry credentials.
190-
// The Secret should have keys 'username' and 'password'.
191-
// This credentials Secret is not required for some registries, e.g. ECR.
183+
type ImageRegistries struct {
192184
// +optional
193-
Secret *corev1.ObjectReference `json:"secretRef,omitempty"`
185+
ImageRegistryCredentials ImageRegistryCredentials `json:"credentials,omitempty"`
194186
}
195187

196-
func (ImageRegistryCredentials) VariableSchema() clusterv1.VariableSchema {
188+
func (ImageRegistries) VariableSchema() clusterv1.VariableSchema {
197189
return clusterv1.VariableSchema{
198190
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
199-
Description: "Extra Subject Alternative Names for the API Server signing cert",
191+
Description: "Configuration for image registries.",
200192
Type: "object",
201193
Properties: map[string]clusterv1.JSONSchemaProps{
202-
"url": {
203-
Description: "Registry URL.",
204-
Type: "string",
205-
},
206-
"secretRef": {
207-
Description: "The Secret containing the registry credentials. " +
208-
"The Secret should have keys 'username' and 'password'. " +
209-
"This credentials Secret is not required for some registries, e.g. ECR.",
210-
Type: "object",
211-
Properties: map[string]clusterv1.JSONSchemaProps{
212-
"name": {
213-
Description: "The name of the Secret containing the registry credentials.",
214-
Type: "string",
215-
},
216-
"namespace": {
217-
Description: "The namespace of the Secret containing the registry credentials. " +
218-
"Defaults to the namespace of the KubeadmControlPlaneTemplate and KubeadmConfigTemplate" +
219-
" that reference this variable.",
220-
Type: "string",
221-
},
194+
"credentials": imageRegistryCredentialsSchema,
195+
},
196+
},
197+
}
198+
}
199+
200+
var (
201+
imageRegistryCredentialsSchema = clusterv1.JSONSchemaProps{
202+
Type: "array",
203+
UniqueItems: true,
204+
Items: &imageRegistryCredentialsResourceSchema,
205+
}
206+
207+
imageRegistryCredentialsResourceSchema = clusterv1.JSONSchemaProps{
208+
Description: "Image registry credentials to set up on all Nodes in the cluster. " +
209+
"Enabling this will the Kubelets with https://kubernetes.io/docs/tasks/administer-cluster/kubelet-credential-provider/.",
210+
Type: "object",
211+
Properties: map[string]clusterv1.JSONSchemaProps{
212+
"url": {
213+
Description: "Registry URL.",
214+
Type: "string",
215+
},
216+
"secretRef": {
217+
Description: "The Secret containing the registry credentials. " +
218+
"The Secret should have keys 'username' and 'password'. " +
219+
"This credentials Secret is not required for some registries, e.g. ECR.",
220+
Type: "object",
221+
Properties: map[string]clusterv1.JSONSchemaProps{
222+
"name": {
223+
Description: "The name of the Secret containing the registry credentials.",
224+
Type: "string",
225+
},
226+
"namespace": {
227+
Description: "The namespace of the Secret containing the registry credentials. " +
228+
"Defaults to the namespace of the KubeadmControlPlaneTemplate and KubeadmConfigTemplate" +
229+
" that reference this variable.",
230+
Type: "string",
222231
},
223232
},
224233
},
225-
Required: []string{"url"},
226234
},
235+
Required: []string{"url"},
236+
}
237+
)
238+
239+
type ImageRegistryCredentials []ImageRegistryCredentialsResource
240+
241+
func (ImageRegistryCredentials) VariableSchema() clusterv1.VariableSchema {
242+
return clusterv1.VariableSchema{
243+
OpenAPIV3Schema: imageRegistryCredentialsSchema,
244+
}
245+
}
246+
247+
// ImageRegistryCredentialsResource required for providing credentials for an image registry URL.
248+
type ImageRegistryCredentialsResource struct {
249+
// Registry URL.
250+
URL string `json:"url"`
251+
252+
// The Secret containing the registry credentials.
253+
// The Secret should have keys 'username' and 'password'.
254+
// This credentials Secret is not required for some registries, e.g. ECR.
255+
// +optional
256+
Secret *corev1.ObjectReference `json:"secretRef,omitempty"`
257+
}
258+
259+
func (ImageRegistryCredentialsResource) VariableSchema() clusterv1.VariableSchema {
260+
return clusterv1.VariableSchema{
261+
OpenAPIV3Schema: imageRegistryCredentialsResourceSchema,
227262
}
228263
}
229264

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/etcd"
3838
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/extraapiservercertsans"
3939
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/httpproxy"
40-
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/imageregistrycredentials"
40+
imageregistrycredentials "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/imageregistries/credentials"
4141
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/kubernetesimagerepository"
4242
)
4343

docs/content/customization/_index.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ spec:
3939
additionalNo:
4040
- no-proxy-1.example.com
4141
- no-proxy-2.example.com
42-
imageRegistryCredentials:
43-
url: https://my-registry.io
44-
secretRef:
45-
name: my-registry-credentials
42+
imageRegistries:
43+
credentials:
44+
- url: https://my-registry.io
45+
secretRef:
46+
name: my-registry-credentials
4647
cni:
4748
provider: calico
4849
```

docs/content/customization/generic/image-registry-credentials.md renamed to docs/content/customization/generic/image-registries.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
+++
2-
title = "Image registry credentials"
2+
title = "Image registries"
33
+++
44

5-
In some network environments it is necessary to use HTTP proxy to successfuly execute HTTP requests.
6-
To configure Kubernetes components (`containerd`, `kubelet`) to use HTTP proxy use the `httpproxypatch`
7-
external patch that will generate appropriate configuration for control plane and worker nodes.
5+
Add image registry configuration to all Nodes in the cluster.
86

9-
Add image registry credentials to all Nodes in the cluster.
10-
When this handle is enabled, the handler will add `files` and `preKubeadmnCommands` with configurations for
7+
When the `credentials` variable is set, `files` and `preKubeadmnCommands` with configurations for
118
[Kubelet image credential provider](https://kubernetes.io/docs/tasks/administer-cluster/kubelet-credential-provider/)
12-
and [dynamic credential provider](https://github.com/mesosphere/dynamic-credential-provider).
9+
and [dynamic credential provider](https://github.com/mesosphere/dynamic-credential-provider) will be added.
1310

1411
This customization will be available when the
1512
[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`.
@@ -20,10 +17,10 @@ If your registry requires static credentials, create a Kubernetes Secret with ke
2017

2118
```shell
2219
kubectl create secret generic my-registry-credentials \
23-
--from-literal username=${REGISTRY_USERNAME} password=${REGISTRY_PASSWORD}
20+
--from-literal username=${REGISTRY_USERNAME} --from-literal password=${REGISTRY_PASSWORD}
2421
```
2522

26-
On the cluster resource then specify desired image registry credentials:
23+
To add image registry credentials, specify the following configuration:
2724

2825
```yaml
2926
apiVersion: cluster.x-k8s.io/v1beta1
@@ -35,10 +32,11 @@ spec:
3532
variables:
3633
- name: clusterConfig
3734
value:
38-
imageRegistryCredentials:
39-
url: https://my-registry.io
40-
secretRef:
41-
name: my-registry-credentials
35+
imageRegistries:
36+
credentials:
37+
- url: https://my-registry.io
38+
secretRef:
39+
name: my-registry-credentials
4240
```
4341
4442
Applying this configuration will result in new files and preKubeadmCommands
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package imageregistries
5+
6+
const (
7+
VariableName = "imageRegistries"
8+
)

pkg/handlers/generic/mutation/imageregistrycredentials/credential_provider_config_files.go renamed to pkg/handlers/generic/mutation/imageregistries/credentials/credential_provider_config_files.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023 D2iQ, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package imageregistrycredentials
4+
package credentials
55

66
import (
77
"bytes"
@@ -15,7 +15,7 @@ import (
1515
credentialproviderv1beta1 "k8s.io/kubelet/pkg/apis/credentialprovider/v1beta1"
1616
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1717

18-
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/imageregistrycredentials/credentialprovider"
18+
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/mutation/imageregistries/credentials/credentialprovider"
1919
)
2020

2121
const (
@@ -51,18 +51,18 @@ var (
5151
installKubeletCredentialProvidersScript []byte
5252
)
5353

54-
type imageRegistryCredentials struct {
54+
type providerInput struct {
5555
URL string
5656
Username string
5757
Password string
5858
}
5959

60-
func (c imageRegistryCredentials) isCredentialsEmpty() bool {
60+
func (c providerInput) isCredentialsEmpty() bool {
6161
return c.Username == "" &&
6262
c.Password == ""
6363
}
6464

65-
func templateFilesForImageCredentialProviderConfigs(credentials imageRegistryCredentials) ([]cabpkv1.File, error) {
65+
func templateFilesForImageCredentialProviderConfigs(credentials providerInput) ([]cabpkv1.File, error) {
6666
var files []cabpkv1.File
6767

6868
kubeletCredentialProviderConfigFile, err := templateKubeletCredentialProviderConfig(credentials)
@@ -84,7 +84,7 @@ func templateFilesForImageCredentialProviderConfigs(credentials imageRegistryCre
8484
return files, nil
8585
}
8686

87-
func templateKubeletCredentialProviderConfig(credentials imageRegistryCredentials) (*cabpkv1.File, error) {
87+
func templateKubeletCredentialProviderConfig(credentials providerInput) (*cabpkv1.File, error) {
8888
return templateCredentialProviderConfig(
8989
credentials,
9090
imageCredentialProviderConfigPatch,
@@ -94,7 +94,7 @@ func templateKubeletCredentialProviderConfig(credentials imageRegistryCredential
9494
}
9595

9696
func templateDynamicCredentialProviderConfig(
97-
credentials imageRegistryCredentials,
97+
credentials providerInput,
9898
) (*cabpkv1.File, error) {
9999
return templateCredentialProviderConfig(
100100
credentials,
@@ -105,15 +105,14 @@ func templateDynamicCredentialProviderConfig(
105105
}
106106

107107
func templateCredentialProviderConfig(
108-
credentials imageRegistryCredentials,
108+
credentials providerInput,
109109
inputTemplate []byte,
110110
filePath string,
111111
providerFunc func(
112112
hasStaticCredentials bool,
113113
host string,
114114
) (providerBinary string, providerArgs []string, providerAPIVersion string, err error),
115115
) (*cabpkv1.File, error) {
116-
117116
mirrorURL, err := url.ParseRequestURI(credentials.URL)
118117
if err != nil {
119118
return nil, fmt.Errorf("failed parsing registry mirror: %w", err)

0 commit comments

Comments
 (0)