sigs.k8s.io/cluster-api-provider-azure@v1.14.3/test/e2e/aks_upgrade.go (about)

     1  //go:build e2e
     2  // +build e2e
     3  
     4  /*
     5  Copyright 2022 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 e2e
    21  
    22  import (
    23  	"context"
    24  
    25  	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    26  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
    27  	. "github.com/onsi/ginkgo/v2"
    28  	. "github.com/onsi/gomega"
    29  	"k8s.io/utils/ptr"
    30  	infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
    31  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    32  	expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
    33  	"sigs.k8s.io/cluster-api/test/framework"
    34  	"sigs.k8s.io/controller-runtime/pkg/client"
    35  )
    36  
    37  type AKSUpgradeSpecInput struct {
    38  	Cluster                    *clusterv1.Cluster
    39  	MachinePools               []*expv1.MachinePool
    40  	KubernetesVersionUpgradeTo string
    41  	WaitForControlPlane        []interface{}
    42  	WaitForMachinePools        []interface{}
    43  }
    44  
    45  func AKSUpgradeSpec(ctx context.Context, inputGetter func() AKSUpgradeSpecInput) {
    46  	input := inputGetter()
    47  
    48  	cred, err := azidentity.NewDefaultAzureCredential(nil)
    49  	Expect(err).NotTo(HaveOccurred())
    50  
    51  	managedClustersClient, err := armcontainerservice.NewManagedClustersClient(getSubscriptionID(Default), cred, nil)
    52  	Expect(err).NotTo(HaveOccurred())
    53  
    54  	mgmtClient := bootstrapClusterProxy.GetClient()
    55  	Expect(mgmtClient).NotTo(BeNil())
    56  
    57  	By("Upgrading the control plane")
    58  	var infraControlPlane = &infrav1.AzureManagedControlPlane{}
    59  	Eventually(func(g Gomega) {
    60  		err = mgmtClient.Get(ctx, client.ObjectKey{Namespace: input.Cluster.Spec.ControlPlaneRef.Namespace, Name: input.Cluster.Spec.ControlPlaneRef.Name}, infraControlPlane)
    61  		g.Expect(err).NotTo(HaveOccurred())
    62  		infraControlPlane.Spec.Version = input.KubernetesVersionUpgradeTo
    63  		g.Expect(mgmtClient.Update(ctx, infraControlPlane)).To(Succeed())
    64  	}, inputGetter().WaitForControlPlane...).Should(Succeed())
    65  
    66  	Eventually(func(g Gomega) {
    67  		resp, err := managedClustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, nil)
    68  		g.Expect(err).NotTo(HaveOccurred())
    69  		g.Expect(resp.Properties.ProvisioningState).To(Equal(ptr.To("Succeeded")))
    70  		aksCluster := resp.ManagedCluster
    71  		g.Expect(aksCluster.Properties).NotTo(BeNil())
    72  		g.Expect(aksCluster.Properties.KubernetesVersion).NotTo(BeNil())
    73  		g.Expect("v" + *aksCluster.Properties.KubernetesVersion).To(Equal(input.KubernetesVersionUpgradeTo))
    74  		g.Expect(aksCluster.Properties.ProvisioningState).To(Equal(ptr.To("Succeeded")))
    75  	}, input.WaitForControlPlane...).Should(Succeed())
    76  
    77  	By("Upgrading the machinepool instances")
    78  	framework.UpgradeMachinePoolAndWait(ctx, framework.UpgradeMachinePoolAndWaitInput{
    79  		ClusterProxy:                   bootstrapClusterProxy,
    80  		Cluster:                        input.Cluster,
    81  		UpgradeVersion:                 input.KubernetesVersionUpgradeTo,
    82  		WaitForMachinePoolToBeUpgraded: input.WaitForMachinePools,
    83  		MachinePools:                   input.MachinePools,
    84  	})
    85  }