Skip to content

Commit f45de61

Browse files
committed
added cel test
1 parent 6c5bf6a commit f45de61

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

api/v1/inferencepool_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type Port struct {
9696

9797
// EndpointPickerRef specifies a reference to an Endpoint Picker extension and its
9898
// associated configuration.
99-
// +kubebuilder:validation:XValidation:rule="self.kind != 'Service' || has(self.port)",message="port is required when kind is 'Service'"
99+
// +kubebuilder:validation:XValidation:rule="self.kind != 'Service' || has(self.port)",message="port is required when kind is 'Service' and unset(default to 'Service')"
100100
type EndpointPickerRef struct {
101101
// Group is the group of the referent API object. When unspecified, the default value
102102
// is "", representing the Core API group.

apix/v1alpha2/inferencepool_conversion_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/google/go-cmp/cmp"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
2425
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
2526
)
2627

config/crd/bases/inference.networking.k8s.io_inferencepools.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ spec:
113113
- name
114114
type: object
115115
x-kubernetes-validations:
116-
- message: port is required when kind is 'Service'
116+
- message: port is required when kind is 'Service' and unset(default
117+
to 'Service')
117118
rule: self.kind != 'Service' || has(self.port)
118119
selector:
119120
description: |-

test/cel/inferencepool_test.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ import (
2323
"time"
2424

2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26-
"sigs.k8s.io/gateway-api-inference-extension/api/v1"
26+
27+
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
2728
)
2829

2930
func TestValidateInferencePool(t *testing.T) {
3031
ctx := context.Background()
3132

32-
// baseInferencePool is a valid, minimal InferencePool resource.
33-
// We use a non-Service kind for the picker to ensure the base object is valid
34-
// without needing a port, making it a neutral starting point for mutations.
33+
// baseInferencePool is a valid, InferencePool resource.
3534
baseInferencePool := v1.InferencePool{
3635
ObjectMeta: metav1.ObjectMeta{
3736
Name: "base-pool",
@@ -43,13 +42,13 @@ func TestValidateInferencePool(t *testing.T) {
4342
},
4443
Selector: v1.LabelSelector{
4544
MatchLabels: map[v1.LabelKey]v1.LabelValue{
46-
"app": "my-model-server",
45+
"app": "model-server",
4746
},
4847
},
4948
EndpointPickerRef: v1.EndpointPickerRef{
5049
Name: "epp",
5150
Kind: "Service",
52-
Port: ptrTo(v1.Port{Number: 9000}),
51+
Port: ptrTo(v1.Port{Number: 9002}),
5352
},
5453
},
5554
}
@@ -59,6 +58,12 @@ func TestValidateInferencePool(t *testing.T) {
5958
mutate func(ip *v1.InferencePool)
6059
wantErrors []string
6160
}{
61+
{
62+
desc: "passes validation with a valid configuration",
63+
mutate: func(ip *v1.InferencePool) {
64+
},
65+
wantErrors: nil,
66+
},
6267
{
6368
desc: "fails validation when kind is unset (defaults to Service) and port is missing",
6469
mutate: func(ip *v1.InferencePool) {
@@ -67,7 +72,7 @@ func TestValidateInferencePool(t *testing.T) {
6772
ip.Spec.EndpointPickerRef.Name = "vllm-llama3-8b-instruct-epp"
6873
ip.Spec.EndpointPickerRef.Port = nil
6974
},
70-
wantErrors: []string{"port is required when kind is 'Service'"},
75+
wantErrors: []string{"port is required when kind is 'Service' and unset(default to 'Service')"},
7176
},
7277
{
7378
desc: "fails validation when kind is explicitly 'Service' and port is missing",
@@ -76,27 +81,7 @@ func TestValidateInferencePool(t *testing.T) {
7681
ip.Spec.EndpointPickerRef.Name = "vllm-llama3-8b-instruct-epp"
7782
ip.Spec.EndpointPickerRef.Port = nil
7883
},
79-
wantErrors: []string{"port is required when kind is 'Service'"},
80-
},
81-
{
82-
desc: "passes validation when kind is 'Service' and port is present",
83-
mutate: func(ip *v1.InferencePool) {
84-
ip.Spec.EndpointPickerRef.Kind = "Service"
85-
ip.Spec.EndpointPickerRef.Name = "vllm-llama3-8b-instruct-epp"
86-
ip.Spec.EndpointPickerRef.Port = &v1.Port{
87-
Number: 9002,
88-
}
89-
},
90-
// No errors expected, so wantErrors is nil or empty.
91-
wantErrors: nil,
92-
},
93-
{
94-
desc: "passes validation with a valid, minimal configuration",
95-
mutate: func(ip *v1.InferencePool) {
96-
// This mutation just uses the base configuration, which should be valid.
97-
// It's a good sanity check. The base uses a non-Service Kind.
98-
},
99-
wantErrors: nil,
84+
wantErrors: []string{"port is required when kind is 'Service' and unset(default to 'Service')"},
10085
},
10186
}
10287

test/cel/main_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import (
2929
"k8s.io/client-go/tools/clientcmd"
3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131
"sigs.k8s.io/controller-runtime/pkg/envtest"
32+
3233
inferencev1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
34+
inferencev1alpha2 "sigs.k8s.io/gateway-api-inference-extension/apix/v1alpha2"
3335
)
3436

3537
var k8sClient client.Client
@@ -40,10 +42,11 @@ func TestMain(m *testing.M) {
4042
var testEnv *envtest.Environment
4143
var err error
4244

43-
inferencev1.AddToScheme(scheme)
45+
_ = inferencev1.Install(scheme)
46+
_ = inferencev1alpha2.Install(scheme)
4447

4548
// Add core APIs in case we refer secrets, services and configmaps
46-
corev1.AddToScheme(scheme)
49+
_ = corev1.AddToScheme(scheme)
4750

4851
// If one wants to use a local cluster, a KUBECONFIG envvar should be passed,
4952
// otherwise testenv will be used
@@ -65,7 +68,7 @@ func TestMain(m *testing.M) {
6568
DownloadBinaryAssetsVersion: k8sVersion,
6669
CRDInstallOptions: envtest.CRDInstallOptions{
6770
Paths: []string{
68-
filepath.Join("..", "..", "..", "config", "crd", "bases"),
71+
filepath.Join("..", "..", "config", "crd", "bases"),
6972
},
7073
CleanUpAfterUse: true,
7174
},

0 commit comments

Comments
 (0)