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

🐛 Check to see if custom source implements fmt.Stringer when logging #3068

Merged

Conversation

troy0820
Copy link
Member

@troy0820 troy0820 commented Jan 13, 2025

When using a custom source, the error when starting will fail because the fmt.Stringer interface is not implemented by the source. The builtin sources have already implanted this interface allow the below line to not fail:

log := c.LogConstructor(nil).WithValues("source", watch.String())
fatal error: concurrent map iteration and map write

Resolves #3057

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 13, 2025
@troy0820 troy0820 force-pushed the troy0820/update-source-interface branch from 8ef597e to 707562c Compare January 13, 2025 18:25
@troy0820
Copy link
Member Author

/test pull-controller-runtime-test

@troy0820 troy0820 changed the title 🐛Add String() to Source interface to enforce fmt.Stringer interface ⚠Add String() to Source interface to enforce fmt.Stringer interface Jan 13, 2025
Copy link
Contributor

@dongjiang1989 dongjiang1989 left a comment

Choose a reason for hiding this comment

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

Great. Looks very elegant

@k8s-ci-robot
Copy link
Contributor

@dongjiang1989: changing LGTM is restricted to collaborators

In response to this:

Great. Looks very elegant

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-sigs/prow repository.

@@ -175,7 +175,7 @@ func (c *Controller[request]) Start(ctx context.Context) error {
// caches.
errGroup := &errgroup.Group{}
for _, watch := range c.startWatches {
log := c.LogConstructor(nil).WithValues("source", fmt.Sprintf("%s", watch))
log := c.LogConstructor(nil).WithValues("source", watch.String())
Copy link
Member

Choose a reason for hiding this comment

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

It is an interesting issue - How about rather then requiring the implementation of fmt.Stringer, we check if it is implemented and if yes use that, otherwise use the Type (i.E. fmt.Sprintf("%T", watch))? That way we avoid the breaking change

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 19, 2025
@troy0820 troy0820 changed the title ⚠Add String() to Source interface to enforce fmt.Stringer interface 🐛 Check to see if custom source implements fmt.Stringer when logging Jan 19, 2025
@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jan 19, 2025
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

thanks!

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

LGTM label has been added.

Git tree hash: a414c38213cf8ff7a9d5fe0e187d2c9bfbc50d2d

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, dongjiang1989, troy0820

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 Jan 19, 2025
@k8s-ci-robot k8s-ci-robot merged commit aafb269 into kubernetes-sigs:main Jan 19, 2025
20 checks passed
@troy0820
Copy link
Member Author

/cherry-pick release-0.19

@k8s-infra-cherrypick-robot

@troy0820: #3068 failed to apply on top of branch "release-0.19":

Applying: add String() to source interface
Using index info to reconstruct a base tree...
M	pkg/internal/controller/controller.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/internal/controller/controller.go
CONFLICT (content): Merge conflict in pkg/internal/controller/controller.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 add String() to source interface

In response to this:

/cherry-pick release-0.19

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-sigs/prow repository.

@troy0820
Copy link
Member Author

/cherry-pick release-0.20

@k8s-infra-cherrypick-robot

@troy0820: new pull request created: #3077

In response to this:

/cherry-pick release-0.20

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-sigs/prow 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. 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

concurrency errors when printing source.TypedSource
5 participants