sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/machine_deployment_helpers.go (about) 1 //go:build e2e 2 // +build e2e 3 4 /* 5 Copyright 2020 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 managed 21 22 import ( 23 "context" 24 25 . "github.com/onsi/gomega" 26 apierrors "k8s.io/apimachinery/pkg/api/errors" 27 "sigs.k8s.io/controller-runtime/pkg/client" 28 29 "sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared" 30 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 31 "sigs.k8s.io/cluster-api/test/framework" 32 ) 33 34 type deleteMachineDeploymentInput struct { 35 MachineDeployment *clusterv1.MachineDeployment 36 Deleter framework.Deleter 37 } 38 39 func deleteMachineDeployment(ctx context.Context, input deleteMachineDeploymentInput) { 40 shared.Byf("Deleting machine deployment %s", input.MachineDeployment.Name) 41 Expect(input.Deleter.Delete(ctx, input.MachineDeployment)).To(Succeed()) 42 } 43 44 type waitForMachineDeploymentDeletedInput struct { 45 MachineDeployment *clusterv1.MachineDeployment 46 Getter framework.Getter 47 } 48 49 func waitForMachineDeploymentDeleted(ctx context.Context, input waitForMachineDeploymentDeletedInput, intervals ...interface{}) { 50 shared.Byf("Waiting for machine deployment %s to be deleted", input.MachineDeployment.GetName()) 51 Eventually(func() bool { 52 mp := &clusterv1.MachineDeployment{} 53 key := client.ObjectKey{ 54 Namespace: input.MachineDeployment.GetNamespace(), 55 Name: input.MachineDeployment.GetName(), 56 } 57 err := input.Getter.Get(ctx, key, mp) 58 notFound := apierrors.IsNotFound(err) 59 return notFound 60 }, intervals...).Should(BeTrue()) 61 } 62 63 type waitForMachineDeletedInput struct { 64 Machine *clusterv1.Machine 65 Getter framework.Getter 66 } 67 68 func waitForMachineDeleted(ctx context.Context, input waitForMachineDeletedInput, intervals ...interface{}) { 69 shared.Byf("Waiting for machine %s to be deleted", input.Machine.GetName()) 70 Eventually(func() bool { 71 mp := &clusterv1.Machine{} 72 key := client.ObjectKey{ 73 Namespace: input.Machine.GetNamespace(), 74 Name: input.Machine.GetName(), 75 } 76 err := input.Getter.Get(ctx, key, mp) 77 notFound := apierrors.IsNotFound(err) 78 return notFound 79 }, intervals...).Should(BeTrue()) 80 }