From 1e170f60fbc94b05d1ed07fe1006c437c7f44c2c Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Fri, 24 Sep 2021 22:03:47 +0200 Subject: [PATCH] Clusterctl enforce provider order during init and upgrade --- cmd/clusterctl/client/cluster/installer.go | 6 ++++++ cmd/clusterctl/client/cluster/upgrader.go | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/clusterctl/client/cluster/installer.go b/cmd/clusterctl/client/cluster/installer.go index c15a55beb5cc..c5e688e42649 100644 --- a/cmd/clusterctl/client/cluster/installer.go +++ b/cmd/clusterctl/client/cluster/installer.go @@ -18,6 +18,7 @@ package cluster import ( "context" + "sort" "time" "github.com/pkg/errors" @@ -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) { diff --git a/cmd/clusterctl/client/cluster/upgrader.go b/cmd/clusterctl/client/cluster/upgrader.go index cd829be313e6..7498ec53e618 100644 --- a/cmd/clusterctl/client/cluster/upgrader.go +++ b/cmd/clusterctl/client/cluster/upgrader.go @@ -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" @@ -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