Skip to content

Commit 70d1b43

Browse files
committed
Revert "feat: add new CoreDNSUpdateStrategy API"
This reverts commit 5dc9fb6.
1 parent 413e47f commit 70d1b43

File tree

10 files changed

+26
-180
lines changed

10 files changed

+26
-180
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import (
1212
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
1313
)
1414

15-
const (
16-
CoreDNSUpdateStrategyAutomatic CoreDNSUpdateStrategy = "Automatic"
17-
CoreDNSUpdateStrategyManual CoreDNSUpdateStrategy = "Manual"
18-
)
19-
2015
var (
2116
DefaultDockerCertSANs = []string{
2217
"localhost",
@@ -325,20 +320,12 @@ type DNS struct {
325320
CoreDNS *CoreDNS `json:"coreDNS,omitempty"`
326321
}
327322

328-
// +kubebuilder:validation:Optional
329-
// +kubebuilder:validation:Enum=Manual;Automatic
330-
type CoreDNSUpdateStrategy string
331-
332323
type CoreDNS struct {
333324
// Image required for overriding Kubernetes DNS image details.
325+
// If the image version is not specified,
326+
// the default version based on the cluster's Kubernetes version will be used.
334327
// +kubebuilder:validation:Optional
335328
Image *Image `json:"image,omitempty"`
336-
337-
// UpdateStrategy defines the strategy for how the CoreDNS version will be updated.
338-
// If not specified, the default value is Automatic,
339-
// which sets the CoreDNS version based on the cluster's Kubernetes version.
340-
// +kubebuilder:default=Automatic
341-
UpdateStrategy *CoreDNSUpdateStrategy `json:"updateStrategy,omitempty"`
342329
}
343330

344331
//nolint:gochecknoinits // Idiomatic to use init functions to register APIs with scheme.

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ spec:
379379
description: CoreDNS defines the CoreDNS configuration for the cluster.
380380
properties:
381381
image:
382-
description: Image required for overriding Kubernetes DNS image details.
382+
description: |-
383+
Image required for overriding Kubernetes DNS image details.
384+
If the image version is not specified,
385+
the default version based on the cluster's Kubernetes version will be used.
383386
properties:
384387
repository:
385388
description: Repository is used to override the image repository to pull from.
@@ -390,16 +393,6 @@ spec:
390393
pattern: ^[\w][\w.-]{0,127}$
391394
type: string
392395
type: object
393-
updateStrategy:
394-
default: Automatic
395-
description: |-
396-
UpdateStrategy defines the strategy for how the CoreDNS version will be updated.
397-
If not specified, the default value is Automatic,
398-
which sets the CoreDNS version based on the cluster's Kubernetes version.
399-
enum:
400-
- Manual
401-
- Automatic
402-
type: string
403396
type: object
404397
type: object
405398
encryptionAtRest:

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ spec:
296296
description: CoreDNS defines the CoreDNS configuration for the cluster.
297297
properties:
298298
image:
299-
description: Image required for overriding Kubernetes DNS image details.
299+
description: |-
300+
Image required for overriding Kubernetes DNS image details.
301+
If the image version is not specified,
302+
the default version based on the cluster's Kubernetes version will be used.
300303
properties:
301304
repository:
302305
description: Repository is used to override the image repository to pull from.
@@ -307,16 +310,6 @@ spec:
307310
pattern: ^[\w][\w.-]{0,127}$
308311
type: string
309312
type: object
310-
updateStrategy:
311-
default: Automatic
312-
description: |-
313-
UpdateStrategy defines the strategy for how the CoreDNS version will be updated.
314-
If not specified, the default value is Automatic,
315-
which sets the CoreDNS version based on the cluster's Kubernetes version.
316-
enum:
317-
- Manual
318-
- Automatic
319-
type: string
320313
type: object
321314
type: object
322315
docker:

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ spec:
5858
cluster.
5959
properties:
6060
image:
61-
description: Image required for overriding Kubernetes DNS
62-
image details.
61+
description: |-
62+
Image required for overriding Kubernetes DNS image details.
63+
If the image version is not specified,
64+
the default version based on the cluster's Kubernetes version will be used.
6365
properties:
6466
repository:
6567
description: Repository is used to override the image
@@ -72,16 +74,6 @@ spec:
7274
pattern: ^[\w][\w.-]{0,127}$
7375
type: string
7476
type: object
75-
updateStrategy:
76-
default: Automatic
77-
description: |-
78-
UpdateStrategy defines the strategy for how the CoreDNS version will be updated.
79-
If not specified, the default value is Automatic,
80-
which sets the CoreDNS version based on the cluster's Kubernetes version.
81-
enum:
82-
- Manual
83-
- Automatic
84-
type: string
8577
type: object
8678
type: object
8779
encryptionAtRest:

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,10 @@ spec:
449449
description: CoreDNS defines the CoreDNS configuration for the cluster.
450450
properties:
451451
image:
452-
description: Image required for overriding Kubernetes DNS image details.
452+
description: |-
453+
Image required for overriding Kubernetes DNS image details.
454+
If the image version is not specified,
455+
the default version based on the cluster's Kubernetes version will be used.
453456
properties:
454457
repository:
455458
description: Repository is used to override the image repository to pull from.
@@ -460,16 +463,6 @@ spec:
460463
pattern: ^[\w][\w.-]{0,127}$
461464
type: string
462465
type: object
463-
updateStrategy:
464-
default: Automatic
465-
description: |-
466-
UpdateStrategy defines the strategy for how the CoreDNS version will be updated.
467-
If not specified, the default value is Automatic,
468-
which sets the CoreDNS version based on the cluster's Kubernetes version.
469-
enum:
470-
- Manual
471-
- Automatic
472-
type: string
473466
type: object
474467
type: object
475468
encryptionAtRest:

api/v1alpha1/zz_generated.deepcopy.go

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

docs/content/customization/generic/dns.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ spec:
3434
image:
3535
repository: my-registry.io/my-org/my-repo
3636
tag: "v1.11.3_custom.0"
37-
updateStrategy: Manual
3837
```
3938
4039
Applying this configuration will result in the following value being set:
@@ -49,49 +48,3 @@ Applying this configuration will result in the following value being set:
4948
imageRepository: "my-registry.io/my-org/my-repo"
5049
imageTag: "v1.11.3_custom.0"
5150
```
52-
53-
The CoreDNS version can also be updated automatically. To do this, set the `updateStrategy` to `Automatic`:
54-
55-
```yaml
56-
apiVersion: cluster.x-k8s.io/v1beta1
57-
kind: Cluster
58-
metadata:
59-
name: <NAME>
60-
spec:
61-
topology:
62-
variables:
63-
- name: clusterConfig
64-
value:
65-
dns:
66-
coreDNS:
67-
updateStrategy: Automatic
68-
```
69-
70-
Alternatively since the default value is `Automatic`, the following configuration is equivalent:
71-
72-
```yaml
73-
apiVersion: cluster.x-k8s.io/v1beta1
74-
kind: Cluster
75-
metadata:
76-
name: <NAME>
77-
spec:
78-
topology:
79-
variables:
80-
- name: clusterConfig
81-
value:
82-
dns:
83-
coreDNS: {}
84-
```
85-
86-
Applying this configuration will result in the following value being set,
87-
with the version of the CoreDNS image being set based on the cluster's Kubernetes version:
88-
89-
- `KubeadmControlPlaneTemplate`:
90-
91-
- ```yaml
92-
spec:
93-
kubeadmConfigSpec:
94-
clusterConfiguration:
95-
dns:
96-
imageTag: "v1.11.3"
97-
```

pkg/handlers/generic/mutation/coredns/inject.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1111
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12-
"k8s.io/utils/ptr"
1312
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1413
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
1514
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
@@ -72,11 +71,10 @@ func (h *coreDNSPatchHandler) Mutate(
7271
h.variableFieldPath...,
7372
)
7473
if err != nil {
75-
if variables.IsNotFoundError(err) {
76-
log.V(5).Info("coreDNS variable not defined")
77-
return nil
74+
if !variables.IsNotFoundError(err) {
75+
return err
7876
}
79-
return err
77+
log.V(5).Info("coreDNS variable not defined")
8078
}
8179

8280
log = log.WithValues(
@@ -103,7 +101,7 @@ func (h *coreDNSPatchHandler) Mutate(
103101
log.WithValues(
104102
"patchedObjectKind", obj.GetObjectKind().GroupVersionKind().String(),
105103
"patchedObjectName", ctrlclient.ObjectKeyFromObject(obj),
106-
).Info("setting CoreDNS version if needed")
104+
).Info("setting CoreDNS version")
107105

108106
if obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration == nil {
109107
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration = &bootstrapv1.ClusterConfiguration{}
@@ -121,14 +119,9 @@ func (h *coreDNSPatchHandler) Mutate(
121119
}
122120
}
123121

124-
// If the updateStrategy is set Automatic, set the image tag to the default CoreDNS version based on the
122+
// If the CoreDNS image tag is still not set, set the image tag to the default CoreDNS version based on the
125123
// Kubernetes version.
126-
// Default the strategy to Automatic if var is not nil.
127-
strategy := ptr.Deref(
128-
coreDNSVar.UpdateStrategy,
129-
v1alpha1.CoreDNSUpdateStrategyAutomatic,
130-
)
131-
if strategy == v1alpha1.CoreDNSUpdateStrategyAutomatic {
124+
if dns.ImageTag == "" {
132125
defaultCoreDNSVersion, found := corednsversions.GetCoreDNSVersion(
133126
cluster.Spec.Topology.Version,
134127
)

pkg/handlers/generic/mutation/coredns/inject_test.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"k8s.io/apimachinery/pkg/runtime"
1414
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1515
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
16-
"k8s.io/utils/ptr"
1716
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1817
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1918

@@ -47,34 +46,7 @@ var _ = Describe("Generate CoreDNS patches", func() {
4746
testDefs := []testObj{
4847
{
4948
patchTest: capitest.PatchTestDef{
50-
Name: "unset variable",
51-
},
52-
cluster: clusterv1.Cluster{
53-
ObjectMeta: metav1.ObjectMeta{
54-
Name: "test-cluster",
55-
Namespace: request.Namespace,
56-
Labels: map[string]string{
57-
clusterv1.ProviderNameLabel: "nutanix",
58-
},
59-
},
60-
Spec: clusterv1.ClusterSpec{
61-
Topology: &clusterv1.Topology{
62-
Version: "1.30.100",
63-
},
64-
},
65-
},
66-
},
67-
{
68-
patchTest: capitest.PatchTestDef{
69-
Name: "variable with defaults",
70-
Vars: []runtimehooksv1.Variable{
71-
capitest.VariableWithValue(
72-
v1alpha1.ClusterConfigVariableName,
73-
v1alpha1.CoreDNS{},
74-
v1alpha1.DNSVariableName,
75-
VariableName,
76-
),
77-
},
49+
Name: "unset variable",
7850
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
7951
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{
8052
Operation: "add",
@@ -113,7 +85,6 @@ var _ = Describe("Generate CoreDNS patches", func() {
11385
Repository: "my-registry.io/my-org/my-repo",
11486
Tag: "v1.11.3_custom.0",
11587
},
116-
UpdateStrategy: ptr.To(v1alpha1.CoreDNSUpdateStrategyManual),
11788
},
11889
v1alpha1.DNSVariableName,
11990
VariableName,
@@ -200,7 +171,6 @@ var _ = Describe("Generate CoreDNS patches", func() {
200171
Image: &v1alpha1.Image{
201172
Tag: "v1.11.3_custom.0",
202173
},
203-
UpdateStrategy: ptr.To(v1alpha1.CoreDNSUpdateStrategyManual),
204174
},
205175
v1alpha1.DNSVariableName,
206176
VariableName,
@@ -235,15 +205,7 @@ var _ = Describe("Generate CoreDNS patches", func() {
235205
},
236206
{
237207
patchTest: capitest.PatchTestDef{
238-
Name: "error if cannot find default CoreDNS version",
239-
Vars: []runtimehooksv1.Variable{
240-
capitest.VariableWithValue(
241-
v1alpha1.ClusterConfigVariableName,
242-
v1alpha1.CoreDNS{},
243-
v1alpha1.DNSVariableName,
244-
VariableName,
245-
),
246-
},
208+
Name: "error if cannot find default CoreDNS version",
247209
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
248210
ExpectedFailure: true,
249211
},
@@ -273,7 +235,6 @@ var _ = Describe("Generate CoreDNS patches", func() {
273235
Repository: "my-registry.io/my-org/my-repo",
274236
Tag: "v1.11.3_custom.0",
275237
},
276-
UpdateStrategy: ptr.To(v1alpha1.CoreDNSUpdateStrategyManual),
277238
},
278239
v1alpha1.DNSVariableName,
279240
VariableName,

pkg/handlers/generic/mutation/coredns/variables_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
1616
)
1717

18-
const (
19-
invalidUpdateStrategy = v1alpha1.CoreDNSUpdateStrategy("this:is:not:a:valid:update:strategy")
20-
)
21-
2218
var testDefs = []capitest.VariableTestDef{{
2319
Name: "unset",
2420
Vals: v1alpha1.GenericClusterConfigSpec{
@@ -82,16 +78,6 @@ var testDefs = []capitest.VariableTestDef{{
8278
},
8379
},
8480
ExpectError: true,
85-
}, {
86-
Name: "set an invalid updateStrategy",
87-
Vals: v1alpha1.GenericClusterConfigSpec{
88-
DNS: &v1alpha1.DNS{
89-
CoreDNS: &v1alpha1.CoreDNS{
90-
UpdateStrategy: ptr.To(invalidUpdateStrategy),
91-
},
92-
},
93-
},
94-
ExpectError: true,
9581
}}
9682

9783
func TestVariableValidation_AWS(t *testing.T) {

0 commit comments

Comments
 (0)