Skip to content

Commit 2d07978

Browse files
authored
Merge pull request #5321 from fabriziopandini/clusterctl-enforce-provider-order
🐛 Clusterctl enforce provider order during init and upgrade
2 parents 3702644 + 1e170f6 commit 2d07978

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cmd/clusterctl/client/cluster/installer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cluster
1818

1919
import (
2020
"context"
21+
"sort"
2122
"time"
2223

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

7778
func (i *providerInstaller) Add(components repository.Components) {
7879
i.installQueue = append(i.installQueue, components)
80+
81+
// Ensure Providers are installed in the following order: Core, Bootstrap, ControlPlane, Infrastructure.
82+
sort.Slice(i.installQueue, func(a, b int) bool {
83+
return i.installQueue[a].Type().Order() < i.installQueue[b].Type().Order()
84+
})
7985
}
8086

8187
func (i *providerInstaller) Install(opts InstallOptions) ([]repository.Components, error) {

cmd/clusterctl/client/cluster/upgrader.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package cluster
1818

1919
import (
20+
"sort"
21+
2022
"github.com/pkg/errors"
2123
"k8s.io/apimachinery/pkg/util/sets"
2224
"k8s.io/apimachinery/pkg/util/version"
@@ -344,7 +346,13 @@ func (u *providerUpgrader) doUpgrade(upgradePlan *UpgradePlan) error {
344346
}
345347
}
346348

347-
for _, upgradeItem := range upgradePlan.Providers {
349+
// Ensure Providers are updated in the following order: Core, Bootstrap, ControlPlane, Infrastructure.
350+
providers := upgradePlan.Providers
351+
sort.Slice(providers, func(a, b int) bool {
352+
return providers[a].GetProviderType().Order() < providers[b].GetProviderType().Order()
353+
})
354+
355+
for _, upgradeItem := range providers {
348356
// If there is not a specified next version, skip it (we are already up-to-date).
349357
if upgradeItem.NextVersion == "" {
350358
continue

0 commit comments

Comments
 (0)