Merge pull request #121347 from SataQiu/fix-kubeadm-20231019

kubeadm: fix TestValidateConfig failure on the host with multiple CRI endpoints
This commit is contained in:
Kubernetes Prow Robot 2023-10-19 12:25:56 +02:00 committed by GitHub
commit a570b05253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 23 deletions

View File

@ -61,7 +61,6 @@ apiVersion: %s
kind: InitConfiguration kind: InitConfiguration
nodeRegistration: nodeRegistration:
name: foo name: foo
criSocket: %s
localAPIEndpoint: localAPIEndpoint:
advertiseAddress: 192.168.2.2 advertiseAddress: 192.168.2.2
bindPort: 6443 bindPort: 6443
@ -86,7 +85,7 @@ networking:
dnsDomain: cluster.local dnsDomain: cluster.local
podSubnet: "" podSubnet: ""
serviceSubnet: 10.96.0.0/12 serviceSubnet: 10.96.0.0/12
`, kubeadmapiv1.SchemeGroupVersion.String(), constants.UnknownCRISocket) `, kubeadmapiv1.SchemeGroupVersion.String())
// fakeWaiter is a fake apiclient.Waiter that returns errors it was initialized with // fakeWaiter is a fake apiclient.Waiter that returns errors it was initialized with
type fakeWaiter struct { type fakeWaiter struct {
@ -600,7 +599,7 @@ func getConfig(version, certsDir, etcdDataDir string) (*kubeadmapi.InitConfigura
configBytes := []byte(fmt.Sprintf(testConfiguration, certsDir, etcdDataDir, version)) configBytes := []byte(fmt.Sprintf(testConfiguration, certsDir, etcdDataDir, version))
// Unmarshal the config // Unmarshal the config
return configutil.BytesToInitConfiguration(configBytes, false) return configutil.BytesToInitConfiguration(configBytes, true /* skipCRIDetect */)
} }
func getTempDir(t *testing.T, name string) (string, func()) { func getTempDir(t *testing.T, name string) (string, func()) {

View File

@ -332,21 +332,21 @@ func ValidateConfig(config []byte, allowExperimental bool) error {
// Validate InitConfiguration and ClusterConfiguration if there are any in the config // Validate InitConfiguration and ClusterConfiguration if there are any in the config
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvks...) || kubeadmutil.GroupVersionKindsHasClusterConfiguration(gvks...) { if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvks...) || kubeadmutil.GroupVersionKindsHasClusterConfiguration(gvks...) {
if _, err := documentMapToInitConfiguration(gvkmap, true, allowExperimental, true, false); err != nil { if _, err := documentMapToInitConfiguration(gvkmap, true, allowExperimental, true, true); err != nil {
return err return err
} }
} }
// Validate JoinConfiguration if there is any // Validate JoinConfiguration if there is any
if kubeadmutil.GroupVersionKindsHasJoinConfiguration(gvks...) { if kubeadmutil.GroupVersionKindsHasJoinConfiguration(gvks...) {
if _, err := documentMapToJoinConfiguration(gvkmap, true, allowExperimental, true, false); err != nil { if _, err := documentMapToJoinConfiguration(gvkmap, true, allowExperimental, true, true); err != nil {
return err return err
} }
} }
// Validate ResetConfiguration if there is any // Validate ResetConfiguration if there is any
if kubeadmutil.GroupVersionKindsHasResetConfiguration(gvks...) { if kubeadmutil.GroupVersionKindsHasResetConfiguration(gvks...) {
if _, err := documentMapToResetConfiguration(gvkmap, true, allowExperimental, true, false); err != nil { if _, err := documentMapToResetConfiguration(gvkmap, true, allowExperimental, true, true); err != nil {
return err return err
} }
} }

View File

@ -510,30 +510,24 @@ func TestValidateConfig(t *testing.T) {
cfg: dedent.Dedent(fmt.Sprintf(` cfg: dedent.Dedent(fmt.Sprintf(`
apiVersion: %s apiVersion: %s
kind: InitConfiguration kind: InitConfiguration
nodeRegistration:
criSocket: %s
name: foo bar # not a valid subdomain name: foo bar # not a valid subdomain
`, gv, constants.UnknownCRISocket)), `, gv)),
expectedError: true, expectedError: true,
}, },
{ {
name: "unknown API GVK", name: "unknown API GVK",
cfg: dedent.Dedent(fmt.Sprintf(` cfg: dedent.Dedent(`
apiVersion: foo/bar # not a valid GroupVersion apiVersion: foo/bar # not a valid GroupVersion
kind: zzz # not a valid Kind kind: zzz # not a valid Kind
nodeRegistration: `),
criSocket: %s
`, constants.UnknownCRISocket)),
expectedError: true, expectedError: true,
}, },
{ {
name: "legacy API GVK", name: "legacy API GVK",
cfg: dedent.Dedent(fmt.Sprintf(` cfg: dedent.Dedent(`
apiVersion: kubeadm.k8s.io/v1beta1 # legacy API apiVersion: kubeadm.k8s.io/v1beta1 # legacy API
kind: InitConfiguration kind: InitConfiguration
nodeRegistration: `),
criSocket: %s
`, constants.UnknownCRISocket)),
expectedError: true, expectedError: true,
}, },
{ {
@ -542,9 +536,7 @@ func TestValidateConfig(t *testing.T) {
apiVersion: %s apiVersion: %s
kind: InitConfiguration kind: InitConfiguration
foo: bar foo: bar
nodeRegistration: `, gv)),
criSocket: %s
`, gv, constants.UnknownCRISocket)),
expectedError: true, expectedError: true,
}, },
{ {
@ -552,9 +544,7 @@ func TestValidateConfig(t *testing.T) {
cfg: dedent.Dedent(fmt.Sprintf(` cfg: dedent.Dedent(fmt.Sprintf(`
apiVersion: %s apiVersion: %s
kind: InitConfiguration kind: InitConfiguration
nodeRegistration: `, gv)),
criSocket: %s
`, gv, constants.UnknownCRISocket)),
expectedError: false, expectedError: false,
}, },
{ {