Skip to content

Commit b900c6f

Browse files
authored
Merge pull request #4268 from fabriziopandini/clusterctl-v1alpha3-should-not-upgrade-to-v1alpha4
⚠️ Clusterctl v1alpha3 should not upgrade to v1alpha4
2 parents d731781 + 1f4f722 commit b900c6f

File tree

7 files changed

+679
-171
lines changed

7 files changed

+679
-171
lines changed

cmd/clusterctl/client/cluster/upgrader.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/pkg/errors"
2121
"k8s.io/apimachinery/pkg/util/sets"
2222
"k8s.io/apimachinery/pkg/util/version"
23+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
2324
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
2425
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
2526
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/repository"
@@ -100,7 +101,8 @@ func (u *providerUpgrader) Plan() ([]UpgradePlan, error) {
100101
// in a management group are expected to support the same API Version of Cluster API (contract).
101102
// e.g if the core provider supports v1alpha3, all the providers in the same management group should support v1alpha3 as well;
102103
// all the providers in the management group can upgrade to the latest release supporting v1alpha3, or if available,
103-
// or if available, all the providers in the management group can upgrade to the latest release supporting v1alpha4.
104+
// all the providers in the management group can upgrade to the latest release supporting v1alpha4
105+
// (not supported in current clusterctl release, but upgrade plan should report these options)
104106

105107
// Gets the upgrade info for the core provider.
106108
coreUpgradeInfo, err := u.getUpgradeInfo(managementGroup.CoreProvider)
@@ -117,8 +119,8 @@ func (u *providerUpgrader) Plan() ([]UpgradePlan, error) {
117119

118120
// Creates an UpgradePlan for each contract considered for upgrades; each upgrade plans contains
119121
// an UpgradeItem for each provider defining the next available version with the target contract, if available.
120-
// e.g. v1alpha3, cluster-api --> v0.3.2, kubeadm bootstrap --> v0.3.2, aws --> v0.5.4
121-
// e.g. v1alpha4, cluster-api --> v0.4.1, kubeadm bootstrap --> v0.4.1, aws --> v0.6.2
122+
// e.g. v1alpha3, cluster-api --> v0.3.2, kubeadm bootstrap --> v0.3.2, aws --> v0.5.4 (not supported in current clusterctl release, but upgrade plan should report these options).
123+
// e.g. v1alpha4, cluster-api --> v0.4.1, kubeadm bootstrap --> v0.4.1, aws --> v0.X.2 (not supported in current clusterctl release, but upgrade plan should report these options).
122124
for _, contract := range contractsForUpgrade {
123125
upgradePlan, err := u.getUpgradePlan(managementGroup, contract)
124126
if err != nil {
@@ -140,6 +142,10 @@ func (u *providerUpgrader) Plan() ([]UpgradePlan, error) {
140142
}
141143

142144
func (u *providerUpgrader) ApplyPlan(coreProvider clusterctlv1.Provider, contract string) error {
145+
if contract != clusterv1.GroupVersion.Version {
146+
return errors.Errorf("current version of clusterctl could only upgrade to %s contract, requested %s", clusterv1.GroupVersion.Version, contract)
147+
}
148+
143149
log := logf.Log
144150
log.Info("Performing upgrade...")
145151

@@ -245,6 +251,10 @@ func (u *providerUpgrader) createCustomPlan(coreProvider clusterctlv1.Provider,
245251
return nil, err
246252
}
247253

254+
if targetContract != clusterv1.GroupVersion.Version {
255+
return nil, errors.Errorf("current version of clusterctl could only upgrade to %s contract, requested %s", clusterv1.GroupVersion.Version, targetContract)
256+
}
257+
248258
// Builds the custom upgrade plan, by adding all the upgrade items after checking consistency with the targetContract.
249259
upgradeInstanceNames := sets.NewString()
250260
upgradePlan := &UpgradePlan{

cmd/clusterctl/client/cluster/upgrader_info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type upgradeInfo struct {
4444
}
4545

4646
// getUpgradeInfo returns all the info required for taking upgrade decisions for a provider.
47+
// NOTE: This could contain also versions for the previous or next Cluster API contract (not supported in current clusterctl release, but upgrade plan should report this options).
4748
func (u *providerUpgrader) getUpgradeInfo(provider clusterctlv1.Provider) (*upgradeInfo, error) {
4849
// Gets the list of versions available in the provider repository.
4950
configRepository, err := u.configClient.Providers().Get(provider.ProviderName, provider.GetProviderType())
@@ -96,6 +97,7 @@ func (u *providerUpgrader) getUpgradeInfo(provider clusterctlv1.Provider) (*upgr
9697
// Filters the versions to be considered for upgrading the provider (next
9798
// versions) and checks if the releaseSeries defined in metadata includes
9899
// all of them.
100+
// NOTE: This could contain also versions for the previous or next Cluster API contract (not supported in current clusterctl release, but upgrade plan should report this options).
99101
nextVersions := []version.Version{}
100102
for _, repositoryVersion := range repositoryVersions {
101103
// we are ignoring the conversion error here because a first check already passed above
@@ -144,9 +146,7 @@ func newUpgradeInfo(metadata *clusterctlv1.Metadata, currentVersion *version.Ver
144146
}
145147
}
146148

147-
// getContractsForUpgrade return the list of API Version of Cluster API (contract) version available for a provider upgrade. e.g.
148-
// - If the current version of the provider support v1alpha3 contract (the latest), it returns v1alpha3
149-
// - If the current version of the provider support v1alpha3 contract but there is also the v1alpha4 contract available, it returns v1alpha3, v1alpha4
149+
// getContractsForUpgrade return the list of API Version of Cluster API (contract) version available for a provider upgrade.
150150
func (i *upgradeInfo) getContractsForUpgrade() []string {
151151
contractsForUpgrade := sets.NewString()
152152
for _, releaseSeries := range i.metadata.ReleaseSeries {

0 commit comments

Comments
 (0)