sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/control_plane_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  	"fmt"
    25  
    26  	"github.com/aws/aws-sdk-go/aws/client"
    27  	"github.com/aws/aws-sdk-go/service/eks"
    28  	. "github.com/onsi/ginkgo"
    29  	. "github.com/onsi/gomega"
    30  	"k8s.io/apimachinery/pkg/util/version"
    31  	crclient "sigs.k8s.io/controller-runtime/pkg/client"
    32  
    33  	ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1"
    34  	"sigs.k8s.io/cluster-api/test/framework"
    35  )
    36  
    37  type waitForControlPlaneToBeUpgradedInput struct {
    38  	ControlPlane   *ekscontrolplanev1.AWSManagedControlPlane
    39  	AWSSession     client.ConfigProvider
    40  	UpgradeVersion string
    41  }
    42  
    43  func waitForControlPlaneToBeUpgraded(input waitForControlPlaneToBeUpgradedInput, intervals ...interface{}) {
    44  	Expect(input.ControlPlane).ToNot(BeNil(), "Invalid argument. input.ControlPlane can't be nil")
    45  	Expect(input.AWSSession).ToNot(BeNil(), "Invalid argument. input.AWSSession can't be nil")
    46  	Expect(input.UpgradeVersion).ToNot(BeNil(), "Invalid argument. input.UpgradeVersion can't be nil")
    47  
    48  	By(fmt.Sprintf("Ensuring EKS control-plane has been upgraded to kubernetes version %s", input.UpgradeVersion))
    49  	v, err := version.ParseGeneric(input.UpgradeVersion)
    50  	Expect(err).NotTo(HaveOccurred())
    51  	expectedVersion := fmt.Sprintf("%d.%d", v.Major(), v.Minor())
    52  
    53  	Eventually(func() (bool, error) {
    54  		cluster, err := getEKSCluster(input.ControlPlane.Spec.EKSClusterName, input.AWSSession)
    55  		if err != nil {
    56  			return false, err
    57  		}
    58  
    59  		switch *cluster.Status {
    60  		case eks.ClusterStatusUpdating:
    61  			return false, nil
    62  		case eks.ClusterStatusActive:
    63  			if *cluster.Version == expectedVersion {
    64  				return true, nil
    65  			}
    66  			return false, nil
    67  		default:
    68  			return false, nil
    69  		}
    70  	}, intervals...).Should(BeTrue())
    71  }
    72  
    73  type GetControlPlaneByNameInput struct {
    74  	Getter    framework.Getter
    75  	Name      string
    76  	Namespace string
    77  }
    78  
    79  func GetControlPlaneByName(ctx context.Context, input GetControlPlaneByNameInput) *ekscontrolplanev1.AWSManagedControlPlane {
    80  	cp := &ekscontrolplanev1.AWSManagedControlPlane{}
    81  	key := crclient.ObjectKey{
    82  		Name:      input.Name,
    83  		Namespace: input.Namespace,
    84  	}
    85  	Expect(input.Getter.Get(ctx, key, cp)).To(Succeed(), "Failed to get AWSManagedControlPlane object %s/%s", input.Namespace, input.Name)
    86  	return cp
    87  }