k8s.io/kubernetes@v1.29.3/test/e2e/windows/utils.go (about) 1 /* 2 Copyright 2019 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 windows 18 19 import ( 20 "context" 21 "fmt" 22 "math/rand" 23 "strings" 24 "time" 25 26 "github.com/onsi/ginkgo/v2" 27 appsv1 "k8s.io/api/apps/v1" 28 v1 "k8s.io/api/core/v1" 29 apierrors "k8s.io/apimachinery/pkg/api/errors" 30 "k8s.io/apimachinery/pkg/util/wait" 31 "k8s.io/kubernetes/pkg/controller/deployment/util" 32 "k8s.io/kubernetes/test/e2e/framework" 33 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" 34 35 semver "github.com/blang/semver/v4" 36 ) 37 38 // waits for a deployment to be created and the desired replicas 39 // are updated and available, and no old pods are running. 40 func waitForDeployment(getDeploymentFunc func() (*appsv1.Deployment, error), interval, timeout time.Duration) error { 41 return wait.PollImmediate(interval, timeout, func() (bool, error) { 42 deployment, err := getDeploymentFunc() 43 if err != nil { 44 if apierrors.IsNotFound(err) { 45 framework.Logf("deployment not found, continue waiting: %s", err) 46 return false, nil 47 } 48 49 framework.Logf("error while deploying, error %s", err) 50 return false, err 51 } 52 framework.Logf("deployment status %s", &deployment.Status) 53 return util.DeploymentComplete(deployment, &deployment.Status), nil 54 }) 55 } 56 57 // gets the container runtime and version for a node 58 func getNodeContainerRuntimeAndVersion(n v1.Node) (string, semver.Version, error) { 59 containerRuntimeVersionString := n.Status.NodeInfo.DeepCopy().ContainerRuntimeVersion 60 parts := strings.Split(containerRuntimeVersionString, "://") 61 62 if len(parts) != 2 { 63 return "", semver.Version{}, fmt.Errorf("could not get container runtime and version from '%s'", containerRuntimeVersionString) 64 } 65 66 v, err := semver.ParseTolerant(parts[1]) 67 if err != nil { 68 return "", semver.Version{}, err 69 } 70 71 return parts[0], v, nil 72 } 73 74 func getRandomUserGrounName() string { 75 var letters = []rune("abcdefghijklmnopqrstuvwxya") 76 77 s := make([]rune, 8) 78 for i := range s { 79 s[i] = letters[rand.Intn(len(letters))] 80 } 81 82 return "hpc-" + string(s) 83 } 84 85 func skipUnlessContainerdOneSevenOrGreater(ctx context.Context, f *framework.Framework) { 86 ginkgo.By("Ensuring Windows nodes are running containerd v1.7+") 87 windowsNode, err := findWindowsNode(ctx, f) 88 framework.ExpectNoError(err, "error finding Windows node") 89 r, v, err := getNodeContainerRuntimeAndVersion(windowsNode) 90 framework.ExpectNoError(err, "error getting node container runtime and version") 91 framework.Logf("Got runtime: %s, version %v for node %s", r, v, windowsNode.Name) 92 93 if !strings.EqualFold(r, "containerd") { 94 e2eskipper.Skipf("container runtime is not containerd") 95 } 96 97 v1dot7 := semver.MustParse("1.7.0-alpha.1") 98 if v.LT(v1dot7) { 99 e2eskipper.Skipf("container runtime is < 1.7.0") 100 } 101 }