sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/managed/control_plane.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 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 "sigs.k8s.io/cluster-api/util/patch" 36 ) 37 38 // UpgradeControlPlaneVersionSpecInput is the input type for UpgradeControlPlaneVersionSpec. 39 type UpgradeControlPlaneVersionSpecInput struct { 40 E2EConfig *clusterctl.E2EConfig 41 AWSSession client.ConfigProvider 42 BootstrapClusterProxy framework.ClusterProxy 43 ClusterName string 44 Namespace *corev1.Namespace 45 UpgradeVersion string 46 } 47 48 // UpgradeControlPlaneVersionSpec updates the EKS control plane version and waits for the upgrade. 49 func UpgradeControlPlaneVersionSpec(ctx context.Context, inputGetter func() UpgradeControlPlaneVersionSpecInput) { 50 input := inputGetter() 51 Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil") 52 Expect(input.AWSSession).ToNot(BeNil(), "Invalid argument. input.AWSSession can't be nil") 53 Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil") 54 Expect(input.ClusterName).ToNot(BeNil(), "Invalid argument. input.ClusterName can't be nil") 55 Expect(input.Namespace).ToNot(BeNil(), "Invalid argument. input.Namespace can't be nil") 56 Expect(input.UpgradeVersion).ToNot(BeNil(), "Invalid argument. input.UpgradeVersion can't be nil") 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("Patching control plane %s from %s to %s", controlPlaneName, *controlPlane.Spec.Version, input.UpgradeVersion) 67 patchHelper, err := patch.NewHelper(controlPlane, mgmtClient) 68 Expect(err).ToNot(HaveOccurred()) 69 controlPlane.Spec.Version = &input.UpgradeVersion 70 Expect(patchHelper.Patch(ctx, controlPlane)).To(Succeed()) 71 72 ginkgo.By("Waiting for EKS control-plane to be upgraded to new version") 73 waitForControlPlaneToBeUpgraded(waitForControlPlaneToBeUpgradedInput{ 74 ControlPlane: controlPlane, 75 AWSSession: input.AWSSession, 76 UpgradeVersion: input.UpgradeVersion, 77 }, input.E2EConfig.GetIntervals("", "wait-control-plane-upgrade")...) 78 }