k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kubeadm/app/util/apiclient/wait_test.go (about) 1 /* 2 Copyright 2024 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package apiclient 18 19 import ( 20 "reflect" 21 "testing" 22 23 kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" 24 ) 25 26 func TestGetControlPlaneComponents(t *testing.T) { 27 testcases := []struct { 28 name string 29 cfg *kubeadmapi.ClusterConfiguration 30 expected []controlPlaneComponent 31 }{ 32 { 33 name: "port values from config", 34 cfg: &kubeadmapi.ClusterConfiguration{ 35 APIServer: kubeadmapi.APIServer{ 36 ControlPlaneComponent: kubeadmapi.ControlPlaneComponent{ 37 ExtraArgs: []kubeadmapi.Arg{ 38 {Name: "secure-port", Value: "1111"}, 39 }, 40 }, 41 }, 42 ControllerManager: kubeadmapi.ControlPlaneComponent{ 43 ExtraArgs: []kubeadmapi.Arg{ 44 {Name: "secure-port", Value: "2222"}, 45 }, 46 }, 47 Scheduler: kubeadmapi.ControlPlaneComponent{ 48 ExtraArgs: []kubeadmapi.Arg{ 49 {Name: "secure-port", Value: "3333"}, 50 }, 51 }, 52 }, 53 expected: []controlPlaneComponent{ 54 {name: "kube-apiserver", url: "https://127.0.0.1:1111/healthz"}, 55 {name: "kube-controller-manager", url: "https://127.0.0.1:2222/healthz"}, 56 {name: "kube-scheduler", url: "https://127.0.0.1:3333/healthz"}, 57 }, 58 }, 59 { 60 name: "default ports", 61 cfg: &kubeadmapi.ClusterConfiguration{}, 62 expected: []controlPlaneComponent{ 63 {name: "kube-apiserver", url: "https://127.0.0.1:6443/healthz"}, 64 {name: "kube-controller-manager", url: "https://127.0.0.1:10257/healthz"}, 65 {name: "kube-scheduler", url: "https://127.0.0.1:10259/healthz"}, 66 }, 67 }, 68 } 69 70 for _, tc := range testcases { 71 t.Run(tc.name, func(t *testing.T) { 72 actual := getControlPlaneComponents(tc.cfg) 73 if !reflect.DeepEqual(tc.expected, actual) { 74 t.Fatalf("expected result: %+v, got: %+v", tc.expected, actual) 75 } 76 }) 77 } 78 }