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

🐛 inline builders in test for MHC reconcilation #5987

Merged
merged 2 commits into from
Jan 28, 2022

Conversation

killianmuldoon
Copy link
Contributor

Signed-off-by: killianmuldoon [email protected]

Inline builders for the reconcileMachineDeploymentTests. Previously this test was written so that side effects could occur from one test case to the next.

c/f #5949 (comment)

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 25, 2022
@killianmuldoon killianmuldoon changed the title inline builders in test for MHC reconcilation 🐛 inline builders in test for MHC reconcilation Jan 25, 2022
@enxebre
Copy link
Member

enxebre commented Jan 26, 2022

/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 26, 2022
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed 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. labels Jan 27, 2022
@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 Jan 27, 2022
Comment on lines 1008 to 1016
if len(m.conditions) > 0 {
out.conditions = make([]clusterv1.UnhealthyCondition, len(m.conditions))
copy(out.conditions, m.conditions)
}
if len(m.ownerRefs) > 0 {
for _, ref := range m.ownerRefs {
out.ownerRefs = append(out.ownerRefs, *ref.DeepCopy())
}
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: why do we copy those arrays differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that because OwnerRefs have pointers in them so they need to be deepcopied to ensure we're getting a copy. UnhealthyConditions only contains values so it should be alright.

Copy link
Member

Choose a reason for hiding this comment

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

Thx. I'll take a look but that sounds reasonable :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alternative here (and maybe a better option) would be to add deepcopy generation for this file.

Copy link
Member

@sbueringer sbueringer Jan 27, 2022

Choose a reason for hiding this comment

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

Yup, in the best case it just generates everything for us and if we're fine with calling DeepCopy instead of Clone we don't have to implement anything ourselves/manually.

WDYT, worth a try?

I'm definitely +1 as it's less effort to write and maintain this code and we reduce the probability to forget setting fields or implementing the copy incorrectly to zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the kubebuilder generation doesn't work with map[string]interface{}.

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 disabled generation for those fields - I'm not sure if there's a way to tweak it to make generation of map[string]interface{} work for kubebuilder or if it would be better to stop using that for the spec fields in the builders. For now though those functions aren't needed so I think it's fine to go forward with the PR as it stands.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds great so far and looks good at a first glance (will take a closer look tomorrow).

I assume "kubebuilder generation" = the deep copy generation of controller-gen? (just to confirm)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - I'm doing it here using the kubebuilder tags.

Copy link
Member

Choose a reason for hiding this comment

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

I think we won't be able to make that work (at least without adjusting controller-gen or changing the data type of the values of the map).

The problem is that controller-gen cannot generate a DeepCopy func for a interface{} (I guess because it can be anything):
https://github.com/kubernetes-sigs/controller-tools/blob/a410b23ff25739563e103e98af887adfd05feb98/pkg/deepcopy/traverse.go#L386-L393

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.

/lgtm

@@ -394,6 +394,7 @@ func (m *MachineDeploymentClassBuilder) Build() *clusterv1.MachineDeploymentClas
}

// InfrastructureMachineTemplateBuilder holds the variables and objects needed to build an InfrastructureMachineTemplate.
// +kubebuilder:object:generate=false
Copy link
Member

Choose a reason for hiding this comment

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

Just for my understanding, why are we excluding some builder from generating deep copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The generation didn't work for map[string]interface{} - I'm not sure if there's a way to manage this automatically. This was the simplest solution as we don't strictly need DeepCopy on these types yet, but I'd be happy to fix it. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation.
If we will need DeepCopy for those types we can either implement it manually or consider using something like apiextensionsv1.JSON (there are also other options), but I ok in tacking thin in a follow up iteration

Copy link
Member

Choose a reason for hiding this comment

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

Using something like apiextensionsv1.JSON sounds reasonable to me, too. Let's open an issue?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 28, 2022
@fabriziopandini
Copy link
Member

@sbueringer PTAL

@sbueringer
Copy link
Member

sbueringer commented Jan 28, 2022

/lgtm
Would be good if we can open an issue for the follow-up (#5987 (comment))

I like how we now leverage controller-gen to avoid writing error-prone code manually.

@fabriziopandini
Copy link
Member

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 Jan 28, 2022
@k8s-ci-robot k8s-ci-robot merged commit 03d6487 into kubernetes-sigs:main Jan 28, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Jan 28, 2022
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.

5 participants