-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 alpha rollout undo for MachineDeployments #4098
✨ Clusterctl alpha rollout undo for MachineDeployments #4098
Conversation
Hi @Arvinderpal. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
@wfernandes Here it is. 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this is building on top of #4054
Yes, it is. @wfernandes suggested it to get the review process started. Once #4054 merges, we can rebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had the chance to actually use these features yet. But this is a first pass review. Thanks for putting in the work.
cmd/clusterctl/client/rollout.go
Outdated
@@ -62,7 +139,7 @@ func (c *clusterctlClient) RolloutRestart(options RolloutRestartOptions) error { | |||
} | |||
|
|||
for _, t := range tuples { | |||
if err := c.alphaClient.Rollout().ObjectRestarter(clusterClient.Proxy(), t, options.Namespace); err != nil { | |||
if err := c.alphaClient.Rollout().ObjectRollbacker(clusterClient.Proxy(), t, options.Namespace, options.ToRevision); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we are calling this behavior "Rollback" and not "Undo" within the Rollout client? Just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason is that kubectl itself has this naming convention -- the command is undo but underlying implementation refers to rollback. I kept it consistent with kubectl, even though it's annoying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying @Arvinderpal!
|
||
selector, err := metav1.LabelSelectorAsSelector(&d.Spec.Selector) | ||
if err != nil { | ||
log.V(5).Info("Skipping MachineSet, failed to get label selector from spec selector", "machineset", ms.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is getting the label selector from the deployment, I'm assuming that the error is meant to reflect just that.
log.V(5).Info("Skipping MachineSet, failed to get label selector from spec selector", "machineset", ms.Name) | |
log.V(5).Info("Skipping MachineSet, failed to get label selector from MachineDeployment.Spec.Selector", "MachineDeployment", d.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, can this and the following selector.Empty()
checks be moved outside the loop? The MachineDeployment is fixed, so should we iterate over the MachineSet items only if we have a non-empty selector.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually leveraged existing code here:
selector, err := metav1.LabelSelectorAsSelector(&d.Spec.Selector) |
But I see your point, I don't see why the selector should be in the loop. I'll change it unless you see any reason otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason TBH. Maybe someone else may know why.
@vincepri Any thoughts?
f3a2143
to
2a25c68
Compare
@Arvinderpal Since #4054 has been merged we can rebase this and remove WIP. 🙂 |
2a25c68
to
db1abdc
Compare
@wfernandes Done. PTAL. |
00d4d4b
to
e99d62e
Compare
@Arvinderpal Thanks! I'll take a look tomorrow asap 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't able to manually test this because of yak-shaving issues. 😄
But apart from the MachineDeployment labelselector being within the MachineSet loop, it lgtm
if toRevision > 0 { | ||
return nil, errors.Errorf("unable to find specified revision: %v", toRevision) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is added to provide a better error msg because I see that the next check would also result in returning an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the specific revision desired was not found. It's different from the next error which is that there is no previous MS associated with this deployment.
@wfernandes Thanks for the final review! |
/ok-to-test |
/assign @fabriziopandini for final review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, I still have to take a look at the tests
// ObjectRollbacker will issue a rollback on the specified cluster-api resource. | ||
func (r *rollout) ObjectRollbacker(proxy cluster.Proxy, tuple util.ResourceTuple, namespace string, toRevision int64) error { | ||
switch tuple.Resource { | ||
case machineDeployment: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at the code base in some places we are using machineDeployment (const), in some others "machinedeployment" (string).
What about getting rid of lowercase version of Kind and use Kind instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, just followed kubectl conventions with the long-term goal to put this functionality in kubectl.
I should be using the const everywhere including tests. I will do that.
for idx := range machineSets.Items { | ||
ms := &machineSets.Items[idx] | ||
|
||
selector, err := metav1.LabelSelectorAsSelector(&d.Spec.Selector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move out of the for loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See discussion with Warren below. :)
cmd := &cobra.Command{ | ||
Use: "undo RESOURCE", | ||
DisableFlagsInUseLine: true, | ||
Short: "Undo a cluster-api resource", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show we be a little bit more specific given that we are supporting only machine deployments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add this to the cleanup PR since all commands will need updating.
@@ -30,6 +30,7 @@ type Rollout interface { | |||
ObjectRestarter(cluster.Proxy, util.ResourceTuple, string) error | |||
ObjectPauser(cluster.Proxy, util.ResourceTuple, string) error | |||
ObjectResumer(cluster.Proxy, util.ResourceTuple, string) error | |||
ObjectRollbacker(cluster.Proxy, util.ResourceTuple, string, int64) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it required to use int64?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the underlying mdutil.Revision()
func returns a int64.
/milestone v0.4.0 @Arvinderpal Please rebase as well, given the changes for Go 1.16 that merged yesterday |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabriziopandini Thank you for the feedback. PTAL again.
@@ -30,6 +30,7 @@ type Rollout interface { | |||
ObjectRestarter(cluster.Proxy, util.ResourceTuple, string) error | |||
ObjectPauser(cluster.Proxy, util.ResourceTuple, string) error | |||
ObjectResumer(cluster.Proxy, util.ResourceTuple, string) error | |||
ObjectRollbacker(cluster.Proxy, util.ResourceTuple, string, int64) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the underlying mdutil.Revision()
func returns a int64.
// ObjectRollbacker will issue a rollback on the specified cluster-api resource. | ||
func (r *rollout) ObjectRollbacker(proxy cluster.Proxy, tuple util.ResourceTuple, namespace string, toRevision int64) error { | ||
switch tuple.Resource { | ||
case machineDeployment: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, just followed kubectl conventions with the long-term goal to put this functionality in kubectl.
I should be using the const everywhere including tests. I will do that.
cmd := &cobra.Command{ | ||
Use: "undo RESOURCE", | ||
DisableFlagsInUseLine: true, | ||
Short: "Undo a cluster-api resource", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add this to the cleanup PR since all commands will need updating.
for idx := range machineSets.Items { | ||
ms := &machineSets.Items[idx] | ||
|
||
selector, err := metav1.LabelSelectorAsSelector(&d.Spec.Selector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See discussion with Warren below. :)
3f347d2
to
9dbfb4f
Compare
for MachineDeployment.
9dbfb4f
to
3cd6fa1
Compare
@fabriziopandini Thanks again for the follow up. If it's okay with you, we can merge this and address the remaining issues in: #4266 See tracking issue as well: #3439 |
/lgtm |
@vincepri @fabriziopandini Considering there are two LGTMs, can we approve and merge this? Thank you. |
@Arvinderpal Could we open an issue for the follow-up PRs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[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 |
|
/retest |
1 similar comment
/retest |
@Arvinderpal: The following test failed, say
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. |
What this PR does / why we need it:
Adds command and client for the
clusterctl alpha rollout undo
command.Example Usage: Rollback to earlier K version after upgrade.
Another example is to rollback to an earlier MachineTemplate. See CAPI book on how to change MachineTemplates.
Tracking Issue:
#3439