Skip to content

Fix trace for optional GitRepository.Spec.Reference#1626

Merged
hiddeco merged 2 commits intofluxcd:mainfrom
allenporter:flux-trace
Jul 23, 2021
Merged

Fix trace for optional GitRepository.Spec.Reference#1626
hiddeco merged 2 commits intofluxcd:mainfrom
allenporter:flux-trace

Conversation

@allenporter
Copy link
Contributor

Check for existence of GitRepository.Spec.Reference when displaying a trace to
avoid error:

✗ template: tmpl:28:21: executing "tmpl" at <.GitRepository.Spec.Reference.Tag>: nil pointer evaluating *v1beta1.GitRepositoryRef.Tag

Fixes issue #1621
Manually tested using the use cases highlighted in the issue.

Signed-off-by: Allen Porter allen@thebends.org

@kingdonb
Copy link
Member

Thanks for your contribution!

We will get this reviewed soon 💯

@dholbach dholbach linked an issue Jul 19, 2021 that may be closed by this pull request
Copy link
Member

@squaremo squaremo left a comment

Choose a reason for hiding this comment

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

Thanks @allenporter, first-time contributor high five ✋

Looks reasonable to me. Usually I would like to see a test, to demonstrate the fix and prevent regressions, but for this it might be fiddly to test the relevant bit since it's all embedded in the command-line code.

(I must leave it for a fluxcd/flux2 maintainer to put their stamp to this, and to merge; I've 📣ed them)

@squaremo squaremo requested review from phillebaba and relu July 19, 2021 13:57
Copy link
Member

@relu relu left a comment

Choose a reason for hiding this comment

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

LGTM ✔️

Thanks for your contribution, @allenporter!

@allenporter
Copy link
Contributor Author

Yeah I looked and didn't see obvious existing tests for this, but not sure I am looking for the right thing.

Do you have a pointer of a "starter" test to base this on? I'm generally interested in learning more about the code base for next time.

@relu
Copy link
Member

relu commented Jul 20, 2021

@allenporter indeed there are no tests inside cmd you can refer to, however, you can check the helm cmd tests which are likely a good reference, you'll notice files from the testdata/output directory are used to compare the string output.

Another good reference is kubectl. Hope that helps.

@squaremo
Copy link
Member

@allenporter To be clear, I didn't mean to make tests a requirement for this PR. It would make a great follow-up, though :-D I would start by factoring out helper funcs and writing unit tests for those.

@allenporter
Copy link
Contributor Author

Yes, thanks, understood. This is ready for review/merge.

@hiddeco
Copy link
Member

hiddeco commented Jul 22, 2021

@allenporter if you rebase this branch against main, I am happy to merge it :-)

Check for existence of GitRepository.Spec.Reference when displaying a trace to
avoid error:

✗ template: tmpl:28:21: executing "tmpl" at <.GitRepository.Spec.Reference.Tag>: nil pointer evaluating *v1beta1.GitRepositoryRef.Tag

Fixes issue fluxcd#1621
Manually tested using the use cases highlighted in the issue.

Signed-off-by: Allen Porter <allen@thebends.org>
Signed-off-by: Allen Porter <allen@thebends.org>
@allenporter
Copy link
Contributor Author

Change was rebased, thanks.

@hiddeco
Copy link
Member

hiddeco commented Jul 23, 2021

First-time contributor high-five @allenporter 🥇

@hiddeco hiddeco merged commit 446a367 into fluxcd:main Jul 23, 2021
allenporter added a commit to allenporter/flux2 that referenced this pull request Aug 1, 2021
Add tests for flux trace command that fake out the kubernetes client,
load objects from a yaml file and create them in the client, and
assert on the output of the trace command to an expected golden file.

This is a follow up from the suggestions in PR fluxcd#1626 which suggested that additional
testing would be helpful. This test approach is modeled after the helm command tests.

This required some changes to the kubernetes client setup to make it
possible to use a fake. If we agree this pattern makes sense, it can be
applied to other commands.
allenporter added a commit to allenporter/flux2 that referenced this pull request Aug 1, 2021
Add tests for flux trace command that fake out the kubernetes client,
load objects from a yaml file and create them in the client, and
assert on the output of the trace command to an expected golden file.

This is a follow up from the suggestions in PR fluxcd#1626 which suggested that additional
testing would be helpful. This test approach is modeled after the helm command tests.

This required some changes to the kubernetes client setup to make it
possible to use a fake. If we agree this pattern makes sense, it can be
applied to other commands.

Signed-off-by: Allen Porter <allen@thebends.org>
allenporter added a commit to allenporter/flux2 that referenced this pull request Aug 1, 2021
Add tests for flux trace command that fake out the kubernetes client,
load objects from a yaml file and create them in the client, and
assert on the output of the trace command to an expected golden file.

This is a follow up from the suggestions in PR fluxcd#1626 which suggested that additional
testing would be helpful. This test approach is modeled after the helm command tests.

This required some changes to the kubernetes client setup to make it
possible to use a fake. If we agree this pattern makes sense, it can be
applied to other commands.

Signed-off-by: Allen Porter <allen@thebends.org>
allenporter added a commit to allenporter/flux2 that referenced this pull request Aug 3, 2021
Add tests for flux trace command that fake out the kubernetes client,
load objects from a yaml file and create them in the client, and
assert on the output of the trace command to an expected golden file.

This is a follow up from the suggestions in PR fluxcd#1626 which suggested that additional
testing would be helpful. This test approach is modeled after the helm command tests.

This required some changes to the kubernetes client setup to make it
possible to use a fake. If we agree this pattern makes sense, it can be
applied to other commands.

Signed-off-by: Allen Porter <allen@thebends.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flux trace fails executing template

5 participants