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

🌱 Test and document controller ownerReferences #9153

Merged

Conversation

killianmuldoon
Copy link
Contributor

@killianmuldoon killianmuldoon commented Aug 9, 2023

Signed-off-by: killianmuldoon kmuldoon@vmware.com

Add tests and documentation for which ownerReferences should have controller: true for Cluster API objects.

Part of #4014

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 9, 2023
@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 Aug 9, 2023
Copy link
Contributor Author

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

IMO we should use this PR to close any gaps between what we see here and the intention expressed in #4014. I'll note them on the tables.

Copy link
Contributor Author

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

One other note - the state of BlockOwnerDeletion is not consistent across all of our types where Controller is true I'd suggest setting this to true in all cases where controller is true.


## Owner reference relationships in Cluster API

The below tables map out the a reference for ownership relationships for the objects in a Cluster API cluster. The tables are identical for classy and non-classy clusters.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

classy and non-classy are the same as far as testing goes. I'm happy to have this as a principle to reduce complexity, but there's certain points where it may not make sense. e.g. for classy clusters KCP is created by the cluster controller, but for non-classy clusters it may be created by the user.

## KubeadmControlPlane types
| type | Owner | Controller | Note |
|-----------------------------|--------------|------------|------|
| KubeadmControlPlane | Cluster | true | |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not be contolled by Cluster as the Cluster doesn't necessarily create it.

## Kubeadm bootstrap types
| type | Owner | Controller | Note |
|-----------------------|--------------|------------|-------------------------------------------------|
| KubeadmConfig | Machine | true | When created for Machine |
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 is created by the MachineSet controller and then the ownerReference is passed over. I think it's still fine to keep this as a controller though.

## Infrastructure provider types
| type | Owner | Controller | Note |
|-------------------------------|--------------|------------|---------------------------------------------|
| InfrastructureMachine | Machine | yes | |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to KubeadmConfig - this is passed over from the MachineSet / KCP controller.

| InfrastructureMachine | Machine | yes | |
| InfrastructureMachineTemplate | Cluster | no | When created by cluster topology controller |
| InfrastructureMachineTemplate | ClusterClass | no | When referenced in a ClusterClass |
| InfrastructureCluster | Cluster | yes | |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not true for classy clusters. Should probably be reverted to no.

| type | Owner | Controller | Note |
|----------------------------|--------------------|------------|-------------------|
| ClusterResourcesSet | None | | |
| ClusterResourcesSetBinding | ClusterResourceSet | no | |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be yes.

| type | Owner | Controller | Note |
|-----------------------|--------------|------------|-------------------------------------------------|
| KubeadmConfig | Machine | true | When created for Machine |
| KubeadmConfig | MachinePool | unknown | When created for MachinePool. Not tested in e2e |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer test MachinePools in the quick start so this isn't covered. I can open an issue for this and tag folks that work regularly on MachinePools.

func hasExactOwnersByGVK(refList []metav1.OwnerReference, wantGVKs []schema.GroupVersionKind) error {
refGVKs := []schema.GroupVersionKind{}
// simpleOwnerRef is a simple representation of an ownerReference.
type simpleOwnerRef struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bunch of glue code changes to make the controller references comparable.

@killianmuldoon
Copy link
Contributor Author

/test

@k8s-ci-robot
Copy link
Contributor

@killianmuldoon: The /test command needs one or more targets.
The following commands are available to trigger required jobs:

  • /test pull-cluster-api-build-main
  • /test pull-cluster-api-e2e-main
  • /test pull-cluster-api-test-main
  • /test pull-cluster-api-verify-main

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-apidiff-main
  • /test pull-cluster-api-e2e-full-dualstack-and-ipv6-main
  • /test pull-cluster-api-e2e-full-main
  • /test pull-cluster-api-e2e-informing-main
  • /test pull-cluster-api-e2e-mink8s-main
  • /test pull-cluster-api-e2e-scale-main-experimental
  • /test pull-cluster-api-e2e-workload-upgrade-1-27-latest-main
  • /test pull-cluster-api-test-mink8s-main

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-apidiff-main
  • pull-cluster-api-build-main
  • pull-cluster-api-e2e-informing-main
  • pull-cluster-api-e2e-main
  • pull-cluster-api-test-main
  • pull-cluster-api-verify-main

In response to this:

/test

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.

@killianmuldoon
Copy link
Contributor Author

/test pull-cluster-api-e2e-full-main

@killianmuldoon killianmuldoon changed the title [WIP] 🌱 Add a guide describing ownerReference usage in CAPI [WIP] 🌱 Test and document controller ownerReferences Aug 9, 2023
@killianmuldoon
Copy link
Contributor Author

/area api

@k8s-ci-robot k8s-ci-robot added the area/api Issues or PRs related to the APIs label Aug 9, 2023
@killianmuldoon killianmuldoon changed the title [WIP] 🌱 Test and document controller ownerReferences 🌱 Test and document controller ownerReferences Aug 23, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 23, 2023
@killianmuldoon
Copy link
Contributor Author

/hold

I want to make sure the utils exposed here are right before merging.

@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 24, 2023
@killianmuldoon killianmuldoon force-pushed the pr-test-controller-refs branch 3 times, most recently from d3bb8dc to f4e80d7 Compare August 24, 2023 13:05
@killianmuldoon
Copy link
Contributor Author

/hold cancel

I think we should get the initial state of this merged and I'll create an issue, or update the existing issue, with elements of our ownerShip graph that we may want to change based on this documentation and test.

@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 24, 2023
@killianmuldoon
Copy link
Contributor Author

/test pull-cluster-api-e2e-full-main

docs/book/src/reference/owner_references.md Show resolved Hide resolved
},
// ClusterResourcesSetBinding has ClusterResourceSet set as owners on creation.
clusterResourceSetBindingKind: func(owners []metav1.OwnerReference) error {
return hasExactOwnersByGVK(owners, []schema.GroupVersionKind{clusterResourceSetGVK})
return HasOneOfExactOwners(owners, []simpleOwnerRef{clusterResourceSetOwner}, []simpleOwnerRef{clusterResourceSetOwner, clusterResourceSetOwner})
Copy link
Member

Choose a reason for hiding this comment

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

Mostly out of curiosity. Do you know why 1 or 2? Just the way our tests are written?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ClusterResourceSetBinding will have as many owners as ClusterResourceSets it managed for a single cluster. I added the option of 2 here just to save me a rewrite in CAPV - can revert if you'd prefer.

I think this is one of the ownerReference that we should reconsider.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see because doesn't matter how many CRS we have we will only have one ClusterResourceSetBinding per cluster, right?

(not really familiar with this stuff)

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 - each Cluster will have one CRS binding, but each binding may represent multiple ClusterResourceSets

Copy link
Member

@sbueringer sbueringer Aug 24, 2023

Choose a reason for hiding this comment

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

WDYT about opening a follow-up issue to support something like ">=1 Owners of the same" in the assertion?

Definitely just a nice to have and we don't have to immediately follow-up. I think the current change is just a simple improvement to support more cases. So fine to merge as is

Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
@sbueringer
Copy link
Member

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: 387f9c8cc25f49e5cb4f8df4ca9c8867af0ce568

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 24, 2023
@k8s-ci-robot k8s-ci-robot merged commit 62a574c into kubernetes-sigs:main Aug 24, 2023
22 of 23 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.6 milestone Aug 24, 2023
@killianmuldoon
Copy link
Contributor Author

/cherry-pick release-1.5

@k8s-infra-cherrypick-robot

@killianmuldoon: new pull request created: #9303

In response to this:

/cherry-pick release-1.5

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.

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. area/api Issues or PRs related to the APIs 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.

None yet

4 participants