k8s.io/kubernetes@v1.29.3/test/e2e/framework/kubesystem/kubesystem.go (about) 1 /* 2 Copyright 2020 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 kubesystem 18 19 import ( 20 "context" 21 "fmt" 22 "net" 23 "strconv" 24 "time" 25 26 "k8s.io/kubernetes/test/e2e/framework" 27 e2essh "k8s.io/kubernetes/test/e2e/framework/ssh" 28 ) 29 30 // RestartControllerManager restarts the kube-controller-manager. 31 func RestartControllerManager(ctx context.Context) error { 32 // TODO: Make it work for all providers and distros. 33 if !framework.ProviderIs("gce", "aws") { 34 return fmt.Errorf("unsupported provider for RestartControllerManager: %s", framework.TestContext.Provider) 35 } 36 if framework.ProviderIs("gce") && !framework.MasterOSDistroIs("gci") { 37 return fmt.Errorf("unsupported master OS distro: %s", framework.TestContext.MasterOSDistro) 38 } 39 cmd := "pidof kube-controller-manager | xargs sudo kill" 40 framework.Logf("Restarting controller-manager via ssh, running: %v", cmd) 41 result, err := e2essh.SSH(ctx, cmd, net.JoinHostPort(framework.APIAddress(), e2essh.SSHPort), framework.TestContext.Provider) 42 if err != nil || result.Code != 0 { 43 e2essh.LogResult(result) 44 return fmt.Errorf("couldn't restart controller-manager: %w", err) 45 } 46 return nil 47 } 48 49 // WaitForControllerManagerUp waits for the kube-controller-manager to be up. 50 func WaitForControllerManagerUp(ctx context.Context) error { 51 cmd := "curl -k https://localhost:" + strconv.Itoa(framework.KubeControllerManagerPort) + "/healthz" 52 for start := time.Now(); time.Since(start) < time.Minute && ctx.Err() == nil; time.Sleep(5 * time.Second) { 53 result, err := e2essh.SSH(ctx, cmd, net.JoinHostPort(framework.APIAddress(), e2essh.SSHPort), framework.TestContext.Provider) 54 if err != nil || result.Code != 0 { 55 e2essh.LogResult(result) 56 } 57 if result.Stdout == "ok" { 58 return nil 59 } 60 } 61 return fmt.Errorf("waiting for controller-manager timed out") 62 }