Skip to content

Commit 4f7e62e

Browse files
dkoshkinjimmidyson
andauthored
feat: add etcd registry and tag patch and vars (#153)
Co-authored-by: Jimmi Dyson <[email protected]>
1 parent c16c492 commit 4f7e62e

18 files changed

+581
-60
lines changed

.gitlint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ regex=https?://
2020
regex=(.*)dependabot(.*) #
2121
ignore=T1,body-min-length
2222

23-
2423
[contrib-title-conventional-commits]
2524
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
2625
types = fix,feat,docs,style,refactor,perf,test,revert,ci,build

api/v1alpha1/clusterconfig_types.go

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ type ClusterConfig struct {
2727

2828
// ClusterConfigSpec defines the desired state of ClusterConfig.
2929
type ClusterConfigSpec struct {
30-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
31-
// Important: Run "make" to regenerate code after modifying this file
30+
// +optional
31+
KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"`
3232

3333
// +optional
34-
KubernetesImageRegistry *KubernetesImageRegistry `json:"kubernetesImageRegistry,omitempty"`
34+
Etcd *Etcd `json:"etcd,omitempty"`
3535

3636
// +optional
3737
Proxy *HTTPProxy `json:"proxy,omitempty"`
@@ -49,34 +49,83 @@ func (ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema {
4949
Description: "Cluster configuration",
5050
Type: "object",
5151
Properties: map[string]clusterv1.JSONSchemaProps{
52-
"kubernetesImageRegistry": KubernetesImageRegistry(
52+
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
53+
"etcd": Etcd{}.VariableSchema().OpenAPIV3Schema,
54+
"extraAPIServerCertSANs": ExtraAPIServerCertSANs{}.VariableSchema().OpenAPIV3Schema,
55+
"proxy": HTTPProxy{}.VariableSchema().OpenAPIV3Schema,
56+
"kubernetesImageRepository": KubernetesImageRepository(
5357
"",
5458
).VariableSchema().
5559
OpenAPIV3Schema,
56-
"proxy": HTTPProxy{}.VariableSchema().OpenAPIV3Schema,
57-
"extraAPIServerCertSANs": ExtraAPIServerCertSANs{}.VariableSchema().OpenAPIV3Schema,
58-
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
5960
},
6061
},
6162
}
6263
}
6364

64-
// KubernetesImageRegistry required for overriding Kubernetes image registry.
65-
type KubernetesImageRegistry string
65+
// KubernetesImageRepository required for overriding Kubernetes image repository.
66+
type KubernetesImageRepository string
6667

67-
func (KubernetesImageRegistry) VariableSchema() clusterv1.VariableSchema {
68+
func (KubernetesImageRepository) VariableSchema() clusterv1.VariableSchema {
6869
return clusterv1.VariableSchema{
6970
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
70-
Description: "Sets the Kubernetes image registry used for the KubeadmControlPlane.",
71+
Description: "Sets the Kubernetes image repository used for the KubeadmControlPlane.",
7172
Type: "string",
73+
Pattern: patterns.Anchored(patterns.ImageRepository),
7274
},
7375
}
7476
}
7577

76-
func (v KubernetesImageRegistry) String() string {
78+
func (v KubernetesImageRepository) String() string {
7779
return string(v)
7880
}
7981

82+
type Image struct {
83+
// Repository is used to override the image repository to pull from.
84+
//+optional
85+
Repository string `json:"repository,omitempty"`
86+
87+
// Tag is used to override the default image tag.
88+
//+optional
89+
Tag string `json:"tag,omitempty"`
90+
}
91+
92+
func (Image) VariableSchema() clusterv1.VariableSchema {
93+
return clusterv1.VariableSchema{
94+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
95+
Type: "object",
96+
Properties: map[string]clusterv1.JSONSchemaProps{
97+
"repository": {
98+
Description: "Image repository to pull from.",
99+
Type: "string",
100+
Pattern: patterns.Anchored(patterns.ImageRepository),
101+
},
102+
"tag": {
103+
Description: "Image tag to use.",
104+
Type: "string",
105+
Pattern: patterns.Anchored(patterns.Tag),
106+
},
107+
},
108+
},
109+
}
110+
}
111+
112+
type Etcd struct {
113+
// Image required for overriding etcd image details.
114+
//+optional
115+
Image *Image `json:"image,omitempty"`
116+
}
117+
118+
func (Etcd) VariableSchema() clusterv1.VariableSchema {
119+
return clusterv1.VariableSchema{
120+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
121+
Type: "object",
122+
Properties: map[string]clusterv1.JSONSchemaProps{
123+
"image": Image{}.VariableSchema().OpenAPIV3Schema,
124+
},
125+
},
126+
}
127+
}
128+
80129
// HTTPProxy required for providing proxy configuration.
81130
type HTTPProxy struct {
82131
// HTTP proxy.

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import (
2929
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/auditpolicy"
3030
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/clusterconfig"
3131
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/cni/calico"
32+
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/etcd"
3233
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/extraapiservercertsans"
3334
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/httpproxy"
34-
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/kubernetesimageregistry"
35+
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/kubernetesimagerepository"
3536
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/servicelbgc"
3637
)
3738

@@ -126,8 +127,11 @@ func main() {
126127

127128
auditpolicy.NewPatch(),
128129

129-
kubernetesimageregistry.NewVariable(),
130-
kubernetesimageregistry.NewPatch(kubernetesimageregistry.VariableName),
130+
kubernetesimagerepository.NewVariable(),
131+
kubernetesimagerepository.NewPatch(kubernetesimagerepository.VariableName),
132+
133+
etcd.NewVariable(),
134+
etcd.NewPatch(etcd.VariableName),
131135

132136
clusterconfig.NewVariable(),
133137
mutation.NewMetaGeneratePatchesHandler(
@@ -138,10 +142,11 @@ func main() {
138142
extraapiservercertsans.VariableName,
139143
),
140144
auditpolicy.NewPatch(),
141-
kubernetesimageregistry.NewPatch(
145+
kubernetesimagerepository.NewPatch(
142146
clusterconfig.VariableName,
143-
kubernetesimageregistry.VariableName,
147+
kubernetesimagerepository.VariableName,
144148
),
149+
etcd.NewPatch(clusterconfig.VariableName, etcd.VariableName),
145150
),
146151
)
147152
if err := mgr.Add(runtimeWebhookServer); err != nil {

common/pkg/openapi/patterns/distribution.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ const (
77
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L53
88
NameSeparator = `(?:[._]|__|[-]+)`
99

10-
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L123C18-L123C65
10+
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L123
1111
PathComponent = Alphanumeric + `(` + NameSeparator + Alphanumeric + `)*`
1212

13-
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L130
14-
ImageRegistry = `(` + DNS1123Subdomain + `|` + IPv6 + `)` + OptionalPort + `(/` + PathComponent + `)*`
13+
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L125-L130
14+
ImageRepository = `(` + HostAndOptionalPort + `/)?` + PathComponent + `(/` + PathComponent + `)*`
15+
16+
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L68
17+
Tag = `[\w][\w.-]{0,127}`
18+
19+
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L81
20+
Digest = `[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][0-9A-Fa-f]{32,}`
1521
)

common/pkg/openapi/patterns/net.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ const (
99

1010
Port = `:[0-9]+`
1111

12+
// See https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L65
1213
OptionalPort = `(` + Port + `)?`
14+
15+
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L106
16+
Host = `(?:` + DNS1123Subdomain + `|` + IPv6 + `)`
17+
18+
// See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L110
19+
HostAndOptionalPort = Host + OptionalPort
1320
)

docs/content/cluster-config.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ spec:
3535
variables:
3636
- name: clusterConfig
3737
value:
38-
kubernetesImageRegistry: "my-registry.io/my-org/my-repo"
38+
kubernetesImageRepository: "my-registry.io/my-org/my-repo"
39+
etcd:
40+
image:
41+
repository: my-registry.io/my-org/my-repo
42+
tag: "v3.5.99_custom.0"
3943
extraAPIServerCertSANs:
4044
- a.b.c.example.com
4145
- d.e.f.example.com

docs/content/etcd.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "etcd"
3+
---
4+
5+
Override the container image registry and tag for [etcd](https://github.com/etcd-io/etcd).
6+
7+
To enable this handler set the `etcdpatch` and `etcdvars` external patches on `ClusterClass`.
8+
9+
```yaml
10+
apiVersion: cluster.x-k8s.io/v1beta1
11+
kind: ClusterClass
12+
metadata:
13+
name: <NAME>
14+
spec:
15+
patches:
16+
- name: image-registry
17+
external:
18+
generateExtension: "etcdpatch.capi-runtime-extensions"
19+
discoverVariablesExtension: "etcdvars.capi-runtime-extensions"
20+
```
21+
22+
On the cluster resource then specify desired etcd image registry and/or image tag values:
23+
24+
```yaml
25+
apiVersion: cluster.x-k8s.io/v1beta1
26+
kind: Cluster
27+
metadata:
28+
name: <NAME>
29+
spec:
30+
topology:
31+
variables:
32+
- name: etcd
33+
values:
34+
image:
35+
repository: my-registry.io/my-org/my-repo
36+
tag: "v3.5.99_custom.0"
37+
```
38+
39+
Applying this configuration will result in the following value being set:
40+
41+
- KubeadmControlPlaneTemplate:
42+
43+
- ```yaml
44+
spec:
45+
kubeadmConfigSpec:
46+
clusterConfiguration:
47+
etcd:
48+
local:
49+
imageRepository: "my-registry.io/my-org/my-repo"
50+
imageTag: "v3.5.99_custom.0"
51+
```

docs/content/kubernetes-image-registry.md renamed to docs/content/kubernetes-image-repository.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: "Kubernete Image Registry"
2+
title: "Kubernete Image Repository"
33
---
44

55
Override the container image registry used when pulling Kubernetes images.
66

7-
To enable this handler set the `imageregistrypatch` and `imageregistryvars` external patches on `ClusterClass`.
7+
To enable this handler set the `imagerepositorypatch` and `imagerepositoryvars` external patches on `ClusterClass`.
88

99
```yaml
1010
apiVersion: cluster.x-k8s.io/v1beta1
@@ -13,10 +13,10 @@ metadata:
1313
name: <NAME>
1414
spec:
1515
patches:
16-
- name: image-registry
16+
- name: image-repository
1717
external:
18-
generateExtension: "imageregistrypatch.capi-runtime-extensions"
19-
discoverVariablesExtension: "imageregistryvars.capi-runtime-extensions"
18+
generateExtension: "imagerepositorypatch.capi-runtime-extensions"
19+
discoverVariablesExtension: "imagerepositoryvars.capi-runtime-extensions"
2020
```
2121
2222
On the cluster resource then specify desired Kubernetes image registry value:
@@ -29,7 +29,7 @@ metadata:
2929
spec:
3030
topology:
3131
variables:
32-
- name: kubernetesImageRegistry
32+
- name: kubernetesImageRepository
3333
value: "my-registry.io/my-org/my-repo"
3434
```
3535

pkg/handlers/cni/constants.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cni
5+
6+
import "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers"
7+
8+
const (
9+
CNIProviderLabelKey = handlers.MetadataDomain + "/cni"
10+
)

0 commit comments

Comments
 (0)