Skip to content

Commit fcd65ff

Browse files
author
Dmitriy Matrenichev
committed
feat: enable forwardKubeDNSToHost by default
And ensure that it works. Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
1 parent 2e64e9e commit fcd65ff

9 files changed

Lines changed: 46 additions & 2 deletions

File tree

hack/release.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ Talos is built with Go 1.22.3.
3131
description = """\
3232
Talos Linux now compresses kernel and initramfs using ZSTD.
3333
Linux arm64 kernel is now compressed (previously it was uncompressed).
34+
"""
35+
36+
[notes.forward-kube-dns-to-host]
37+
title = "DNS Forwarding for CoreDNS pods"
38+
description = """\
39+
Usage of the host DNS resolver as upstream for Kubernetes CoreDNS pods is now enabled by default. You can disable it
40+
with:
41+
42+
```yaml
43+
machine:
44+
features:
45+
hostDNS:
46+
enabled: true
47+
forwardKubeDNSToHost: false
48+
```
49+
50+
Please note that on running cluster you will have to kill CoreDNS pods for this change to apply.
3451
"""
3552

3653
[make_deps]

pkg/machinery/config/contract.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,8 @@ func (contract *VersionContract) UseRSAServiceAccountKey() bool {
149149
func (contract *VersionContract) ClusterNameForWorkers() bool {
150150
return contract.Greater(TalosVersion1_7)
151151
}
152+
153+
// HostDNSForwardKubeDNSToHost returns true if version of Talos forces host dns router to be used as upstream for Kubernetes CoreDNS pods.
154+
func (contract *VersionContract) HostDNSForwardKubeDNSToHost() bool {
155+
return contract.Greater(TalosVersion1_7)
156+
}

pkg/machinery/config/contract_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestContractCurrent(t *testing.T) {
6161
assert.True(t, contract.HostDNSEnabled())
6262
assert.True(t, contract.UseRSAServiceAccountKey())
6363
assert.True(t, contract.ClusterNameForWorkers())
64+
assert.True(t, contract.HostDNSForwardKubeDNSToHost())
6465
}
6566

6667
func TestContract1_8(t *testing.T) {
@@ -81,6 +82,7 @@ func TestContract1_8(t *testing.T) {
8182
assert.True(t, contract.HostDNSEnabled())
8283
assert.True(t, contract.UseRSAServiceAccountKey())
8384
assert.True(t, contract.ClusterNameForWorkers())
85+
assert.True(t, contract.HostDNSForwardKubeDNSToHost())
8486
}
8587

8688
func TestContract1_7(t *testing.T) {
@@ -101,6 +103,7 @@ func TestContract1_7(t *testing.T) {
101103
assert.True(t, contract.HostDNSEnabled())
102104
assert.True(t, contract.UseRSAServiceAccountKey())
103105
assert.False(t, contract.ClusterNameForWorkers())
106+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
104107
}
105108

106109
func TestContract1_6(t *testing.T) {
@@ -121,6 +124,7 @@ func TestContract1_6(t *testing.T) {
121124
assert.False(t, contract.HostDNSEnabled())
122125
assert.False(t, contract.UseRSAServiceAccountKey())
123126
assert.False(t, contract.ClusterNameForWorkers())
127+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
124128
}
125129

126130
func TestContract1_5(t *testing.T) {
@@ -141,6 +145,7 @@ func TestContract1_5(t *testing.T) {
141145
assert.False(t, contract.HostDNSEnabled())
142146
assert.False(t, contract.UseRSAServiceAccountKey())
143147
assert.False(t, contract.ClusterNameForWorkers())
148+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
144149
}
145150

146151
func TestContract1_4(t *testing.T) {
@@ -161,6 +166,7 @@ func TestContract1_4(t *testing.T) {
161166
assert.False(t, contract.HostDNSEnabled())
162167
assert.False(t, contract.UseRSAServiceAccountKey())
163168
assert.False(t, contract.ClusterNameForWorkers())
169+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
164170
}
165171

166172
func TestContract1_3(t *testing.T) {
@@ -181,6 +187,7 @@ func TestContract1_3(t *testing.T) {
181187
assert.False(t, contract.HostDNSEnabled())
182188
assert.False(t, contract.UseRSAServiceAccountKey())
183189
assert.False(t, contract.ClusterNameForWorkers())
190+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
184191
}
185192

186193
func TestContract1_2(t *testing.T) {
@@ -201,6 +208,7 @@ func TestContract1_2(t *testing.T) {
201208
assert.False(t, contract.HostDNSEnabled())
202209
assert.False(t, contract.UseRSAServiceAccountKey())
203210
assert.False(t, contract.ClusterNameForWorkers())
211+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
204212
}
205213

206214
func TestContract1_1(t *testing.T) {
@@ -221,6 +229,7 @@ func TestContract1_1(t *testing.T) {
221229
assert.False(t, contract.HostDNSEnabled())
222230
assert.False(t, contract.UseRSAServiceAccountKey())
223231
assert.False(t, contract.ClusterNameForWorkers())
232+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
224233
}
225234

226235
func TestContract1_0(t *testing.T) {
@@ -241,4 +250,5 @@ func TestContract1_0(t *testing.T) {
241250
assert.False(t, contract.HostDNSEnabled())
242251
assert.False(t, contract.UseRSAServiceAccountKey())
243252
assert.False(t, contract.ClusterNameForWorkers())
253+
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
244254
}

pkg/machinery/config/generate/init.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (in *Input) init() ([]config.Document, error) {
9696
if in.Options.VersionContract.HostDNSEnabled() {
9797
machine.MachineFeatures.HostDNSSupport = &v1alpha1.HostDNSConfig{
9898
HostDNSEnabled: pointer.To(true),
99-
HostDNSForwardKubeDNSToHost: in.Options.HostDNSForwardKubeDNSToHost.Ptr(),
99+
HostDNSForwardKubeDNSToHost: ptrOrNil(in.Options.HostDNSForwardKubeDNSToHost.ValueOrZero() || in.Options.VersionContract.HostDNSForwardKubeDNSToHost()),
100100
}
101101
}
102102

@@ -229,3 +229,11 @@ func (in *Input) init() ([]config.Document, error) {
229229

230230
return []config.Document{v1alpha1Config}, nil
231231
}
232+
233+
func ptrOrNil(b bool) *bool {
234+
if b {
235+
return &b
236+
}
237+
238+
return nil
239+
}

pkg/machinery/config/generate/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (in *Input) worker() ([]config.Document, error) {
9797
if in.Options.VersionContract.HostDNSEnabled() {
9898
machine.MachineFeatures.HostDNSSupport = &v1alpha1.HostDNSConfig{
9999
HostDNSEnabled: pointer.To(true),
100-
HostDNSForwardKubeDNSToHost: in.Options.HostDNSForwardKubeDNSToHost.Ptr(),
100+
HostDNSForwardKubeDNSToHost: ptrOrNil(in.Options.HostDNSForwardKubeDNSToHost.ValueOrZero() || in.Options.VersionContract.HostDNSForwardKubeDNSToHost()),
101101
}
102102
}
103103

pkg/machinery/config/types/v1alpha1/testdata/stability/v1.8/base-controlplane.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ machine:
2525
port: 7445
2626
hostDNS:
2727
enabled: true
28+
forwardKubeDNSToHost: true
2829
cluster:
2930
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
3031
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=

pkg/machinery/config/types/v1alpha1/testdata/stability/v1.8/base-worker.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ machine:
2525
port: 7445
2626
hostDNS:
2727
enabled: true
28+
forwardKubeDNSToHost: true
2829
cluster:
2930
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
3031
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=

pkg/machinery/config/types/v1alpha1/testdata/stability/v1.8/overrides-controlplane.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ machine:
4444
port: 7445
4545
hostDNS:
4646
enabled: true
47+
forwardKubeDNSToHost: true
4748
cluster:
4849
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
4950
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=

pkg/machinery/config/types/v1alpha1/testdata/stability/v1.8/overrides-worker.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ machine:
4444
port: 7445
4545
hostDNS:
4646
enabled: true
47+
forwardKubeDNSToHost: true
4748
cluster:
4849
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
4950
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=

0 commit comments

Comments
 (0)