sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/machine_deployment.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/aws/aws-sdk-go/aws/client" 26 . "github.com/onsi/gomega" 27 corev1 "k8s.io/api/core/v1" 28 "k8s.io/utils/pointer" 29 30 "sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared" 31 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 32 "sigs.k8s.io/cluster-api/test/framework" 33 "sigs.k8s.io/cluster-api/test/framework/clusterctl" 34 ) 35 36 // MachineDeploymentSpecInput is the input for MachineDeploymentSpec. 37 type MachineDeploymentSpecInput struct { 38 E2EConfig *clusterctl.E2EConfig 39 ConfigClusterFn DefaultConfigClusterFn 40 BootstrapClusterProxy framework.ClusterProxy 41 AWSSession client.ConfigProvider 42 Namespace *corev1.Namespace 43 Replicas int64 44 ClusterName string 45 Cleanup bool 46 } 47 48 // MachineDeploymentSpec implements a test for creating a machine deployment for use with CAPA. 49 func MachineDeploymentSpec(ctx context.Context, inputGetter func() MachineDeploymentSpecInput) { 50 input := inputGetter() 51 Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil") 52 Expect(input.ConfigClusterFn).ToNot(BeNil(), "Invalid argument. input.ConfigClusterFn can't be nil") 53 Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil") 54 Expect(input.AWSSession).ToNot(BeNil(), "Invalid argument. input.AWSSession can't be nil") 55 Expect(input.Namespace).NotTo(BeNil(), "Invalid argument. input.Namespace can't be nil") 56 Expect(input.ClusterName).ShouldNot(HaveLen(0), "Invalid argument. input.ClusterName can't be empty") 57 58 shared.Byf("getting cluster with name %s", input.ClusterName) 59 cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{ 60 Getter: input.BootstrapClusterProxy.GetClient(), 61 Namespace: input.Namespace.Name, 62 Name: input.ClusterName, 63 }) 64 Expect(cluster).NotTo(BeNil(), "couldn't find CAPI cluster") 65 66 shared.Byf("creating an applying the %s template", EKSMachineDeployOnlyFlavor) 67 configCluster := input.ConfigClusterFn(input.ClusterName, input.Namespace.Name) 68 configCluster.Flavor = EKSMachineDeployOnlyFlavor 69 configCluster.WorkerMachineCount = pointer.Int64Ptr(input.Replicas) 70 err := shared.ApplyTemplate(ctx, configCluster, input.BootstrapClusterProxy) 71 Expect(err).ShouldNot(HaveOccurred()) 72 73 shared.Byf("Waiting for the worker node to be running") 74 md := framework.DiscoveryAndWaitForMachineDeployments(ctx, framework.DiscoveryAndWaitForMachineDeploymentsInput{ 75 Lister: input.BootstrapClusterProxy.GetClient(), 76 Cluster: cluster, 77 }, input.E2EConfig.GetIntervals("", "wait-worker-nodes")...) 78 79 workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{ 80 Lister: input.BootstrapClusterProxy.GetClient(), 81 ClusterName: input.ClusterName, 82 Namespace: input.Namespace.Name, 83 MachineDeployment: *md[0], 84 }) 85 86 Expect(len(workerMachines)).To(Equal(1)) 87 88 statusChecks := []framework.MachineStatusCheck{framework.MachinePhaseCheck(string(clusterv1.MachinePhaseRunning))} 89 machineStatusInput := framework.WaitForMachineStatusCheckInput{ 90 Getter: input.BootstrapClusterProxy.GetClient(), 91 Machine: &workerMachines[0], 92 StatusChecks: statusChecks, 93 } 94 framework.WaitForMachineStatusCheck(ctx, machineStatusInput, input.E2EConfig.GetIntervals("", "wait-machine-status")...) 95 96 if input.Cleanup { 97 deleteMachineDeployment(ctx, deleteMachineDeploymentInput{ 98 Deleter: input.BootstrapClusterProxy.GetClient(), 99 MachineDeployment: md[0], 100 }) 101 // deleteMachine(ctx, deleteMachineInput{ 102 // Deleter: input.BootstrapClusterProxy.GetClient(), 103 // Machine: &workerMachines[0], 104 // }) 105 106 waitForMachineDeploymentDeleted(ctx, waitForMachineDeploymentDeletedInput{ 107 Getter: input.BootstrapClusterProxy.GetClient(), 108 MachineDeployment: md[0], 109 }, input.E2EConfig.GetIntervals("", "wait-delete-machine-deployment")...) 110 111 waitForMachineDeleted(ctx, waitForMachineDeletedInput{ 112 Getter: input.BootstrapClusterProxy.GetClient(), 113 Machine: &workerMachines[0], 114 }, input.E2EConfig.GetIntervals("", "wait-delete-machine")...) 115 } 116 }