diff --git a/cmd/kubeadm/app/util/config/common_test.go b/cmd/kubeadm/app/util/config/common_test.go index 538c03e0962..0e76cc5d0a4 100644 --- a/cmd/kubeadm/app/util/config/common_test.go +++ b/cmd/kubeadm/app/util/config/common_test.go @@ -455,8 +455,10 @@ func TestMigrateOldConfig(t *testing.T) { // - JoinConfiguration.Discovery.Timeout -> JoinConfiguration.Timeout.Discovery func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { var ( - gv = kubeadmapiv1old.SchemeGroupVersion.String() - gvNew = kubeadmapiv1.SchemeGroupVersion.String() + gv = kubeadmapiv1old.SchemeGroupVersion.String() + gvNew = kubeadmapiv1.SchemeGroupVersion.String() + criSocket = fmt.Sprintf("%s:///some-socket-path", kubeadmapiv1.DefaultContainerRuntimeURLScheme) + caCertPath = kubeadmapiv1.DefaultCACertPath input = dedent.Dedent(fmt.Sprintf(` apiVersion: %s @@ -473,7 +475,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { advertiseAddress: 1.2.3.4 bindPort: 6443 nodeRegistration: - criSocket: unix:///some-socket-path + criSocket: %[2]s kubeletExtraArgs: # MIGRATED foo: bar name: node @@ -499,7 +501,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { apiVersion: %[1]s kind: JoinConfiguration nodeRegistration: - criSocket: unix:///some-socket-path + criSocket: %[2]s imagePullPolicy: IfNotPresent kubeletExtraArgs: # MIGRATED foo: baz @@ -512,7 +514,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { unsafeSkipCAVerification: true tlsBootstrapToken: abcdef.0123456789abcdef timeout: 2m10s # MIGRATED - `, gv)) + `, gv, criSocket)) expectedOutput = dedent.Dedent(fmt.Sprintf(` apiVersion: %s @@ -529,7 +531,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { advertiseAddress: 1.2.3.4 bindPort: 6443 nodeRegistration: - criSocket: unix:///some-socket-path + criSocket: %[2]s imagePullPolicy: IfNotPresent imagePullSerial: true kubeletExtraArgs: @@ -582,7 +584,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { value: bar --- apiVersion: %[1]s - caCertPath: /etc/kubernetes/pki/ca.crt + caCertPath: %[3]s discovery: bootstrapToken: apiServerEndpoint: some-address:6443 @@ -591,7 +593,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { tlsBootstrapToken: abcdef.0123456789abcdef kind: JoinConfiguration nodeRegistration: - criSocket: unix:///some-socket-path + criSocket: %[2]s imagePullPolicy: IfNotPresent imagePullSerial: true kubeletExtraArgs: @@ -607,7 +609,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) { kubernetesAPICall: 1m0s tlsBootstrap: 5m0s upgradeManifests: 5m0s - `, gvNew)) + `, gvNew, criSocket, caCertPath)) ) b, err := MigrateOldConfig([]byte(input), false, defaultEmptyMigrateMutators()) diff --git a/pkg/kubelet/util/util_windows_test.go b/pkg/kubelet/util/util_windows_test.go index ace346adbe9..e3f1cf500af 100644 --- a/pkg/kubelet/util/util_windows_test.go +++ b/pkg/kubelet/util/util_windows_test.go @@ -20,13 +20,12 @@ limitations under the License. package util import ( - "context" - "net" + "fmt" "reflect" "runtime" + "strings" "testing" - "github.com/Microsoft/go-winio" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -98,13 +97,10 @@ func TestLocalEndpoint(t *testing.T) { } } -func npipeDial(ctx context.Context, addr string) (net.Conn, error) { - return winio.DialPipeContext(ctx, addr) -} - func TestLocalEndpointRoundTrip(t *testing.T) { - npipeDialPointer := reflect.ValueOf(npipeDial).Pointer() - expectedDialerName := runtime.FuncForPC(npipeDialPointer).Name() + functionPointer := reflect.ValueOf(util.GetAddressAndDialer).Pointer() + functionName := runtime.FuncForPC(functionPointer).Name() + expectedDialerName := fmt.Sprintf("%s.npipeDial", functionName[:strings.LastIndex(functionName, ".")]) expectedAddress := "//./pipe/kubelet-pod-resources" fullPath, err := LocalEndpoint(`pod-resources`, "kubelet") @@ -116,8 +112,6 @@ func TestLocalEndpointRoundTrip(t *testing.T) { dialerPointer := reflect.ValueOf(dialer).Pointer() actualDialerName := runtime.FuncForPC(dialerPointer).Name() - assert.Equalf(t, npipeDialPointer, dialerPointer, - "Expected dialer %s, but get %s", expectedDialerName, actualDialerName) - + assert.Equal(t, expectedDialerName, actualDialerName) assert.Equal(t, expectedAddress, address) } diff --git a/pkg/proxy/apis/config/validation/validation_other_test.go b/pkg/proxy/apis/config/validation/validation_other_test.go new file mode 100644 index 00000000000..330b8f9b0f9 --- /dev/null +++ b/pkg/proxy/apis/config/validation/validation_other_test.go @@ -0,0 +1,42 @@ +//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 validation + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/validation/field" + kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" +) + +var ( + kubeProxyConfigNewPath = field.NewPath("KubeProxyConfiguration") + osKubeProxyConfigTestCases = map[string]struct { + mutateConfigFunc func(*kubeproxyconfig.KubeProxyConfiguration) + expectedErrs field.ErrorList + }{ + // Windows doesn't support IPVS, so this test will fail. + "IPVS mode selected without providing required SyncPeriod": { + mutateConfigFunc: func(config *kubeproxyconfig.KubeProxyConfiguration) { + config.Mode = kubeproxyconfig.ProxyModeIPVS + }, + expectedErrs: field.ErrorList{field.Invalid(kubeProxyConfigNewPath.Child("KubeProxyIPVSConfiguration.SyncPeriod"), metav1.Duration{Duration: 0}, "must be greater than 0")}, + }, + } +) diff --git a/pkg/proxy/apis/config/validation/validation_test.go b/pkg/proxy/apis/config/validation/validation_test.go index 379161f5a5e..30cda3e1dd9 100644 --- a/pkg/proxy/apis/config/validation/validation_test.go +++ b/pkg/proxy/apis/config/validation/validation_test.go @@ -55,7 +55,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) { } newPath := field.NewPath("KubeProxyConfiguration") - for name, testCase := range map[string]struct { + testCases := map[string]struct { mutateConfigFunc func(*kubeproxyconfig.KubeProxyConfiguration) expectedErrs field.ErrorList }{ @@ -155,12 +155,6 @@ func TestValidateKubeProxyConfiguration(t *testing.T) { }, expectedErrs: field.ErrorList{field.Invalid(newPath.Child("ConfigSyncPeriod"), metav1.Duration{Duration: -1 * time.Second}, "must be greater than 0")}, }, - "IPVS mode selected without providing required SyncPeriod": { - mutateConfigFunc: func(config *kubeproxyconfig.KubeProxyConfiguration) { - config.Mode = kubeproxyconfig.ProxyModeIPVS - }, - expectedErrs: field.ErrorList{field.Invalid(newPath.Child("KubeProxyIPVSConfiguration.SyncPeriod"), metav1.Duration{Duration: 0}, "must be greater than 0")}, - }, "interfacePrefix is empty": { mutateConfigFunc: func(config *kubeproxyconfig.KubeProxyConfiguration) { config.DetectLocalMode = kubeproxyconfig.LocalModeInterfaceNamePrefix @@ -193,7 +187,13 @@ func TestValidateKubeProxyConfiguration(t *testing.T) { }, expectedErrs: field.ErrorList{field.Invalid(newPath.Child("logging.format"), "unsupported format", "Unsupported log format")}, }, - } { + } + + for name, testCase := range osKubeProxyConfigTestCases { + testCases[name] = testCase + } + + for name, testCase := range testCases { t.Run(name, func(t *testing.T) { config := baseConfig.DeepCopy() testCase.mutateConfigFunc(config) diff --git a/pkg/proxy/apis/config/validation/validation_windows_test.go b/pkg/proxy/apis/config/validation/validation_windows_test.go new file mode 100644 index 00000000000..49e1eb2889c --- /dev/null +++ b/pkg/proxy/apis/config/validation/validation_windows_test.go @@ -0,0 +1,32 @@ +//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 validation + +import ( + "k8s.io/apimachinery/pkg/util/validation/field" + kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" +) + +var ( + osKubeProxyConfigTestCases = map[string]struct { + mutateConfigFunc func(*kubeproxyconfig.KubeProxyConfiguration) + expectedErrs field.ErrorList + }{} +)