sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/machine_pool.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/ginkgo"
    27  	. "github.com/onsi/gomega"
    28  	corev1 "k8s.io/api/core/v1"
    29  	"k8s.io/utils/pointer"
    30  
    31  	"sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared"
    32  	"sigs.k8s.io/cluster-api/test/framework"
    33  	"sigs.k8s.io/cluster-api/test/framework/clusterctl"
    34  )
    35  
    36  // ManagedMachinePoolSpecInput is the input for ManagedMachinePoolSpec.
    37  type ManagedMachinePoolSpecInput struct {
    38  	E2EConfig             *clusterctl.E2EConfig
    39  	ConfigClusterFn       DefaultConfigClusterFn
    40  	BootstrapClusterProxy framework.ClusterProxy
    41  	AWSSession            client.ConfigProvider
    42  	Namespace             *corev1.Namespace
    43  	ClusterName           string
    44  	IncludeScaling        bool
    45  	Cleanup               bool
    46  }
    47  
    48  // ManagedMachinePoolSpec implements a test for creating a managed machine pool.
    49  func ManagedMachinePoolSpec(ctx context.Context, inputGetter func() ManagedMachinePoolSpecInput) {
    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", EKSManagedPoolOnlyFlavor)
    67  	configCluster := input.ConfigClusterFn(input.ClusterName, input.Namespace.Name)
    68  	configCluster.Flavor = EKSManagedPoolOnlyFlavor
    69  	configCluster.WorkerMachineCount = pointer.Int64Ptr(1)
    70  	err := shared.ApplyTemplate(ctx, configCluster, input.BootstrapClusterProxy)
    71  	Expect(err).ShouldNot(HaveOccurred())
    72  
    73  	shared.Byf("Waiting for the machine pool to be running")
    74  	mp := framework.DiscoveryAndWaitForMachinePools(ctx, framework.DiscoveryAndWaitForMachinePoolsInput{
    75  		Lister:  input.BootstrapClusterProxy.GetClient(),
    76  		Getter:  input.BootstrapClusterProxy.GetClient(),
    77  		Cluster: cluster,
    78  	}, input.E2EConfig.GetIntervals("", "wait-worker-nodes")...)
    79  	Expect(len(mp)).To(Equal(1))
    80  
    81  	shared.Byf("Check the status of the node group")
    82  	nodeGroupName := getEKSNodegroupName(input.Namespace.Name, input.ClusterName)
    83  	eksClusterName := getEKSClusterName(input.Namespace.Name, input.ClusterName)
    84  	verifyManagedNodeGroup(eksClusterName, nodeGroupName, true, input.AWSSession)
    85  
    86  	if input.IncludeScaling { // TODO (richardcase): should this be a separate spec?
    87  		ginkgo.By("Scaling the machine pool up")
    88  		framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
    89  			ClusterProxy:              input.BootstrapClusterProxy,
    90  			Cluster:                   cluster,
    91  			Replicas:                  2,
    92  			MachinePools:              mp,
    93  			WaitForMachinePoolToScale: input.E2EConfig.GetIntervals("", "wait-worker-nodes"),
    94  		})
    95  
    96  		ginkgo.By("Scaling the machine pool down")
    97  		framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
    98  			ClusterProxy:              input.BootstrapClusterProxy,
    99  			Cluster:                   cluster,
   100  			Replicas:                  1,
   101  			MachinePools:              mp,
   102  			WaitForMachinePoolToScale: input.E2EConfig.GetIntervals("", "wait-worker-nodes"),
   103  		})
   104  	}
   105  
   106  	if input.Cleanup {
   107  		deleteMachinePool(ctx, deleteMachinePoolInput{
   108  			Deleter:     input.BootstrapClusterProxy.GetClient(),
   109  			MachinePool: mp[0],
   110  		})
   111  
   112  		waitForMachinePoolDeleted(ctx, waitForMachinePoolDeletedInput{
   113  			Getter:      input.BootstrapClusterProxy.GetClient(),
   114  			MachinePool: mp[0],
   115  		}, input.E2EConfig.GetIntervals("", "wait-delete-machine-pool")...)
   116  	}
   117  }