cleanup UnknownCRISocket for unit tests

This commit is contained in:
SataQiu 2023-10-24 16:46:51 +08:00
parent 71bedf5cb2
commit 16b3acc27a
4 changed files with 4 additions and 24 deletions

View File

@ -81,7 +81,7 @@ func TestNewInitData(t *testing.T) {
}{
// Init data passed using flags
{
name: "pass without any flag except the cri socket (use defaults)",
name: "pass without any flag (use defaults)",
},
{
name: "fail if unknown feature gates flag are passed",
@ -188,17 +188,9 @@ func TestNewInitData(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// initialize an external init option and inject it to the init cmd
initOptions := newInitOptions()
initOptions.skipCRIDetect = true // avoid CRI detection in unit tests
cmd := newCmdInit(nil, initOptions)
// set the cri socket here, otherwise the testcase might fail if is run on the node with multiple
// cri endpoints configured, the failure caused by this is normally not an expected failure.
if tc.flags == nil {
tc.flags = make(map[string]string)
}
// set `cri-socket` only if `CfgPath` is not set
if _, okay := tc.flags[options.CfgPath]; !okay {
tc.flags[options.NodeCRISocket] = constants.UnknownCRISocket
}
// sets cmd flags (that will be reflected on the init options)
for f, v := range tc.flags {
cmd.Flags().Set(f, v)

View File

@ -35,7 +35,6 @@ import (
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
)
@ -312,6 +311,7 @@ func TestNewJoinData(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// initialize an external join option and inject it to the join cmd
joinOptions := newJoinOptions()
joinOptions.skipCRIDetect = true // avoid CRI detection in unit tests
cmd := newCmdJoin(nil, joinOptions)
// set klog output destination to bytes.Buffer so that log could be fetched and verified later.
@ -320,15 +320,6 @@ func TestNewJoinData(t *testing.T) {
klog.LogToStderr(false)
defer klog.LogToStderr(true)
// set the cri socket here, otherwise the testcase might fail if is run on the node with multiple
// cri endpoints configured, the failure caused by this is normally not an expected failure.
if tc.flags == nil {
tc.flags = make(map[string]string)
}
// set `cri-socket` only if `CfgPath` is not set
if _, okay := tc.flags[options.CfgPath]; !okay {
tc.flags[options.NodeCRISocket] = constants.UnknownCRISocket
}
// sets cmd flags (that will be reflected on the join options)
for f, v := range tc.flags {
cmd.Flags().Set(f, v)

View File

@ -261,9 +261,6 @@ const (
// init/join time for use later. kubeadm annotates the node object with this information
AnnotationKubeadmCRISocket = "kubeadm.alpha.kubernetes.io/cri-socket"
// UnknownCRISocket defines the undetected or unknown CRI socket
UnknownCRISocket = "unix:///var/run/unknown.sock"
// KubeadmConfigConfigMap specifies in what ConfigMap in the kube-system namespace the `kubeadm init` configuration should be stored
KubeadmConfigConfigMap = "kubeadm-config"

View File

@ -56,7 +56,7 @@ func TestUploadConfiguration(t *testing.T) {
cfg.ComponentConfigs = kubeadmapi.ComponentConfigMap{}
cfg.ClusterConfiguration.KubernetesVersion = kubeadmconstants.MinimumControlPlaneVersion.WithPatch(10).String()
cfg.NodeRegistration.Name = "node-foo"
cfg.NodeRegistration.CRISocket = kubeadmconstants.UnknownCRISocket
cfg.NodeRegistration.CRISocket = kubeadmconstants.DefaultCRISocket
client := clientsetfake.NewSimpleClientset()
// For idempotent test, we check the result of the second call.