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

use cluster api patch helper to do the scope close #1020

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

xrmzju
Copy link
Member

@xrmzju xrmzju commented Aug 15, 2019

What this PR does / why we need it:
fix issue: #1019
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 #

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:


@k8s-ci-robot
Copy link
Contributor

Welcome @xrmzju!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-aws 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-aws has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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 added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 15, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @xrmzju. Thanks for your PR.

I'm waiting for a kubernetes-sigs or kubernetes 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 the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 15, 2019
@vincepri
Copy link
Member

/hold

@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 Aug 15, 2019
@vincepri
Copy link
Member

@xrmzju It seems that the issue can be fixed by issuing Status().Patch() before the normal Patch(), see kubernetes-sigs/cluster-api#1261

@xrmzju
Copy link
Member Author

xrmzju commented Aug 19, 2019

I signed it

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 19, 2019
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 19, 2019
@xrmzju
Copy link
Member Author

xrmzju commented Aug 19, 2019

@xrmzju It seems that the issue can be fixed by issuing Status().Patch() before the normal Patch(), see kubernetes-sigs/cluster-api#1261

@vincepri this is my first solution when i found the overwrite issue. but i found another problem about it. in my provider controller, i will generate certs info if not specified in the provider spec and store it in a secret. after first reconcile, the certs info and secret are generated normally. after status.Patch, it will trigger a new update event, and the cert info of the upcoming object is still nil<status.Patch does not update spec>, so the second reconcile round would do the generate certs action again without update the secret info(cause i'll try to get the secret, if exist i will not create it), that causes inconsistence between the cert info in the spec and stored in the secret.
the above case is only to declare that if we try to do some in our logic(i am not sure if it exist in aws controller), just put status.Patch before the client.Patch will cause some problem. i think the status copy action would be the most secure solution.

@vincepri
Copy link
Member

@xrmzju Thanks for the detailed explanation! The change LGTM, can we add unit tests to cover the behaviors you've described? It'd be great to cover both the failing and success cases with DeepCopy, so we can track this issue.

@detiber is also working on a generic implementation of patching in Cluster API, once that's ready we should switch to that one.

@vincepri
Copy link
Member

/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 Aug 19, 2019
@ncdc
Copy link
Contributor

ncdc commented Aug 20, 2019

@detiber your patch helper will handle this, won't it?

@detiber
Copy link
Member

detiber commented Aug 20, 2019

@detiber your patch helper will handle this, won't it?

That is correct, an example of usage can be found here: kubernetes-retired/cluster-api-bootstrap-provider-kubeadm#148

@ncdc
Copy link
Contributor

ncdc commented Aug 20, 2019

@xrmzju do you want to adjust this PR to be based on the new patch helper & the example Jason provided? If not, please let us know, and we can get someone else to work on it.

@xrmzju
Copy link
Member Author

xrmzju commented Aug 21, 2019

@xrmzju do you want to adjust this PR to be based on the new patch helper & the example Jason provided? If not, please let us know, and we can get someone else to work on it.
@ncdc i'll adjust it.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 22, 2019
@xrmzju xrmzju changed the title copy object before do patch use cluster api patch helper to do the scope close Aug 22, 2019
@xrmzju
Copy link
Member Author

xrmzju commented Aug 22, 2019

/assign @vincepri @detiber @ncdc

}

return nil
return m.patchHelper.Patch(context.Background(), m.Machine)
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 m.patchHelper.Patch(context.Background(), m.Machine)
return m.patchHelper.Patch(context.Background(), m.AWSMachine)

Copy link
Member Author

Choose a reason for hiding this comment

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

my fault... done.

@@ -66,13 +67,17 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
params.AWSClients.ELB = elb.New(session)
}

helper, err := patch.NewHelper(params.AWSCluster, params.Client)
if err != nil {
return nil, errors.Errorf("failed to init patch helper: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use errors.Wrap

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -63,25 +63,28 @@ func NewMachineScope(params MachineScopeParams) (*MachineScope, error) {
params.Logger = klogr.New()
}

helper, err := patch.NewHelper(params.AWSMachine, params.Client)
if err != nil {
return nil, errors.Errorf("failed to init patch helper: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use errors.Wrap

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}, nil
}

// MachineScope defines a scope defined around a machine and its cluster.
type MachineScope struct {
logr.Logger
patch client.Patch
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of times we separate the unexported from the exported fields, as was the case here. I'd recommend you keep this pattern - move patchHelper back up here, and preserve the blank line in between client and Cluster.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, i'll keep that pattern

@ncdc
Copy link
Contributor

ncdc commented Aug 23, 2019

/lgtm
/approve

/assign @detiber
Jason, can you give it one final look, then cancel the hold? Thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc, xrmzju

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 Aug 23, 2019
@ncdc ncdc added this to the v0.4 milestone Aug 23, 2019
Copy link
Member

@detiber detiber left a comment

Choose a reason for hiding this comment

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

/lgtm

@detiber
Copy link
Member

detiber commented Aug 23, 2019

/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 Aug 23, 2019
@k8s-ci-robot k8s-ci-robot merged commit 469e8c9 into kubernetes-sigs:master Aug 23, 2019
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants