Skip to content

Commit

Permalink
feat: enable forwardKubeDNSToHost by default
Browse files Browse the repository at this point in the history
And ensure that it works.

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
  • Loading branch information
DmitriyMV committed May 23, 2024
1 parent 2e64e9e commit fcd65ff
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 2 deletions.
17 changes: 17 additions & 0 deletions hack/release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ Talos is built with Go 1.22.3.
description = """\
Talos Linux now compresses kernel and initramfs using ZSTD.
Linux arm64 kernel is now compressed (previously it was uncompressed).
"""

[notes.forward-kube-dns-to-host]
title = "DNS Forwarding for CoreDNS pods"
description = """\
Usage of the host DNS resolver as upstream for Kubernetes CoreDNS pods is now enabled by default. You can disable it
with:
```yaml
machine:
features:
hostDNS:
enabled: true
forwardKubeDNSToHost: false
```
Please note that on running cluster you will have to kill CoreDNS pods for this change to apply.
"""

[make_deps]
Expand Down
5 changes: 5 additions & 0 deletions pkg/machinery/config/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,8 @@ func (contract *VersionContract) UseRSAServiceAccountKey() bool {
func (contract *VersionContract) ClusterNameForWorkers() bool {
return contract.Greater(TalosVersion1_7)
}

// HostDNSForwardKubeDNSToHost returns true if version of Talos forces host dns router to be used as upstream for Kubernetes CoreDNS pods.
func (contract *VersionContract) HostDNSForwardKubeDNSToHost() bool {
return contract.Greater(TalosVersion1_7)
}
10 changes: 10 additions & 0 deletions pkg/machinery/config/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestContractCurrent(t *testing.T) {
assert.True(t, contract.HostDNSEnabled())
assert.True(t, contract.UseRSAServiceAccountKey())
assert.True(t, contract.ClusterNameForWorkers())
assert.True(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_8(t *testing.T) {
Expand All @@ -81,6 +82,7 @@ func TestContract1_8(t *testing.T) {
assert.True(t, contract.HostDNSEnabled())
assert.True(t, contract.UseRSAServiceAccountKey())
assert.True(t, contract.ClusterNameForWorkers())
assert.True(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_7(t *testing.T) {
Expand All @@ -101,6 +103,7 @@ func TestContract1_7(t *testing.T) {
assert.True(t, contract.HostDNSEnabled())
assert.True(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_6(t *testing.T) {
Expand All @@ -121,6 +124,7 @@ func TestContract1_6(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_5(t *testing.T) {
Expand All @@ -141,6 +145,7 @@ func TestContract1_5(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_4(t *testing.T) {
Expand All @@ -161,6 +166,7 @@ func TestContract1_4(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_3(t *testing.T) {
Expand All @@ -181,6 +187,7 @@ func TestContract1_3(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_2(t *testing.T) {
Expand All @@ -201,6 +208,7 @@ func TestContract1_2(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_1(t *testing.T) {
Expand All @@ -221,6 +229,7 @@ func TestContract1_1(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}

func TestContract1_0(t *testing.T) {
Expand All @@ -241,4 +250,5 @@ func TestContract1_0(t *testing.T) {
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
assert.False(t, contract.HostDNSForwardKubeDNSToHost())
}
10 changes: 9 additions & 1 deletion pkg/machinery/config/generate/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (in *Input) init() ([]config.Document, error) {
if in.Options.VersionContract.HostDNSEnabled() {
machine.MachineFeatures.HostDNSSupport = &v1alpha1.HostDNSConfig{
HostDNSEnabled: pointer.To(true),
HostDNSForwardKubeDNSToHost: in.Options.HostDNSForwardKubeDNSToHost.Ptr(),
HostDNSForwardKubeDNSToHost: ptrOrNil(in.Options.HostDNSForwardKubeDNSToHost.ValueOrZero() || in.Options.VersionContract.HostDNSForwardKubeDNSToHost()),
}
}

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

return []config.Document{v1alpha1Config}, nil
}

func ptrOrNil(b bool) *bool {
if b {
return &b
}

return nil
}
2 changes: 1 addition & 1 deletion pkg/machinery/config/generate/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (in *Input) worker() ([]config.Document, error) {
if in.Options.VersionContract.HostDNSEnabled() {
machine.MachineFeatures.HostDNSSupport = &v1alpha1.HostDNSConfig{
HostDNSEnabled: pointer.To(true),
HostDNSForwardKubeDNSToHost: in.Options.HostDNSForwardKubeDNSToHost.Ptr(),
HostDNSForwardKubeDNSToHost: ptrOrNil(in.Options.HostDNSForwardKubeDNSToHost.ValueOrZero() || in.Options.VersionContract.HostDNSForwardKubeDNSToHost()),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ machine:
port: 7445
hostDNS:
enabled: true
forwardKubeDNSToHost: true
cluster:
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ machine:
port: 7445
hostDNS:
enabled: true
forwardKubeDNSToHost: true
cluster:
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ machine:
port: 7445
hostDNS:
enabled: true
forwardKubeDNSToHost: true
cluster:
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ machine:
port: 7445
hostDNS:
enabled: true
forwardKubeDNSToHost: true
cluster:
id: 0raF93qnkMvF-FZNuvyGozXNdLiT2FOWSlyBaW4PR-w=
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=
Expand Down

0 comments on commit fcd65ff

Please sign in to comment.