Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clusterDNS cannot change when DNS is enabled #379

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/k8s/pkg/k8sd/types/cluster_config_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func MergeClusterConfig(existing ClusterConfig, new ClusterConfig) (ClusterConfi
// apiserver
{name: "kube-apiserver authorization mode", val: &config.APIServer.AuthorizationMode, old: existing.APIServer.AuthorizationMode, new: new.APIServer.AuthorizationMode, allowChange: true},
// kubelet
{name: "kubelet cluster DNS", val: &config.Kubelet.ClusterDNS, old: existing.Kubelet.ClusterDNS, new: new.Kubelet.ClusterDNS, allowChange: true},
{name: "kubelet cluster DNS", val: &config.Kubelet.ClusterDNS, old: existing.Kubelet.ClusterDNS, new: new.Kubelet.ClusterDNS, allowChange: !existing.DNS.GetEnabled() || !new.DNS.GetEnabled()},
{name: "kubelet cluster domain", val: &config.Kubelet.ClusterDomain, old: existing.Kubelet.ClusterDomain, new: new.Kubelet.ClusterDomain, allowChange: true},
{name: "kubelet cloud provider", val: &config.Kubelet.CloudProvider, old: existing.Kubelet.CloudProvider, new: new.Kubelet.CloudProvider, allowChange: true},
// ingress
Expand Down
73 changes: 70 additions & 3 deletions src/k8s/pkg/k8sd/types/cluster_config_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ func TestMergeClusterConfig(t *testing.T) {
generateMergeClusterConfigTestCases("APIServer/SecurePort", false, 6443, 16443, func(c *types.ClusterConfig, v any) { c.APIServer.SecurePort = utils.Pointer(v.(int)) }),
generateMergeClusterConfigTestCases("APIServer/AuthorizationMode", true, "v1", "v2", func(c *types.ClusterConfig, v any) { c.APIServer.AuthorizationMode = utils.Pointer(v.(string)) }),
generateMergeClusterConfigTestCases("Kubelet/CloudProvider", true, "v1", "v2", func(c *types.ClusterConfig, v any) { c.Kubelet.CloudProvider = utils.Pointer(v.(string)) }),
generateMergeClusterConfigTestCases("Kubelet/ClusterDNS", true, "1.1.1.1", "2.2.2.2", func(c *types.ClusterConfig, v any) { c.Kubelet.ClusterDNS = utils.Pointer(v.(string)) }),
generateMergeClusterConfigTestCases("Kubelet/ClusterDNS/AllowChange", true, "1.1.1.1", "2.2.2.2", func(c *types.ClusterConfig, v any) { c.Kubelet.ClusterDNS = utils.Pointer(v.(string)) }),
generateMergeClusterConfigTestCases("Kubelet/ClusterDNS/PreventChangeIfDNSEnabled", false, "1.1.1.1", "2.2.2.2", func(c *types.ClusterConfig, v any) {
c.DNS.Enabled = utils.Pointer(true)
c.Kubelet.ClusterDNS = utils.Pointer(v.(string))
}),
generateMergeClusterConfigTestCases("Kubelet/ClusterDomain", true, "v1", "v2", func(c *types.ClusterConfig, v any) { c.Kubelet.ClusterDomain = utils.Pointer(v.(string)) }),
generateMergeClusterConfigTestCases("DNS/Enable", true, true, false, func(c *types.ClusterConfig, v any) { c.DNS.Enabled = utils.Pointer(v.(bool)) }),
generateMergeClusterConfigTestCases("DNS/Disable", true, false, true, func(c *types.ClusterConfig, v any) { c.DNS.Enabled = utils.Pointer(v.(bool)) }),
Expand Down Expand Up @@ -178,14 +182,14 @@ func TestMergeClusterConfig(t *testing.T) {
generateMergeClusterConfigTestCases("LocalStorage/LocalPath/AllowChange", true, "a1", "a2", func(c *types.ClusterConfig, v any) {
c.LocalStorage.LocalPath = utils.Pointer(v.(string))
}),
generateMergeClusterConfigTestCases("LocalStorage/LocalPath/PreventChange", false, "a1", "a2", func(c *types.ClusterConfig, v any) {
generateMergeClusterConfigTestCases("LocalStorage/LocalPath/PreventChangeIfEnabled", false, "a1", "a2", func(c *types.ClusterConfig, v any) {
c.LocalStorage.Enabled = utils.Pointer(true)
c.LocalStorage.LocalPath = utils.Pointer(v.(string))
}),
generateMergeClusterConfigTestCases("LocalStorage/ReclaimPolicy/AllowChange", true, "Retain", "Delete", func(c *types.ClusterConfig, v any) {
c.LocalStorage.ReclaimPolicy = utils.Pointer(v.(string))
}),
generateMergeClusterConfigTestCases("LocalStorage/ReclaimPolicy/PreventChange", false, "Retain", "Delete", func(c *types.ClusterConfig, v any) {
generateMergeClusterConfigTestCases("LocalStorage/ReclaimPolicy/PreventChangeIfEnabled", false, "Retain", "Delete", func(c *types.ClusterConfig, v any) {
c.LocalStorage.Enabled = utils.Pointer(true)
c.LocalStorage.LocalPath = utils.Pointer("path")
c.LocalStorage.ReclaimPolicy = utils.Pointer(v.(string))
Expand Down Expand Up @@ -219,6 +223,69 @@ func TestMergeClusterConfig_Scenarios(t *testing.T) {
expectMerged types.ClusterConfig
expectErr bool
}{
{
name: "Kubelet/AllowSetClusterDNS/EnableDNSAfter",
old: types.ClusterConfig{
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("1.1.1.1"),
},
},
new: types.ClusterConfig{
DNS: types.DNS{
Enabled: utils.Pointer(true),
},
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("2.2.2.2"),
},
},
expectMerged: types.ClusterConfig{
DNS: types.DNS{
Enabled: utils.Pointer(true),
},
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("2.2.2.2"),
},
},
},
{
name: "Kubelet/AllowSetClusterDNS/KeepDNSDisabled",
old: types.ClusterConfig{
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("1.1.1.1"),
},
},
new: types.ClusterConfig{
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("2.2.2.2"),
},
},
expectMerged: types.ClusterConfig{
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("2.2.2.2"),
},
},
},
{
name: "Kubelet/AllowSetClusterDNS/IfDNSEnabledButDNSEmpty",
old: types.ClusterConfig{
DNS: types.DNS{
Enabled: utils.Pointer(true),
},
},
new: types.ClusterConfig{
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("2.2.2.2"),
},
},
expectMerged: types.ClusterConfig{
DNS: types.DNS{
Enabled: utils.Pointer(true),
},
Kubelet: types.Kubelet{
ClusterDNS: utils.Pointer("2.2.2.2"),
},
},
},
{
name: "LoadBalancer/NeedNetwork",
old: types.ClusterConfig{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func mergeField[T comparable](old *T, new *T, allowChange bool) (*T, error) {

// both values are not-empty
if !allowChange {
return nil, fmt.Errorf("value has changed")
return nil, fmt.Errorf("value cannot change")
}
return new, nil
}
Expand Down
Loading