Skip to content

Commit

Permalink
Merge pull request #1307 from sykim-etri/azure-pmks-implement-upgrade…
Browse files Browse the repository at this point in the history
…-nodegroups-when-upgrading-a-cluster

[azure:pmks] upgrade nodegroups when upgrading a cluster
  • Loading branch information
powerkimhub authored Aug 28, 2024
2 parents efc7b8f + d08d9f1 commit 76d963e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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
Expand Down Expand Up @@ -88,6 +89,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
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 76d963e

Please sign in to comment.