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

🐛 handle nil pointer in clusterctl describe #8724

Conversation

bavarianbidi
Copy link
Contributor

What this PR does / why we need it:

if a cluster as an empy bootstrap.configref in the machinedeployment (which is allowed), a nil pointer will raise if clusterctl describe cluster is called with --show-templates.

Also add a second type of a fake machinedeployment which has a secret reference in the boostrap object instead of a config ref

/*
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x19478c0]

goroutine 1 [running]:
sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree.ObjectReferenceObject(0x0)
        sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree/util.go:116 +0x40
sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree.addMachineDeploymentToObjectTree({0x2153e90, 0xc000120008}, {0x215ebf8, 0xc0002ca770}, 0xc000c336c0, 0xc000c336c0?, 0x2171100?, 0xc0009e2200, {{0x7fffd7f57514, 0x3}, ...}, ...)
        sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree/discovery.go:244 +0x35b
sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree.Discovery({0x2153e90, 0xc000120008}, {0x215ebf8?, 0xc0002ca770?}, {0x7fffd7f574f3, 0xe}, {0x7fffd7f574eb, 0x4}, {{0x7fffd7f57514, 0x3}, ...})
        sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree/discovery.go:145 +0x94c
sigs.k8s.io/cluster-api/cmd/clusterctl/client.(*clusterctlClient).DescribeCluster(0x0?, {{{0x0, 0x0}, {0x0, 0x0}}, {0x7fffd7f574f3, 0xe}, {0x7fffd7f574eb, 0x4}, {0x7fffd7f57514, ...}, ...})
        sigs.k8s.io/cluster-api/cmd/clusterctl/client/describe.go:91 +0x218
sigs.k8s.io/cluster-api/cmd/clusterctl/cmd.runDescribeCluster(0x0?, {0x7fffd7f574eb, 0x4})
        sigs.k8s.io/cluster-api/cmd/clusterctl/cmd/describe_cluster.go:154 +0x1d8
sigs.k8s.io/cluster-api/cmd/clusterctl/cmd.glob..func6(0x31aae60?, {0xc00018af80?, 0x8?, 0x8?})
        sigs.k8s.io/cluster-api/cmd/clusterctl/cmd/describe_cluster.go:105 +0x2d
github.com/spf13/cobra.(*Command).execute(0x31aae60, {0xc00018af00, 0x8, 0x8})
        github.com/spf13/cobra@v1.7.0/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0x31ad980)
        github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.7.0/command.go:992
sigs.k8s.io/cluster-api/cmd/clusterctl/cmd.Execute()
        sigs.k8s.io/cluster-api/cmd/clusterctl/cmd/root.go:105 +0x25
main.main()
        sigs.k8s.io/cluster-api/cmd/clusterctl/main.go:27 +0x17
*/

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 #

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 23, 2023
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 23, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @bavarianbidi. 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 area/clusterctl Issues or PRs related to clusterctl label May 23, 2023
@killianmuldoon
Copy link
Contributor

/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 May 23, 2023
@killianmuldoon
Copy link
Contributor

Second time I've seen this flake where the env cleanup fails 🤔

@bavarianbidi bavarianbidi force-pushed the handle_empty_boostrap_configref branch from f2eec62 to c79417b Compare May 23, 2023 11:40
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.

The nil check makes sense.

I will do another pass and will take a closer look at the updated tests.

@bavarianbidi
Copy link
Contributor Author

The nil check makes sense.

I will do another pass and will take a closer look at the updated tests.

Thank you.

In the end, i just copied the FakeMachineDeployment generation to create another md where the bootstrap.configref is nil and a secret is used.
Wherever the origin FakeMachineDeployment was used in the test, i've added an additional test-case (or extended an existing one) to make use of the newly generated fake md as well.

cmd/clusterctl/client/tree/discovery_test.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
cmd/clusterctl/client/tree/discovery_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/internal/test/fake_objects.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/objectgraph_test.go Outdated Show resolved Hide resolved
@bavarianbidi bavarianbidi force-pushed the handle_empty_boostrap_configref branch from ba83907 to 8236791 Compare June 1, 2023 12:40
@bavarianbidi bavarianbidi force-pushed the handle_empty_boostrap_configref branch from 8236791 to 946db30 Compare June 2, 2023 09:42
if a cluster as an empy bootstrap.configref in the machinedeployment
(which is allowed), a nil pointer will raise if clusterctl describe
cluster is called with --show-templates.

Also add a second type of a fake machinedeployment which has a secret
reference in the boostrap object instead of a config ref

Signed-off-by: Mario Constanti <mario@constanti.de>
@bavarianbidi bavarianbidi force-pushed the handle_empty_boostrap_configref branch from 946db30 to 5adeb34 Compare June 12, 2023 07:38
@fabriziopandini
Copy link
Member

thanks for this PR
/lgtm

@ykakarap @Jont828 for a final pass

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

LGTM label has been added.

Git tree hash: 31658f380bfe7f2f907d573d5b300afc2ed5e99e

@bavarianbidi
Copy link
Contributor Author

@ykakarap / @Jont828 any chance to get this merged soon or do you want me to add something more?

@sbueringer
Copy link
Member

Thank you very much. Very nice test coverage!!

/lgtm
/approve

@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 Jun 27, 2023
@k8s-ci-robot k8s-ci-robot merged commit 520d7ba into kubernetes-sigs:main Jun 27, 2023
10 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.5 milestone Jun 27, 2023
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/clusterctl Issues or PRs related to clusterctl 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/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

6 participants