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

fix: panic in consumer sort func #1658

Merged
merged 3 commits into from
Aug 5, 2021
Merged

fix: panic in consumer sort func #1658

merged 3 commits into from
Aug 5, 2021

Conversation

shaneutt
Copy link
Contributor

@shaneutt shaneutt commented Aug 4, 2021

What this PR does / why we need it:

Small fix to prevent a panic when an empty username is given for a KongConsumer.

Which issue this PR fixes

Fixes #550

PR Readiness Checklist:

  • the CHANGELOG.md release notes have been updated to reflect any significant (and particularly user-facing) changes introduced by this PR

@shaneutt shaneutt added bug Something isn't working priority/medium labels Aug 4, 2021
@shaneutt shaneutt self-assigned this Aug 4, 2021
@shaneutt shaneutt marked this pull request as ready for review August 4, 2021 19:18
@shaneutt shaneutt requested a review from a team as a code owner August 4, 2021 19:18
@shaneutt shaneutt linked an issue Aug 4, 2021 that may be closed by this pull request
@shaneutt shaneutt enabled auto-merge (rebase) August 4, 2021 19:18
@codecov
Copy link

codecov bot commented Aug 4, 2021

Codecov Report

Merging #1658 (1525cf9) into next (f79e8ee) will decrease coverage by 0.14%.
The diff coverage is 0.00%.

❗ Current head 1525cf9 differs from pull request most recent head 18f5548. Consider uploading reports for the commit 18f5548 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             next    #1658      +/-   ##
==========================================
- Coverage   62.11%   61.96%   -0.15%     
==========================================
  Files          83       83              
  Lines        7319     7330      +11     
==========================================
- Hits         4546     4542       -4     
- Misses       2440     2454      +14     
- Partials      333      334       +1     
Flag Coverage Δ
integration-test 61.96% <0.00%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/deckgen/generate.go 47.39% <0.00%> (-3.22%) ⬇️
internal/ctrlutils/ingress-status.go 48.67% <0.00%> (-1.21%) ⬇️
internal/ctrlutils/utils.go 88.46% <0.00%> (+1.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f79e8ee...18f5548. Read the comment docs.

@rainest
Copy link
Contributor

rainest commented Aug 4, 2021

Does this indeed prevent all panics when submitting a no-username consumer? IIRC the deck code further down also panicked when we gave it one, so fixing the sort mechanism will just result in a panic at a different point in the code.

Instead, we probably want something like what we do for credentials missing required fields: if we know they will break later, we just log that they're invalid and don't add them to the list. That's ideally accompanied by an admission controller rule to reject them in the client, since logging alone isn't the most obvious UX.

If we do proceed with something like Kong/deck#246 eventually we will still want the sort in the controller to work properly, so a sort fix will future proof for that even if it's a no-op if we just drop no-username consumers for the time being. However, it should probably concatenate Username+CustomID rather than have a blanket behavior for any no-username consumer: you can have multiple no-username consumers with distinct custom IDs, and those consumers should sort consistently.

@shaneutt shaneutt marked this pull request as draft August 4, 2021 20:53
auto-merge was automatically disabled August 4, 2021 20:53

Pull request was converted to draft

@shaneutt
Copy link
Contributor Author

shaneutt commented Aug 4, 2021

Yep you were right @rainest: my first attempt here was assuming that the consumer would be handled gracefully at the deck level, but after digging into that further it would panic there also.

Check out this new patch instead 👍

@shaneutt shaneutt marked this pull request as ready for review August 4, 2021 21:37
Copy link
Contributor

@rainest rainest left a comment

Choose a reason for hiding this comment

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

Ideally this would include an admission controller rule also, but eh, probably still worth avoiding the panic even without.

There's one remaining change that should probably go in; I'm pretty sure the IDs here aren't ever of use.

Co-authored-by: Travis Raines <traines@konghq.com>
@shaneutt shaneutt disabled auto-merge August 5, 2021 03:42
@shaneutt shaneutt enabled auto-merge (squash) August 5, 2021 03:42
@shaneutt shaneutt merged commit 8405d26 into next Aug 5, 2021
@shaneutt shaneutt deleted the issue-550 branch August 5, 2021 03:56
@rainest rainest mentioned this pull request Aug 27, 2021
rainest pushed a commit that referenced this pull request Sep 30, 2021
* fix: panic in deckgen with nil consumer username
* docs: update CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KongConsumer without username crashes KIC
2 participants