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

✨ Extra validations for v1alpha3 -> v1alpha4 upgrade #4230

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

shysank
Copy link
Contributor

@shysank shysank commented Feb 24, 2021

What this PR does / why we need it:
Validations for v1alpha3 -> v1alpha4 upgrade

  • Blocks if there are multiple instances of a provider
  • Deletes capi-webhook-system namespace

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #4194

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 24, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 24, 2021
@@ -143,6 +149,13 @@ func (u *providerUpgrader) ApplyPlan(coreProvider clusterctlv1.Provider, contrac
log := logf.Log
log.Info("Performing upgrade...")

// Check for multiple instances of the same provider for v1alpha4 contract.
if contract == v1alpha4Contract {
Copy link
Contributor Author

@shysank shysank Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be contract > v1alpha3? Is there an api version parsing library that can be used for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are moving this check into the doUpgrade func, then we can rely on the upgrade plan and do check only if the current contract is v1alpha3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to find the current contract in upgradePlan, I could only find upgradePlan.contract which I believe is the contract that we want to upgrade to.

@shysank
Copy link
Contributor Author

shysank commented Feb 24, 2021

/test pull-cluster-api-test-main

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/clusterctl/client/cluster/components.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/components.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/components.go Outdated Show resolved Hide resolved
func Test_providerComponents_DeleteCoreProviderWebhookNamespace(t *testing.T) {
t.Run("deletes capi-webhook-system namespace", func(t *testing.T) {
g := NewWithT(t)
labels := map[string]string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these labels required for the test scenario?

cmd/clusterctl/client/cluster/upgrader.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/upgrader.go Outdated Show resolved Hide resolved
Comment on lines 197 to 205
providerTypeGrouping := make(map[string][]string)
for _, p := range providers.Items {
namespacedName := types.NamespacedName{Namespace: p.Namespace, Name: p.Name}.String()
if providers, ok := providerTypeGrouping[p.Type]; ok {
providerTypeGrouping[p.Type] = append(providers, namespacedName)
} else {
providerTypeGrouping[p.Type] = []string{namespacedName}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use provider.ManifestLabel() to uniquely identify a provider (it is a combination of type and name).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to return the namespaces of the provider in the error message so that it's useful for the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got your point, but my concern is that we are redefining the concept of provider uniqueness (name + type) and provider instance (a combination of type, name + namespace), while there was an effort to centralizing those definitions on the Provider type and make them consistent across the codebase.

Please also note that the proposed implementation uses as criteria for detecting duplicates only type which is not correct because if you have infrastructure docker + infrastructure AWS it will block (instead this should pass).

The only use where we should black is when I have two instances of the same provider, where the same is defined by the uniqueness concept defined above (name + type). e,g if you have infrastructure AWS on ns1, infrastructure AWS on ns2 it should block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, Fabrizio. I think I misread your original comment thinking it was for the value in the map. Thanks for catching it. I've fixed it now and updated the tests to reflect that. Let me know what you think.

cmd/clusterctl/client/cluster/upgrader.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/upgrader_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/upgrader.go Outdated Show resolved Hide resolved
@shysank
Copy link
Contributor Author

shysank commented Feb 26, 2021

@fabriziopandini I've addressed the review comments, PTAL.

@shysank
Copy link
Contributor Author

shysank commented Feb 26, 2021

/test pull-cluster-api-test-main

Comment on lines 372 to 373
return errors.Wrap(kerrors.NewAggregate(errs), "detected multiple instances of the same provider, "+
"multi-tenancy does not require to run multiple provider instances from v1alpha4: https://master.cluster-api.sigs.k8s.io/developer/architecture/controllers/support-multiple-instances.html")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.Wrap(kerrors.NewAggregate(errs), "detected multiple instances of the same provider, "+
"multi-tenancy does not require to run multiple provider instances from v1alpha4: https://master.cluster-api.sigs.k8s.io/developer/architecture/controllers/support-multiple-instances.html")
return errors.Wrap(kerrors.NewAggregate(errs), "detected multiple instances of the same provider, "+
"but clusterctl v1alpha4 does not support this use case. See https://cluster-api.sigs.k8s.io/developer/architecture/controllers/support-multiple-instances.html for more details")

@@ -49,6 +49,10 @@ type UpgradePlan struct {
Providers []UpgradeItem
}

const (
v1alpha4Contract = "v1alpha4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use clusterv1.GroupVersion.Version instead of this const, so the code will be more future proof

return
}

g.Expect(err).NotTo(HaveOccurred())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a check ensuring the webhook namespace is removed?

@CecileRobertMichon
Copy link
Contributor

/retitle ✨ Extra validations for v1alpha3 -> v1alpha4 upgrade

@k8s-ci-robot k8s-ci-robot changed the title ✨ Extra validations for v1alph3 -> valpha4 upgrade ✨ Extra validations for v1alpha3 -> v1alpha4 upgrade Feb 26, 2021
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 1, 2021
@vincepri
Copy link
Member

vincepri commented Mar 1, 2021

/retest

1 similar comment
@vincepri
Copy link
Member

vincepri commented Mar 1, 2021

/retest

@fabriziopandini
Copy link
Member

/milestone v0.4.0

@k8s-ci-robot k8s-ci-robot added this to the v0.4.0 milestone Mar 5, 2021
@shysank
Copy link
Contributor Author

shysank commented Mar 8, 2021

/test pull-cluster-api-test-main

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 1, 2021
@shysank shysank force-pushed the feature/4194 branch 2 times, most recently from 1810198 to ac44257 Compare April 1, 2021 18:56
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Apr 6, 2021

@shysank: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-cluster-api-apidiff-main 5afd3ac link /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 6, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 6, 2021
@k8s-ci-robot k8s-ci-robot merged commit c5b434a into kubernetes-sigs:master Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement clusterctl v1alpha3 --> v1alpha4 extra steps
5 participants