Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 clusterctl: add flag to skip lagging provider check in ApplyCustomPlan #11196

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions cmd/clusterctl/client/cluster/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ type UpgradePlan struct {

// UpgradeOptions defines the options used to upgrade installation.
type UpgradeOptions struct {
WaitProviders bool
WaitProviderTimeout time.Duration
WaitProviders bool
WaitProviderTimeout time.Duration
SkipLaggingProvidersCheck bool
}

// isPartialUpgrade returns true if at least one upgradeItem in the plan does not have a target version.
Expand Down Expand Up @@ -180,7 +181,7 @@ func (u *providerUpgrader) ApplyCustomPlan(ctx context.Context, opts UpgradeOpti

// Create a custom upgrade plan from the upgrade items, taking care of ensuring all the providers in a management
// cluster are consistent with the API Version of Cluster API (contract).
upgradePlan, err := u.createCustomPlan(ctx, upgradeItems)
upgradePlan, err := u.createCustomPlan(ctx, opts, upgradeItems)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +219,7 @@ func (u *providerUpgrader) getUpgradePlan(ctx context.Context, providers []clust

// createCustomPlan creates a custom upgrade plan from a set of upgrade items, taking care of ensuring all the providers
// in a management cluster are consistent with the API Version of Cluster API (contract).
func (u *providerUpgrader) createCustomPlan(ctx context.Context, upgradeItems []UpgradeItem) (*UpgradePlan, error) {
func (u *providerUpgrader) createCustomPlan(ctx context.Context, opts UpgradeOptions, upgradeItems []UpgradeItem) (*UpgradePlan, error) {
// Gets the API Version of Cluster API (contract).
// The this is required to ensure all the providers in a management cluster are consistent with the contract supported by the core provider.
// e.g if the core provider is v1beta1, all the provider should be v1beta1 as well.
Expand Down Expand Up @@ -286,20 +287,22 @@ func (u *providerUpgrader) createCustomPlan(ctx context.Context, upgradeItems []
}

// Before doing upgrades, checks if other providers in the management cluster are lagging behind the target contract.
for _, provider := range providerList.Items {
// skip providers already included in the upgrade plan
if upgradeInstanceNames.Has(provider.InstanceName()) {
continue
}
if !opts.SkipLaggingProvidersCheck {
for _, provider := range providerList.Items {
// skip providers already included in the upgrade plan
if upgradeInstanceNames.Has(provider.InstanceName()) {
continue
}

// Retrieves the contract that is supported by the current version of the provider.
contract, err := u.getProviderContractByVersion(ctx, provider, provider.Version)
if err != nil {
return nil, err
}
// Retrieves the contract that is supported by the current version of the provider.
contract, err := u.getProviderContractByVersion(ctx, provider, provider.Version)
if err != nil {
return nil, err
}

if contract != targetContract {
return nil, errors.Errorf("unable to complete that upgrade: the provider %s supports the %s API Version of Cluster API (contract), while the management cluster is being updated to %s. Please include the %[1]s provider in the upgrade", provider.InstanceName(), contract, targetContract)
if contract != targetContract {
return nil, errors.Errorf("unable to complete that upgrade: the provider %s supports the %s API Version of Cluster API (contract), while the management cluster is being updated to %s. Please include the %[1]s provider in the upgrade", provider.InstanceName(), contract, targetContract)
}
}
}
return upgradePlan, nil
Expand Down Expand Up @@ -448,7 +451,13 @@ func (u *providerUpgrader) doUpgrade(ctx context.Context, upgradePlan *UpgradePl
}
}

return waitForProvidersReady(ctx, InstallOptions(opts), installQueue, u.proxy)
// Convert UpgradeOptions to InstallOptions struct
installOptions := InstallOptions{
WaitProviders: opts.WaitProviders,
WaitProviderTimeout: opts.WaitProviderTimeout,
}

return waitForProvidersReady(ctx, installOptions, installQueue, u.proxy)
}

func (u *providerUpgrader) scaleDownProvider(ctx context.Context, provider clusterctlv1.Provider) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func Test_providerUpgrader_createCustomPlan(t *testing.T) {
},
providerInventory: newInventoryClient(tt.fields.proxy, nil),
}
got, err := u.createCustomPlan(ctx, tt.args.providersToUpgrade)
got, err := u.createCustomPlan(ctx, UpgradeOptions{}, tt.args.providersToUpgrade)
if tt.wantErr {
g.Expect(err).To(HaveOccurred())
return
Expand Down
8 changes: 6 additions & 2 deletions cmd/clusterctl/client/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ type ApplyUpgradeOptions struct {

// WaitProviderTimeout sets the timeout per provider upgrade.
WaitProviderTimeout time.Duration

// SkipLaggingProvidersCheck skips checking if other providers in the management cluster are lagging behind the target contract during upgrade planning.
SkipLaggingProvidersCheck bool
}

func (c *clusterctlClient) ApplyUpgrade(ctx context.Context, options ApplyUpgradeOptions) error {
Expand Down Expand Up @@ -171,8 +174,9 @@ func (c *clusterctlClient) ApplyUpgrade(ctx context.Context, options ApplyUpgrad
len(options.AddonProviders) > 0

opts := cluster.UpgradeOptions{
WaitProviders: options.WaitProviders,
WaitProviderTimeout: options.WaitProviderTimeout,
WaitProviders: options.WaitProviders,
WaitProviderTimeout: options.WaitProviderTimeout,
SkipLaggingProvidersCheck: options.SkipLaggingProvidersCheck,
}

// If we are upgrading a specific set of providers only, process the providers and call ApplyCustomPlan.
Expand Down
4 changes: 4 additions & 0 deletions cmd/clusterctl/cmd/upgrade_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type upgradeApplyOptions struct {
addonProviders []string
waitProviders bool
waitProviderTimeout int
skipLaggingProvidersCheck bool
}

var ua = &upgradeApplyOptions{}
Expand Down Expand Up @@ -93,6 +94,8 @@ func init() {
"Wait for providers to be upgraded.")
upgradeApplyCmd.Flags().IntVar(&ua.waitProviderTimeout, "wait-provider-timeout", 5*60,
"Wait timeout per provider upgrade in seconds. This value is ignored if --wait-providers is false")
upgradeApplyCmd.Flags().BoolVar(&ua.skipLaggingProvidersCheck, "skip-lagging-providers-check", false,
"Skips checking if other providers in the management cluster are lagging behind the target contract during upgrade planning")
}

func runUpgradeApply() error {
Expand Down Expand Up @@ -130,5 +133,6 @@ func runUpgradeApply() error {
AddonProviders: ua.addonProviders,
WaitProviders: ua.waitProviders,
WaitProviderTimeout: time.Duration(ua.waitProviderTimeout) * time.Second,
SkipLaggingProvidersCheck: ua.skipLaggingProvidersCheck,
})
}