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

hotfix: return error instead of log at FromMapAndOption #5381

Merged
merged 10 commits into from Oct 27, 2023

Conversation

chansuke
Copy link
Member

@chansuke chansuke commented Oct 12, 2023

Make FromMapAndOption to return error.

@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 12, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @chansuke!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 12, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @chansuke. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 12, 2023
@DiptoChakrabarty
Copy link
Member

also seems like the tests are failing can you go ahead and fix them

koba1t
koba1t previously requested changes Oct 14, 2023
Copy link
Member

@koba1t koba1t left a comment

Choose a reason for hiding this comment

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

I think we should avoid the fatal function.
But we are currently using log.Fatal(), and we can fix it with the next PR.
https://github.com/kubernetes-sigs/kustomize/pull/5381/files#diff-9041e805f414eb549e8ebcf4f2b82c1f40403e3ebe86a1f67f9c76718bd91797L65

I think this PR is moving forward to the first step and is useful for kustomize.

@chansuke
Thanks for your contribution!
I added any comments, Could you check it?

err = expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash))
config, err := makeConfigMapOptions(rf, name, c.behavior, !c.needsHash)
if err != nil {
t.Errorf("unexpected error: %v", err)
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 the unexpected error message is confusing.
Could you add any meaningful message?

}))
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

same here

}))
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

same too

assert.NoError(t, w.AbsorbAll(makeMap2(types.BehaviorMerge)))
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

same too

Comment on lines 908 to 907
err = w.AbsorbAll(w2)
assert.Error(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

If you can, Could you summarize it in one line?

return rf.FromMapAndOption(m, nil)
res, err := rf.FromMapAndOption(m, nil)
if err != nil {
log.Fatal("Option must not be null")
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this line abandoned a non-nil error.
Could you make a change to print the substance of the returned error?

r := rf.FromMapAndOption(m, nil)
r, err := rf.FromMapAndOption(m, nil)
if err != nil {
log.Fatal("Option must not be null")
Copy link
Member

Choose a reason for hiding this comment

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

same here

@chansuke
Copy link
Member Author

@koba1t I appreciate your feedback and review! I will go fix them.

@chansuke
Copy link
Member Author

@koba1t I've addressed your comments and made the necessary changes. Please take a look 🙏
And I'd like to work on this in the next PR if it's possible 🙇

I think we should avoid the fatal function.
But we are currently using log.Fatal(), and we can fix it with the next PR.

@chansuke chansuke requested a review from koba1t October 15, 2023 05:29
@natasha41575
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 Oct 16, 2023
@koba1t
Copy link
Member

koba1t commented Oct 17, 2023

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Oct 17, 2023
@koba1t
Copy link
Member

koba1t commented Oct 17, 2023

@chansuke

Thanks for the fix!
Looks good for me!

/lgtm

@natasha41575
Would you like to review this PR, or do you have any opinions?
In the meantime, I look forward to your reply.

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

@koba1t Thanks! I'll take a look on friday

return rf.FromMapAndOption(m, nil)
res, err := rf.FromMapAndOption(m, nil)
if err != nil {
log.Fatalf("failed to create resource from map: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the idea of the TODO was to return the error all the way to the top, e.g. completely avoid the use of log.Fatalf for this. That would mean FromMap and FromMapWithNamespaceAndName should the error, instead of doing log.Fatalf here, and likewise all the way up.

Looks like you and @koba1t already had a discussion about potentially doing that in a follow-up PR. I think that's fine to do in a followup, but in that case could we keep the TODO here?

if err != nil {
		// TODO: return err instead of log.
		log.Fatalf("failed to create resource from map: %v", err)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@natasha41575 Thank you for the review. Yes, I will put the TODO comment again

r := rf.FromMapAndOption(m, nil)
r, err := rf.FromMapAndOption(m, nil)
if err != nil {
log.Fatalf("failed to create resource from map: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 21, 2023
@chansuke
Copy link
Member Author

@natasha41575 Updated the code. Please take a look.

Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 27, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chansuke, natasha41575

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

@natasha41575 natasha41575 dismissed koba1t’s stale review October 27, 2023 20:35

LGTM was given above

@k8s-ci-robot k8s-ci-robot merged commit e002b49 into kubernetes-sigs:master Oct 27, 2023
9 checks passed
antoooks pushed a commit to antoooks/kustomize that referenced this pull request Nov 21, 2023
…-sigs#5381)

* hotfix: return error instead of log at `FromMapAndOption`

* chore: show error message

* hotfix: use correct function

* hotix: use `t.Helper()` and fix `t *testing.T order

* hotfix: wrapt the error of `FromMapAndOption`

* hotfix: meaningful message for an error

* hotfix: summarize in one line

* hotfix: fix the abandoned error and show meaningful message

* hotfix: start with helper function

* Keep TODO comment
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/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Development

Successfully merging this pull request may close these issues.

None yet

5 participants