From 4f16887a11466dbdf84b3961ee090075b1731c99 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Tue, 14 Mar 2023 09:45:16 +0000 Subject: [PATCH] unit tests: Fixes init and rejoin unit tests for Windows The default CRI Socket on Windows is npipe://./pipe/containerd-containerd. --- cmd/kubeadm/app/cmd/init_test.go | 6 +++--- cmd/kubeadm/app/cmd/join_test.go | 6 +++--- cmd/kubeadm/app/cmd/util_other_test.go | 22 ++++++++++++++++++++++ cmd/kubeadm/app/cmd/util_windows_test.go | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 cmd/kubeadm/app/cmd/util_other_test.go create mode 100644 cmd/kubeadm/app/cmd/util_windows_test.go diff --git a/cmd/kubeadm/app/cmd/init_test.go b/cmd/kubeadm/app/cmd/init_test.go index 10112726489..9ce458a31e4 100644 --- a/cmd/kubeadm/app/cmd/init_test.go +++ b/cmd/kubeadm/app/cmd/init_test.go @@ -42,7 +42,7 @@ localAPIEndpoint: bootstrapTokens: - token: "abcdef.0123456789abcdef" nodeRegistration: - criSocket: unix:///var/run/containerd/containerd.sock + criSocket: %s name: someName ignorePreflightErrors: - c @@ -51,7 +51,7 @@ nodeRegistration: apiVersion: %[1]s kind: ClusterConfiguration controlPlaneEndpoint: "3.4.5.6" -`, kubeadmapiv1.SchemeGroupVersion.String()) +`, kubeadmapiv1.SchemeGroupVersion.String(), expectedCRISocket) func TestNewInitData(t *testing.T) { // create temp directory @@ -113,7 +113,7 @@ func TestNewInitData(t *testing.T) { cfg: &kubeadmapi.InitConfiguration{ NodeRegistration: kubeadmapi.NodeRegistrationOptions{ Name: "somename", - CRISocket: "unix:///var/run/containerd/containerd.sock", + CRISocket: expectedCRISocket, IgnorePreflightErrors: []string{"c", "d"}, ImagePullPolicy: "IfNotPresent", }, diff --git a/cmd/kubeadm/app/cmd/join_test.go b/cmd/kubeadm/app/cmd/join_test.go index 4e323bb74e1..b6d547ad5fe 100644 --- a/cmd/kubeadm/app/cmd/join_test.go +++ b/cmd/kubeadm/app/cmd/join_test.go @@ -48,12 +48,12 @@ discovery: controlPlane: certificateKey: c39a18bae4a72e71b178661f437363da218a3efb83ddb03f1cd91d9ae1da41bd nodeRegistration: - criSocket: unix:///var/run/containerd/containerd.sock + criSocket: %s name: someName ignorePreflightErrors: - c - d -`, kubeadmapiv1.SchemeGroupVersion.String()) +`, kubeadmapiv1.SchemeGroupVersion.String(), expectedCRISocket) func TestNewJoinData(t *testing.T) { // create temp directory @@ -218,7 +218,7 @@ func TestNewJoinData(t *testing.T) { TypeMeta: metav1.TypeMeta{Kind: "", APIVersion: ""}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{ Name: "somename", - CRISocket: "unix:///var/run/containerd/containerd.sock", + CRISocket: expectedCRISocket, IgnorePreflightErrors: []string{"c", "d"}, ImagePullPolicy: "IfNotPresent", Taints: []v1.Taint{{Key: "node-role.kubernetes.io/control-plane", Effect: "NoSchedule"}}, diff --git a/cmd/kubeadm/app/cmd/util_other_test.go b/cmd/kubeadm/app/cmd/util_other_test.go new file mode 100644 index 00000000000..d2a2ab41832 --- /dev/null +++ b/cmd/kubeadm/app/cmd/util_other_test.go @@ -0,0 +1,22 @@ +//go:build !windows +// +build !windows + +/* +Copyright 2023 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 cmd + +const expectedCRISocket = "unix://var/run/containerd/containerd.sock" diff --git a/cmd/kubeadm/app/cmd/util_windows_test.go b/cmd/kubeadm/app/cmd/util_windows_test.go new file mode 100644 index 00000000000..1eaa8e4bf5f --- /dev/null +++ b/cmd/kubeadm/app/cmd/util_windows_test.go @@ -0,0 +1,22 @@ +//go:build windows +// +build windows + +/* +Copyright 2023 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 cmd + +const expectedCRISocket = "npipe://./pipe/containerd-containerd"