sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/addon.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  	"context"
    24  
    25  	"github.com/aws/aws-sdk-go/aws/client"
    26  	"github.com/aws/aws-sdk-go/service/eks"
    27  	. "github.com/onsi/gomega"
    28  	corev1 "k8s.io/api/core/v1"
    29  	crclient "sigs.k8s.io/controller-runtime/pkg/client"
    30  
    31  	ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1"
    32  	"sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared"
    33  	"sigs.k8s.io/cluster-api/test/framework"
    34  	"sigs.k8s.io/cluster-api/test/framework/clusterctl"
    35  )
    36  
    37  type CheckAddonExistsSpecInput struct {
    38  	E2EConfig             *clusterctl.E2EConfig
    39  	BootstrapClusterProxy framework.ClusterProxy
    40  	AWSSession            client.ConfigProvider
    41  	Namespace             *corev1.Namespace
    42  	ClusterName           string
    43  	AddonName             string
    44  	AddonVersion          string
    45  }
    46  
    47  // CheckAddonExistsSpec implements a test for a cluster having an addon.
    48  func CheckAddonExistsSpec(ctx context.Context, inputGetter func() CheckAddonExistsSpecInput) {
    49  	input := inputGetter()
    50  	Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil")
    51  	Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil")
    52  	Expect(input.AWSSession).ToNot(BeNil(), "Invalid argument. input.AWSSession can't be nil")
    53  	Expect(input.Namespace).NotTo(BeNil(), "Invalid argument. input.Namespace can't be nil")
    54  	Expect(input.ClusterName).ShouldNot(HaveLen(0), "Invalid argument. input.ClusterName can't be empty")
    55  	Expect(input.AddonName).ShouldNot(HaveLen(0), "Invalid argument. input.AddonName can't be empty")
    56  	Expect(input.AddonVersion).ShouldNot(HaveLen(0), "Invalid argument. input.AddonVersion can't be empty")
    57  
    58  	mgmtClient := input.BootstrapClusterProxy.GetClient()
    59  	controlPlaneName := getControlPlaneName(input.ClusterName)
    60  
    61  	shared.Byf("Getting control plane: %s", controlPlaneName)
    62  	controlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
    63  	err := mgmtClient.Get(ctx, crclient.ObjectKey{Namespace: input.Namespace.Name, Name: controlPlaneName}, controlPlane)
    64  	Expect(err).ToNot(HaveOccurred())
    65  
    66  	shared.Byf("Checking EKS addon %s is installed on cluster %s and is active", input.AddonName, input.ClusterName)
    67  	waitForEKSAddonToHaveStatus(waitForEKSAddonToHaveStatusInput{
    68  		ControlPlane: controlPlane,
    69  		AWSSession:   input.AWSSession,
    70  		AddonName:    input.AddonName,
    71  		AddonVersion: input.AddonVersion,
    72  		AddonStatus:  []string{eks.AddonStatusActive, eks.AddonStatusDegraded},
    73  	}, input.E2EConfig.GetIntervals("", "wait-addon-status")...)
    74  }