Skip to content

Commit

Permalink
fix: add cluster name to the worker machine config
Browse files Browse the repository at this point in the history
This is 1.8+ only.

Fixes #8694

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed May 7, 2024
1 parent 4aac5b4 commit 763dae2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
2 changes: 0 additions & 2 deletions internal/integration/cli/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ func (suite *GenSuite) testGenConfigPatch(patch []byte) {
switch {
case tt.shouldAffect[configName]:
suite.Assert().Equal("bar", cfg.Cluster().Name(), "checking %q", configName)
case configName == "worker.yaml":
suite.Assert().Equal("", cfg.Cluster().Name(), "checking %q", configName)
default:
suite.Assert().Equal("foo", cfg.Cluster().Name(), "checking %q", configName)
}
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 @@ -144,3 +144,8 @@ func (contract *VersionContract) HostDNSEnabled() bool {
func (contract *VersionContract) UseRSAServiceAccountKey() bool {
return contract.Greater(TalosVersion1_6)
}

// ClusterNameForWorkers returns true if version of Talos should put cluster name to the worker machine config.
func (contract *VersionContract) ClusterNameForWorkers() 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 @@ -60,6 +60,7 @@ func TestContractCurrent(t *testing.T) {
assert.True(t, contract.KubePrismEnabled())
assert.True(t, contract.HostDNSEnabled())
assert.True(t, contract.UseRSAServiceAccountKey())
assert.True(t, contract.ClusterNameForWorkers())
}

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

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

func TestContract1_6(t *testing.T) {
Expand All @@ -117,6 +120,7 @@ func TestContract1_6(t *testing.T) {
assert.True(t, contract.KubePrismEnabled())
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
}

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

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

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

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

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

func TestContract1_0(t *testing.T) {
Expand All @@ -231,4 +240,5 @@ func TestContract1_0(t *testing.T) {
assert.False(t, contract.KubePrismEnabled())
assert.False(t, contract.HostDNSEnabled())
assert.False(t, contract.UseRSAServiceAccountKey())
assert.False(t, contract.ClusterNameForWorkers())
}
4 changes: 4 additions & 0 deletions pkg/machinery/config/generate/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (in *Input) worker() ([]config.Document, error) {
}
}

if in.Options.VersionContract.ClusterNameForWorkers() {
cluster.ClusterName = in.ClusterName
}

v1alpha1Config.MachineConfig = machine
v1alpha1Config.ClusterConfig = cluster

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cluster:
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=
controlPlane:
endpoint: https://base:6443
clusterName: base
network:
dnsDomain: cluster.local
podSubnets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cluster:
secret: pofHbABZq7VXuObsdLdy/bHmz6hlMHZ3p8+6WKrv1ic=
controlPlane:
endpoint: https://base:6443
clusterName: base
network:
cni:
name: custom
Expand Down

0 comments on commit 763dae2

Please sign in to comment.