forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#124038 from SataQiu/fix-kubeadm-20240325
kubeadm: stop storing the ResolverConfig in the global KubeletConfiguration and instead set it dynamically for each node
- Loading branch information
Showing
6 changed files
with
127 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package componentconfigs | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
kubeletconfig "k8s.io/kubelet/config/v1beta1" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func TestMutateResolverConfig(t *testing.T) { | ||
var fooResolverConfig = "/foo/resolver" | ||
|
||
tests := []struct { | ||
name string | ||
cfg *kubeletconfig.KubeletConfiguration | ||
isServiceActiveFunc func(string) (bool, error) | ||
expected *kubeletconfig.KubeletConfiguration | ||
}{ | ||
{ | ||
name: "the resolver config should not be mutated when it was set already even if systemd-resolved is active", | ||
cfg: &kubeletconfig.KubeletConfiguration{ | ||
ResolverConfig: ptr.To(fooResolverConfig), | ||
}, | ||
isServiceActiveFunc: func(string) (bool, error) { return true, nil }, | ||
expected: &kubeletconfig.KubeletConfiguration{ | ||
ResolverConfig: ptr.To(fooResolverConfig), | ||
}, | ||
}, | ||
{ | ||
name: "the resolver config should be set when systemd-resolved is active", | ||
cfg: &kubeletconfig.KubeletConfiguration{ | ||
ResolverConfig: nil, | ||
}, | ||
isServiceActiveFunc: func(string) (bool, error) { return true, nil }, | ||
expected: &kubeletconfig.KubeletConfiguration{ | ||
ResolverConfig: ptr.To(kubeletSystemdResolverConfig), | ||
}, | ||
}, | ||
{ | ||
name: "the resolver config should not be set when systemd-resolved is not active", | ||
cfg: &kubeletconfig.KubeletConfiguration{ | ||
ResolverConfig: nil, | ||
}, | ||
isServiceActiveFunc: func(string) (bool, error) { return false, nil }, | ||
expected: &kubeletconfig.KubeletConfiguration{ | ||
ResolverConfig: nil, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
err := mutateResolverConfig(test.cfg, test.isServiceActiveFunc) | ||
if err != nil { | ||
t.Fatalf("failed to mutate ResolverConfig for KubeletConfiguration, %v", err) | ||
} | ||
if !reflect.DeepEqual(test.cfg, test.expected) { | ||
t.Errorf("Missmatch between expected and got:\nExpected:\n%+v\n---\nGot:\n%+v", | ||
test.expected, test.cfg) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|