Skip to content

fix(targets) deduplicate nil-weight targets #5946

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

Merged
merged 1 commit into from
Apr 29, 2024
Merged

Conversation

rainest
Copy link
Contributor

@rainest rainest commented Apr 27, 2024

What this PR does / why we need it:

Assume the Kong default 100 weight for targets that have nil weight when being deduplicated.

Which issue this PR fixes:

#5817 results in a segfault if deduplicated targets have no weight. I'm not sure if this happens in other cases, but it definitely happens for multi-replica Services that use the service-upstream annotation. We generate multiple targets all with the same Service hostname for service-upstream, which is maybe a bit silly, but I saw no reason to change it and wanted to make sure we cover any other situations that may generate nil-weight targets.

See segfault.txt for the fault. https://github.com/Kong/go-echo/blob/main/example_deploy.yaml will trigger it in current nightly.

Special notes for your reviewer:

I cannibalized TestIngressNamespaces() to test service-upstream in general. service-upstream is common enough (most mesh users, AFAIK) and we apparently never had an integration test that utilized it.

While looking for a test I could maybe slot it into, I discovered that a test added long long ago was no longer really testing anything in particular due to refactors elsewhere, so I have repurposed it into the service-upstream test.

The thing it was originally testing is mostly irrelevant, since we were mostly re-testing functionality built into controller-runtime.

PR Readiness Checklist:

Complete these before marking the PR as ready to review:

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

@rainest rainest requested a review from a team as a code owner April 27, 2024 00:14
@rainest rainest enabled auto-merge (squash) April 27, 2024 00:15
Copy link

codecov bot commented Apr 27, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@b014561). Click here to learn what that means.

❗ Current head f169cfe differs from pull request most recent head f6eadd4. Consider uploading reports for the commit f6eadd4 to get more accurate results

Files Patch % Lines
...ternal/dataplane/translator/translate_upstreams.go 80.0% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##             main   #5946   +/-   ##
======================================
  Coverage        ?   67.3%           
======================================
  Files           ?     179           
  Lines           ?   18304           
  Branches        ?       0           
======================================
  Hits            ?   12327           
  Misses          ?    5032           
  Partials        ?     945           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@randmonkey
Copy link
Contributor

randmonkey commented Apr 27, 2024

#5848
I see #5817 is backported to release/3.1.x and included in 3.1.3 and 3.1.4 releases.
I tried to deploy the services in https://github.com/Kong/go-echo/blob/main/example_deploy.yaml and an ingress pointing to 2 different port of the service and I did not reproduce the crash. @rainest can you test if it affects these versions, and provide a more detailed reproduce enviroment?

@rainest
Copy link
Contributor Author

rainest commented Apr 29, 2024

@randmonkey hmm, that's annoying, I guess there's no way to tell backports from the commit data.

The echo manifest lacks the ingress.kubernetes.io/service-upstream: "true" Service annotation necessary to trigger this. Not sure where I added that, but it's the missing piece. This does indeed occur on 3.1.x.

Assume the Kong default 100 weight for targets that have nil weight when
being deduplicated.
@rainest rainest force-pushed the fix/upstream-segfault branch from f6eadd4 to 5539522 Compare April 29, 2024 18:21
@rainest rainest merged commit b8f7eb5 into main Apr 29, 2024
@rainest rainest deleted the fix/upstream-segfault branch April 29, 2024 20:04
@team-k8s-bot
Copy link
Collaborator

The backport to release/3.1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release/3.1.x release/3.1.x
# Navigate to the new working tree
cd .worktrees/backport-release/3.1.x
# Create a new branch
git switch --create backport-5946-to-release/3.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b8f7eb54420592f8ada2078082cb49170cf364e0
# Push it to GitHub
git push --set-upstream origin backport-5946-to-release/3.1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release/3.1.x

Then, create a pull request where the base branch is release/3.1.x and the compare/head branch is backport-5946-to-release/3.1.x.

randmonkey pushed a commit that referenced this pull request May 15, 2024
Assume the Kong default 100 weight for targets that have nil weight when
being deduplicated.

(cherry picked from commit b8f7eb5)
randmonkey added a commit that referenced this pull request May 15, 2024
* fix(targets) deduplicate nil-weight targets (#5946)

Assume the Kong default 100 weight for targets that have nil weight when
being deduplicated.

(cherry picked from commit b8f7eb5)

* add changelog entry

---------

Co-authored-by: Travis Raines <[email protected]>
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.

4 participants