Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Use CAPI utils to reduce boilerplate #106

Merged
merged 2 commits into from
Aug 9, 2019

Conversation

chuckha
Copy link
Contributor

@chuckha chuckha commented Aug 9, 2019

Signed-off-by: Chuck Ha [email protected]

What this PR does / why we need it:
This PR uses the util code and removes some boilerplate making the Reconcile function shorter and easier to read.

It also bumps CAPI version and refactors some test logic.

Release note:

NONE

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chuckha

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 9, 2019
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 9, 2019
@chuckha chuckha changed the title Use GetOwnerMachine Use CAPI utils to reduce boilerplate Aug 9, 2019
@chuckha
Copy link
Contributor Author

chuckha commented Aug 9, 2019

/assign @fabriziopandini @detiber

Copy link
Contributor

@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

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2019
@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2019
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, machine.ObjectMeta)
if err != nil {
if err == util.ErrNoCluster {
log.Info(fmt.Sprintf("Please set the label %q on the machine equal to the name of the cluster this machine belongs to", capiv1alpha2.MachineClusterLabelName))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this the right place to log this message?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this error to be set from the Machine controller rather than here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i'll nix it, thanks

@detiber
Copy link
Contributor

detiber commented Aug 9, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 9, 2019
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 9, 2019
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 9, 2019
Copy link
Contributor

@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.

@chuckha thanks for cleaning up the reconcile method!
only one minor from my side, but nothing blocking

@@ -32,6 +32,42 @@ import (
)

func TestControlPlaneInitLockerAcquire(t *testing.T) {
tests := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

[1] Are you expecting more test case should be added? otherwise, we can get rid of subtests...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

some context:

I took a test that was testing too many things (error case + non error case) and split it into these two test functions. I kept the structure identical to make sure the tests didn't actually change.

I think it's ok to leave the table structure even with only one test.

My general approach here is to: Write a test that does not use table testing. If I need a second or third case I will add table tests if it makes sense, but overall I prefer the look and readability of table tests.

Are you ok leaving this one as is?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok!

}
}

func TestControlPlaneInitLockerAcquireErrors(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one has 3 table tests, I don't think we should get rid of subtests.

Copy link
Contributor

Choose a reason for hiding this comment

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

time to take a break...

@fabriziopandini
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2019
@k8s-ci-robot k8s-ci-robot merged commit c3315b0 into kubernetes-retired:master Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 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.

4 participants