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

✨Add clusterctl options to show templates and cluster resource sets #5762

Merged
merged 1 commit into from Apr 14, 2022

Conversation

Jont828
Copy link
Contributor

@Jont828 Jont828 commented Dec 1, 2021

What this PR does / why we need it: This PR adds additional options to the Discovery client for clusterctl describe. These changes are meant to (1) allow the command to show all resources associated with the cluster and (2) allow the client to construct a tree that can be used as an input for a separate Cluster API GUI.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 1, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @Jont828. 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 1, 2021
@sbueringer
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 Dec 1, 2021
@Jont828
Copy link
Contributor Author

Jont828 commented Dec 1, 2021

Actually we can hold this for now, I'm still trying to see if I can add some other features and also clean up some of the code.

/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 Dec 1, 2021
@fabriziopandini
Copy link
Member

@ykakarap

@ykakarap
Copy link
Contributor

ykakarap commented Dec 1, 2021

/cc

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 9, 2021
@Jont828 Jont828 force-pushed the tree-hacks branch 2 times, most recently from 7c685e1 to eefd1f2 Compare December 21, 2021 21:29
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 21, 2021
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.

Given this is still WIP, feel free to ignore comments

cmd/clusterctl/client/cluster/proxy.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/multicluster_discovery.go Outdated Show resolved Hide resolved
@Jont828 Jont828 force-pushed the tree-hacks branch 2 times, most recently from 8a9fa99 to dff76ce Compare January 19, 2022 17:56
@Jont828 Jont828 force-pushed the tree-hacks branch 3 times, most recently from c08f88d to b43f4ee Compare January 26, 2022 00:16
@Jont828 Jont828 changed the title ✨Add additional options to Discovery for clusterctl describe [WIP] ✨Add additional options to Discovery for clusterctl describe Jan 26, 2022
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.

A couple of comments, mostly for

  • better understanding the use case you are trying to address
  • avoid mixing semantics of flags/flags with semantics too generic
  • avoid to load too many objects at T0 (we can consider incremental loading if it makes sense)

cmd/clusterctl/client/cluster/proxy.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
@@ -93,37 +106,110 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt

if visible {
if machineInfra, err := external.Get(ctx, c, &m.Spec.InfrastructureRef, cluster.Namespace); err == nil {
tree.Add(m, machineInfra, ObjectMetaName("MachineInfrastructure"), NoEcho(true))
tree.Add(m, machineInfra, ObjectMetaName("MachineInfrastructure"), NoEcho(!options.Echo))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabriziopandini Do you think we'd want to add a placeholder unstructured object in this case as well?

Copy link
Member

Choose a reason for hiding this comment

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

might be in a followUp PR, let's keep this one scoped (it is already adding a bunch of flag in the same changeset)

}
tree.Add(workers, mp, addOpts...)

if options.ShowTemplates {
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 could probably add a "ShowMachinePools" flag similar to "ShowMachineSets" and replicate the behavior once MachinePoolMachines are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually we might not need that at all since we have --echo and --grouping=false already

@killianmuldoon
Copy link
Contributor

Are there any assumptions that we can make about the name/location of the infrastructureRef/infrastructureTemplate in control planes? While the contents of unstructured.Unstructured types are being used for provider specific info, I think it's still useful to include the machine template for the control plane in the output.

If I get you the assumptions you can make are part of the contract e.g. for spec fields: https://cluster-api.sigs.k8s.io/developer/architecture/controllers/control-plane.html#required-spec-fields-for-implementations-using-machines. So you should have machineTemplate.infrastructureRef

e.g. a control plane on my dev cluster has the spec:

  spec:
    kubeadmConfigSpec:
      clusterConfiguration:
        apiServer:
          certSANs:
          - localhost
          - 127.0.0.1
          - 0.0.0.0
        controllerManager:
          extraArgs:
            enable-hostpath-provisioner: "true"
        dns: {}
        etcd:
          local: {}
        imageRepository: k8s.gcr.io
        networking: {}
        scheduler: {}
      format: cloud-config
      initConfiguration:
        localAPIEndpoint: {}
        nodeRegistration:
          criSocket: unix:///var/run/containerd/containerd.sock
          kubeletExtraArgs:
            cgroup-driver: cgroupfs
            eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%
      joinConfiguration:
        discovery: {}
        nodeRegistration:
          criSocket: unix:///var/run/containerd/containerd.sock
          kubeletExtraArgs:
            cgroup-driver: cgroupfs
            eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%
    machineTemplate:
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: DockerMachineTemplate
        name: cloister-control-plane-lmbll
        namespace: default
      metadata:
        labels:
          cluster.x-k8s.io/cluster-name: cloister
          topology.cluster.x-k8s.io/owned: ""
    replicas: 3
    rolloutStrategy:
      rollingUpdate:
        maxSurge: 1
      type: RollingUpdate
    version: v1.21.2

@killianmuldoon
Copy link
Contributor

@Jont828 I think the spec.infrastructureTemplate variant is the way things were with the v1alpha3 API. I just created a PR #6392 to update the example in the book - did you see that structure used somewhere else? Maybe we need an update in clusterctl code too.

@Jont828
Copy link
Contributor Author

Jont828 commented Apr 7, 2022

@killianmuldoon Yeah I'm seeing the spec.infrastructureTemplate field in internal fake types here. In that case is it safe to assume that we will update the fake control plane type?

@ykakarap
Copy link
Contributor

ykakarap commented Apr 8, 2022

@ykakarap @fabriziopandini So I looked into adding tests but it seems like I found an small issue. Kubeadmcontrolplanes have the infrastructureRef field in spec.machineTemplate.infrastructureRef while our fake controlPlane has the field in spec.infrastuctureTemplate.

Are there any assumptions that we can make about the name/location of the infrastructureRef/infrastructureTemplate in control planes? While the contents of unstructured.Unstructured types are being used for provider specific info, I think it's still useful to include the machine template for the control plane in the output.

The infrastructureRef path is different in the real and the GenericControlPlane type. GenericControlPlane most likely is structured like that for historical reasons to match with v1alpha3 types. Changing GenericControlPlaneSpec to :

// GenericMachineTemplate contains the generic machine template.
type GenericMachineTemplate struct {
	InfrastructureRef corev1.ObjectReference `json:"infrastructureRef"`
}

// GenericControlPlaneSpec contains a generic control plane spec.
type GenericControlPlaneSpec struct {
	MachineTemplate GenericMachineTemplate `json:"machineTemplate"`
}

should be fine. I believe it will not affect any of the other tests (I have tested this locally) as all others tests that use GenericControlPlane primarily look for values in ownerReferences and will not be affected by this path.

PS: You will have to run make generate-go-deepcopy-core after making the change to generate deep copy functions for the modified type.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 8, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Apr 9, 2022

@ykakarap Sounds good, I wrote some tests, including the edge case you found with having two machine deployments. I tagged Fabrizio in a minor comment about the test cases, but otherwise I think we should be good for a final review pass.

@Jont828 Jont828 force-pushed the tree-hacks branch 2 times, most recently from e463824 to c2af91e Compare April 11, 2022 19:21
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.

I have tested this locally and it works great!
please fix lint errors and remove the hold, IMO we are ready to merge!

cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
@fabriziopandini
Copy link
Member

/lgtm
/hold cancel
waiting for the last check from @ykakarap if he can get to it

@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 Apr 12, 2022
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 12, 2022
Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

Tested locally and everything seems to bo working as expected.

This is great work @Jont828 🚀
Thanks for doing this!

Just small nits (non-blocking).

/lgtm

cmd/clusterctl/client/tree/util.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery_test.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 12, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Apr 12, 2022

Just pushed some changes to fix the nits. Huge shoutout to @fabriziopandini for tons of feedback and design suggestions!

Copy link
Contributor

@ykakarap ykakarap 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 "Looks good to me", indicates that a PR is ready to be merged. label Apr 13, 2022
@fabriziopandini
Copy link
Member

/lgtm
/approve
Yay!

@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 Apr 14, 2022
@k8s-ci-robot k8s-ci-robot merged commit 61c9e21 into kubernetes-sigs:main Apr 14, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Apr 14, 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. 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.

None yet

7 participants