Skip to content

Commit

Permalink
Merge pull request #5321 from fabriziopandini/clusterctl-enforce-prov…
Browse files Browse the repository at this point in the history
…ider-order

🐛 Clusterctl enforce provider order during init and upgrade
  • Loading branch information
k8s-ci-robot committed Sep 24, 2021
2 parents 3702644 + 1e170f6 commit 2d07978
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/clusterctl/client/cluster/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cluster

import (
"context"
"sort"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -76,6 +77,11 @@ var _ ProviderInstaller = &providerInstaller{}

func (i *providerInstaller) Add(components repository.Components) {
i.installQueue = append(i.installQueue, components)

// Ensure Providers are installed in the following order: Core, Bootstrap, ControlPlane, Infrastructure.
sort.Slice(i.installQueue, func(a, b int) bool {
return i.installQueue[a].Type().Order() < i.installQueue[b].Type().Order()
})
}

func (i *providerInstaller) Install(opts InstallOptions) ([]repository.Components, error) {
Expand Down
10 changes: 9 additions & 1 deletion cmd/clusterctl/client/cluster/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package cluster

import (
"sort"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/version"
Expand Down Expand Up @@ -344,7 +346,13 @@ func (u *providerUpgrader) doUpgrade(upgradePlan *UpgradePlan) error {
}
}

for _, upgradeItem := range upgradePlan.Providers {
// Ensure Providers are updated in the following order: Core, Bootstrap, ControlPlane, Infrastructure.
providers := upgradePlan.Providers
sort.Slice(providers, func(a, b int) bool {
return providers[a].GetProviderType().Order() < providers[b].GetProviderType().Order()
})

for _, upgradeItem := range providers {
// If there is not a specified next version, skip it (we are already up-to-date).
if upgradeItem.NextVersion == "" {
continue
Expand Down

0 comments on commit 2d07978

Please sign in to comment.