Skip to content

Conversation

@sjberman
Copy link
Collaborator

@sjberman sjberman commented Dec 3, 2025

Problem: When provisioning the NGINX Service, if the Gateway name was very long, it could result in a failure to create the Service. A Service name must be 63 characters or less. This also could affect the shadow Service that we create for InferencePools if the InferencePool name is long.

Solution: If the name of the resource that we create is going to be over the max, create a hash of the name and truncate to ensure that it is less than the max. The suffix is still included, since we rely on that for certain resources. Just the prefix is shortened as necessary to include the hash.

Testing: Deployed a Gateway with a very long name and verified that the Service was still created properly. Also did the same test with an InferencePool.

Closes #4177

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Fix a bug where NGINX Service could not be created if the Gateway name was very long.

@sjberman sjberman requested a review from a team as a code owner December 3, 2025 18:59
@github-actions github-actions bot added the bug Something isn't working label Dec 3, 2025
@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.15%. Comparing base (6fba1e3) to head (b1b0188).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/controller/provisioner/handler.go 0.00% 3 Missing and 3 partials ⚠️
internal/controller/provisioner/objects.go 25.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4387   +/-   ##
=======================================
  Coverage   86.15%   86.15%           
=======================================
  Files         132      132           
  Lines       14359    14376   +17     
  Branches       35       35           
=======================================
+ Hits        12371    12386   +15     
+ Misses       1785     1781    -4     
- Partials      203      209    +6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sjberman sjberman requested a review from Copilot December 3, 2025 19:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue where Services could fail to be created when the Gateway or InferencePool names were very long, exceeding the Kubernetes 63-character limit for Service names. The solution implements name truncation with hash-based uniqueness preservation.

Key Changes:

  • Implements truncateAndHashName function that truncates long resource names and adds an 8-character hash for uniqueness while preserving required suffixes
  • Replaces GetInferencePoolName function with InferencePoolName field in RouteBackendRef struct to avoid recreating pool names from service names
  • Adds comprehensive tests for name truncation logic

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/framework/controller/resource.go Implements new truncation logic with hash generation for resource names exceeding 63 characters
internal/framework/controller/resource_test.go Adds comprehensive unit tests for name truncation scenarios
internal/controller/state/graph/route_common.go Adds InferencePoolName field to RouteBackendRef struct
internal/controller/state/graph/httproute.go Updates to populate and use new InferencePoolName field
internal/controller/state/graph/inferencepools.go Uses InferencePoolName field instead of deriving from service name
internal/controller/state/graph/backend_refs.go Uses InferencePoolName field instead of deriving from service name
internal/controller/state/graph/*_test.go Updates test data to include InferencePoolName field
internal/controller/provisioner/objects.go Truncates gateway name when used as label value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added the tests Pull requests that update tests label Dec 3, 2025
@sjberman sjberman force-pushed the bug/max-service-name-len branch from b874551 to 279bea5 Compare December 3, 2025 21:33
Problem: When provisioning the NGINX Service, if the Gateway name was very long, it could result in a failure to create the Service. A Service name must be 63 characters or less. This also could affect the shadow Service that we create for InferencePools if the InferencePool name is long.

Solution: If the name of the resource that we create is going to be over the max, create a hash of the name and truncate to ensure that it is less than the max. The suffix is still included, since we rely on that for certain resources. Just the prefix is shortened as necessary to include the hash.
@sjberman sjberman force-pushed the bug/max-service-name-len branch from 279bea5 to 82767ae Compare December 3, 2025 21:33
@github-actions github-actions bot removed the tests Pull requests that update tests label Dec 3, 2025
@sjberman sjberman enabled auto-merge (squash) December 4, 2025 16:57
@sjberman sjberman merged commit a1afc9d into main Dec 4, 2025
60 of 61 checks passed
@sjberman sjberman deleted the bug/max-service-name-len branch December 4, 2025 18:18
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in NGINX Gateway Fabric Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release-notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Validate Data Plane resources name length

4 participants