sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/addon_helpers.go (about)

     1  //go:build e2e
     2  // +build e2e
     3  
     4  /*
     5  Copyright 2021 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  	"fmt"
    24  
    25  	"github.com/aws/aws-sdk-go/aws/client"
    26  	"github.com/onsi/ginkgo"
    27  	. "github.com/onsi/gomega"
    28  
    29  	ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1"
    30  )
    31  
    32  type waitForEKSAddonToHaveStatusInput struct {
    33  	ControlPlane *ekscontrolplanev1.AWSManagedControlPlane
    34  	AWSSession   client.ConfigProvider
    35  	AddonName    string
    36  	AddonVersion string
    37  	AddonStatus  []string
    38  }
    39  
    40  func waitForEKSAddonToHaveStatus(input waitForEKSAddonToHaveStatusInput, intervals ...interface{}) {
    41  	Expect(input.ControlPlane).ToNot(BeNil(), "Invalid argument. input.ControlPlane can't be nil")
    42  	Expect(input.AWSSession).ToNot(BeNil(), "Invalid argument. input.AWSSession can't be nil")
    43  	Expect(input.AddonName).ShouldNot(HaveLen(0), "Invalid argument. input.AddonName can't be empty")
    44  	Expect(input.AddonVersion).ShouldNot(HaveLen(0), "Invalid argument. input.AddonVersion can't be empty")
    45  	Expect(input.AddonStatus).ShouldNot(HaveLen(0), "Invalid argument. input.AddonStatus can't be empty")
    46  
    47  	ginkgo.By(fmt.Sprintf("Ensuring EKS addon %s has status in %q for EKS cluster %s", input.AddonName, input.AddonStatus, input.ControlPlane.Spec.EKSClusterName))
    48  
    49  	Eventually(func() (bool, error) {
    50  		installedAddon, err := getEKSClusterAddon(input.ControlPlane.Spec.EKSClusterName, input.AddonName, input.AWSSession)
    51  		if err != nil {
    52  			return false, err
    53  		}
    54  
    55  		if installedAddon == nil {
    56  			return false, err
    57  		}
    58  
    59  		for i := range input.AddonStatus {
    60  			wantedStatus := input.AddonStatus[i]
    61  
    62  			if wantedStatus == *installedAddon.Status {
    63  				return true, nil
    64  			}
    65  		}
    66  
    67  		return false, nil
    68  	}, intervals...).Should(BeTrue())
    69  }