diff --git a/cloud-control-manager/cloud-driver/drivers/azure/resources/ClusterHandler.go b/cloud-control-manager/cloud-driver/drivers/azure/resources/ClusterHandler.go index 634f9d310..60ed3b2e6 100644 --- a/cloud-control-manager/cloud-driver/drivers/azure/resources/ClusterHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/azure/resources/ClusterHandler.go @@ -5,9 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v6" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" "io" "math" "net" @@ -20,6 +17,11 @@ import ( "sync" "time" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v6" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" + "github.com/Azure/go-autorest/autorest/to" + call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log" idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources" @@ -453,14 +455,51 @@ func upgradeCluter(cluster *armcontainerservice.ManagedCluster, newVersion strin } updateCluster := cluster updateCluster.Properties.KubernetesVersion = &newVersion - _, err = managedClustersClient.BeginCreateOrUpdate(ctx, region.Region, *cluster.Name, *updateCluster, nil) + updateClusterPoller, err := managedClustersClient.BeginCreateOrUpdate(ctx, region.Region, to.String(cluster.Name), *updateCluster, nil) if err != nil { return err } - //err = upgradeResult.WaitForCompletionRef(ctx, managedClustersClient.Client) - //if err != nil { - // return err - //} + _, err = updateClusterPoller.PollUntilDone(ctx, nil) + if err != nil { + return err + } + + clusterResourceGroup, err := getResourceGroupById(to.String(cluster.ID)) + if err != nil { + return err + } + + var agentPoolList []*armcontainerservice.AgentPool + + pager := agentPoolsClient.NewListPager(clusterResourceGroup, to.String(cluster.Name), nil) + + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + return err + } + + for _, agentPool := range page.Value { + agentPoolList = append(agentPoolList, agentPool) + } + } + + var errs []error + for _, agentPool := range agentPoolList { + updateAgentPool := agentPool + updateAgentPool.Properties = &armcontainerservice.ManagedClusterAgentPoolProfileProperties{ + OrchestratorVersion: to.StringPtr(newVersion), + } + _, err := agentPoolsClient.BeginCreateOrUpdate(ctx, region.Region, to.String(cluster.Name), to.String(agentPool.Name), *updateAgentPool, nil) + if err != nil { + errs = append(errs, err) + } + } + + if len(errs) > 0 { + return errors.Join(errs...) + } + return nil } diff --git a/go.mod b/go.mod index b6b1e8577..0edb3992e 100644 --- a/go.mod +++ b/go.mod @@ -62,6 +62,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 v6.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.2.0 + github.com/Azure/go-autorest/autorest/to v0.4.0 github.com/IBM/platform-services-go-sdk v0.30.0 github.com/Masterminds/semver/v3 v3.2.1 github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.13 @@ -89,6 +90,7 @@ require ( require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect + github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect github.com/alibabacloud-go/debug v1.0.0 // indirect diff --git a/go.sum b/go.sum index ef0bb516a..185606f28 100644 --- a/go.sum +++ b/go.sum @@ -69,11 +69,14 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscripti github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.2.0/go.mod h1:qskvSQeW+cxEE2bcKYyKimB1/KiQ9xpJ99bcHY0BX6c= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.11.18/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA= github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= +github.com/Azure/go-autorest/autorest/to v0.4.0 h1:oXVqrxakqqV1UZdSazDOPOLvOIz+XA683u8EctwboHk= +github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcPR4o9jEImooCeWJcYV/zLE= github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU=