sigs.k8s.io/cluster-api-provider-azure@v1.14.3/test/e2e/daemonsets.go (about) 1 //go:build e2e 2 // +build e2e 3 4 /* 5 Copyright 2022 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package e2e 21 22 import ( 23 "context" 24 25 . "github.com/onsi/ginkgo/v2" 26 . "github.com/onsi/gomega" 27 corev1 "k8s.io/api/core/v1" 28 kubeadmv1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" 29 "sigs.k8s.io/cluster-api/test/framework" 30 "sigs.k8s.io/controller-runtime/pkg/client" 31 ) 32 33 // DaemonsetsSpecInput is the input for EnsureDaemonsets. 34 type DaemonsetsSpecInput struct { 35 BootstrapClusterProxy framework.ClusterProxy 36 Namespace *corev1.Namespace 37 ClusterName string 38 } 39 40 // EnsureDaemonsets implements a test that verifies expected Daemonset Pods are running. 41 func EnsureDaemonsets(ctx context.Context, inputGetter func() DaemonsetsSpecInput) { 42 var ( 43 specName = "daemonsets" 44 input DaemonsetsSpecInput 45 ) 46 47 Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName) 48 49 input = inputGetter() 50 Expect(input.BootstrapClusterProxy).NotTo(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName) 51 Expect(input.Namespace).NotTo(BeNil(), "Invalid argument. input.Namespace can't be nil when calling %s spec", specName) 52 Expect(input.ClusterName).NotTo(BeEmpty(), "Invalid argument. input.ClusterName can't be empty when calling %s spec", specName) 53 54 mgmtClient := bootstrapClusterProxy.GetClient() 55 Expect(mgmtClient).NotTo(BeNil()) 56 cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{ 57 Getter: mgmtClient, 58 Name: input.ClusterName, 59 Namespace: input.Namespace.Name, 60 }) 61 kubeadmControlPlane := &kubeadmv1.KubeadmControlPlane{} 62 key := client.ObjectKey{ 63 Namespace: cluster.Spec.ControlPlaneRef.Namespace, 64 Name: cluster.Spec.ControlPlaneRef.Name, 65 } 66 Eventually(func() error { 67 return mgmtClient.Get(ctx, key, kubeadmControlPlane) 68 }, e2eConfig.GetIntervals(specName, "wait-daemonset")...).Should(Succeed(), "Failed to get KubeadmControlPlane object %s/%s", cluster.Spec.ControlPlaneRef.Namespace, cluster.Spec.ControlPlaneRef.Name) 69 70 workloadClusterProxy := input.BootstrapClusterProxy.GetWorkloadCluster(ctx, input.Namespace.Name, input.ClusterName) 71 By("Waiting for all DaemonSet Pods to be Running") 72 WaitForDaemonsets(ctx, workloadClusterProxy, specName, e2eConfig.GetIntervals(specName, "wait-daemonset")...) 73 }