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 alpha rollout pause/resume for MachineDeployments #4054

Merged

Conversation

Arvinderpal
Copy link
Contributor

What this PR does / why we need it:
Adds command and client for the clusterctl alpha rollout pause/resume.

Tracking Issue:
#3439

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 6, 2021
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 6, 2021
@Arvinderpal Arvinderpal mentioned this pull request Jan 6, 2021
9 tasks
@Arvinderpal
Copy link
Contributor Author

@wfernandes @vincepri PTAL.
I also have the undo command ready to go but will wait until this is merged.
Thank you

@wfernandes
Copy link
Contributor

@Arvinderpal Thanks for this PR! I'll take a look at this first thing next week 🙂

@wfernandes
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 8, 2021
Copy link
Contributor

@wfernandes wfernandes left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Arvinderpal. Just some minor comments 🙂

cmd/clusterctl/client/alpha/rollout_pauser.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_pauser_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_resumer.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_resumer_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_resumer_test.go Outdated Show resolved Hide resolved
Comment on lines 73 to 66
clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
if err != nil {
return err
}

// If the option specifying the Namespace is empty, try to detect it.
if options.Namespace == "" {
currentNamespace, err := clusterClient.Proxy().CurrentNamespace()
if err != nil {
return err
}
options.Namespace = currentNamespace
}

if len(options.Resources) == 0 {
return fmt.Errorf("required resource not specified")
}
normalized := normalizeResources(options.Resources)
tuples, err := util.ResourceTypeAndNameArgs(normalized...)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code seems duplicated in every method. I suggest refactoring it to consolidate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored it.

@@ -32,7 +32,7 @@ func Test_clusterctlClient_RolloutRestart(t *testing.T) {
client *fakeClient
}
type args struct {
options RolloutRestartOptions
options RolloutOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's refactor this test so that we can assert on each of the rollout behaviors - pause, resume, restart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL

cmd/clusterctl/cmd/rollout/pause.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/rollout/resume.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/rollout/pause.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Arvinderpal Arvinderpal left a comment

Choose a reason for hiding this comment

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

@wfernandes Thank you for the review. I think I have addressed all your comments.

cmd/clusterctl/client/alpha/rollout_pauser.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_pauser_test.go Outdated Show resolved Hide resolved
Comment on lines 73 to 66
clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
if err != nil {
return err
}

// If the option specifying the Namespace is empty, try to detect it.
if options.Namespace == "" {
currentNamespace, err := clusterClient.Proxy().CurrentNamespace()
if err != nil {
return err
}
options.Namespace = currentNamespace
}

if len(options.Resources) == 0 {
return fmt.Errorf("required resource not specified")
}
normalized := normalizeResources(options.Resources)
tuples, err := util.ResourceTypeAndNameArgs(normalized...)
if err != nil {
return err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored it.

@@ -32,7 +32,7 @@ func Test_clusterctlClient_RolloutRestart(t *testing.T) {
client *fakeClient
}
type args struct {
options RolloutRestartOptions
options RolloutOptions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL

cmd/clusterctl/cmd/rollout/resume.go Outdated Show resolved Hide resolved
Copy link
Contributor

@wfernandes wfernandes left a comment

Choose a reason for hiding this comment

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

Just a clarification. Thanks.

clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
if err != nil {
return err
}
tuples, err := getResourceTuples(clusterClient, options)
if err != nil {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Umm...is this correct? Or should this be return err? It also looks like the tests all passed having this logic in so if this is indeed meant to be return err then we should have a unit test that asserts this. Thanks!

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 pointing that out! The fakeClient was not calling the individual funcs for the subcommands.
I also had to separate these tests -- for example, the RolloutResume will throw an error if the md is not paused, while the RolloutRestart will do the opposite if it is paused, so the same test cases cannot be passed to all of them.
There are additional tests in the lower level funcs that check for functional correctness. Is it okay if we keep these tests relatively simple?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah...that's fine. I just wanted to ensure that if I changed this to return nil and run the tests in the client pkg, then I would see a failing test for the right reason. 🙂

cmd/clusterctl/client/rollout.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/rollout.go Outdated Show resolved Hide resolved
@Arvinderpal Arvinderpal force-pushed the clusterctl-alpha-rollout-pause branch 2 times, most recently from f0b137d to 43afe6c Compare January 13, 2021 21:30
@wfernandes
Copy link
Contributor

/lgtm
Over to @fabriziopandini or @CecileRobertMichon for approval.

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

Thanks @wfernandes
@fabriziopandini @CecileRobertMichon PTAL.
I have the undo command PR ready to go after this one as well.

@fabriziopandini
Copy link
Member

/milestone v0.4.0

@k8s-ci-robot k8s-ci-robot added this to the v0.4.0 milestone Jan 19, 2021
@wfernandes
Copy link
Contributor

@Arvinderpal If you'd like to submit the PR for the undo rollout command we can temporarily put a WIP or a /hold until this gets merged and then we can rebase onto it.
Just a suggestion so you can get eyes on the other PR immediately instead of having to wait for this to get merged. 🙂

@Arvinderpal
Copy link
Contributor Author

@Arvinderpal If you'd like to submit the PR for the undo rollout command we can temporarily put a WIP or a /hold until this gets merged and then we can rebase onto it.
Just a suggestion so you can get eyes on the other PR immediately instead of having to wait for this to get merged.

@wfernandes That's a good idea. I'll open an undo PR with a wip on it.

cmd/clusterctl/client/alpha/rollout_resumer.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_resumer.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/alpha/rollout_pauser.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Arvinderpal Arvinderpal left a comment

Choose a reason for hiding this comment

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

@vincepri Thanks for the review. I have incorporated your suggestions.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 22, 2021
@wfernandes
Copy link
Contributor

/lgtm

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

@vincepri Can we merge this?

)

// NewCmdRolloutPause returns a Command instance for 'rollout pause' sub command
func NewCmdRolloutPause(cfgFile string) *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

are you planning to add docs for the pause/resume command in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually don't see any docs for the rollout command in https://github.com/kubernetes-sigs/cluster-api/tree/master/docs/book/src/clusterctl/commands, are we tracking that in an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CecileRobertMichon There is a tracking issue and docs is in the list: #3439
If it's okay with you, I want to wait for a few more rollout subcommands to merge before opening a PR for the docs.

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
/hold
/assign @CecileRobertMichon
to remove the hold if everything looks 👍

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 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 Feb 3, 2021
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 2021
@Arvinderpal
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Feb 4, 2021

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

Test name Commit Details Rerun command
pull-cluster-api-apidiff-main b769eab 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.

@k8s-ci-robot k8s-ci-robot merged commit 1acb1b0 into kubernetes-sigs:master Feb 4, 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants