generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 182
cleanup: make port definitions symmetric and clean endpointPickerRef.port #1484
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
k8s-ci-robot
merged 11 commits into
kubernetes-sigs:main
from
capri-xiyue:capri-xiyue/clean-up-ports
Aug 28, 2025
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
91dca8d
make port definitions symmetric
capri-xiyue b2c12ff
fixed linter
capri-xiyue 1716d2f
change spec
capri-xiyue ca703a4
clean comment
capri-xiyue ca3d9dd
fixed port
capri-xiyue 6195211
change port default
capri-xiyue d9cbca5
fixed test
capri-xiyue 6c5bf6a
draft cel test
capri-xiyue f45de61
added cel test
capri-xiyue da4a889
Update api/v1/inferencepool_types.go
capri-xiyue e58d830
updated test
capri-xiyue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1" | ||
) | ||
|
||
func TestValidateInferencePool(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
// baseInferencePool is a valid, InferencePool resource. | ||
baseInferencePool := v1.InferencePool{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "base-pool", | ||
Namespace: metav1.NamespaceDefault, | ||
}, | ||
Spec: v1.InferencePoolSpec{ | ||
TargetPorts: []v1.Port{ | ||
{Number: 8000}, | ||
}, | ||
Selector: v1.LabelSelector{ | ||
MatchLabels: map[v1.LabelKey]v1.LabelValue{ | ||
"app": "model-server", | ||
}, | ||
}, | ||
EndpointPickerRef: v1.EndpointPickerRef{ | ||
Name: "epp", | ||
Kind: "Service", | ||
Port: ptrTo(v1.Port{Number: 9002}), | ||
}, | ||
}, | ||
} | ||
|
||
testCases := []struct { | ||
desc string | ||
mutate func(ip *v1.InferencePool) | ||
wantErrors []string | ||
}{ | ||
{ | ||
desc: "passes validation with a valid configuration", | ||
mutate: func(ip *v1.InferencePool) { | ||
}, | ||
wantErrors: nil, | ||
}, | ||
{ | ||
desc: "fails validation when kind is unset (defaults to Service) and port is missing", | ||
mutate: func(ip *v1.InferencePool) { | ||
// By setting Kind to an empty string, we rely on the API server's default value of "Service". | ||
ip.Spec.EndpointPickerRef.Kind = "" | ||
ip.Spec.EndpointPickerRef.Name = "vllm-llama3-8b-instruct-epp" | ||
ip.Spec.EndpointPickerRef.Port = nil | ||
}, | ||
wantErrors: []string{"port is required when kind is 'Service' and unset(default to 'Service')"}, | ||
}, | ||
{ | ||
desc: "fails validation when kind is explicitly 'Service' and port is missing", | ||
mutate: func(ip *v1.InferencePool) { | ||
ip.Spec.EndpointPickerRef.Kind = "Service" | ||
ip.Spec.EndpointPickerRef.Name = "vllm-llama3-8b-instruct-epp" | ||
ip.Spec.EndpointPickerRef.Port = nil | ||
}, | ||
wantErrors: []string{"port is required when kind is 'Service' and unset(default to 'Service')"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
ip := baseInferencePool.DeepCopy() | ||
// Use a unique name for each test case to avoid conflicts. | ||
ip.Name = fmt.Sprintf("test-pool-%v", time.Now().UnixNano()) | ||
|
||
if tc.mutate != nil { | ||
tc.mutate(ip) | ||
} | ||
err := k8sClient.Create(ctx, ip) | ||
|
||
// This is a boolean XOR. It's true if one is true, but not both. | ||
// It ensures that an error is returned if and only if we expect one. | ||
if (len(tc.wantErrors) != 0) != (err != nil) { | ||
t.Fatalf("Unexpected response while creating InferencePool; got err=\n%v\n; want error=%v", err, tc.wantErrors != nil) | ||
} | ||
|
||
// If we got an error, check that it contains the expected substrings. | ||
var missingErrorStrings []string | ||
for _, wantError := range tc.wantErrors { | ||
if !celErrorStringMatches(err.Error(), wantError) { | ||
missingErrorStrings = append(missingErrorStrings, wantError) | ||
} | ||
} | ||
if len(missingErrorStrings) != 0 { | ||
t.Errorf("Unexpected response while creating InferencePool; got err=\n%v\n; missing strings within error=%q", err, missingErrorStrings) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.