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

Refactor beforeSuite in integration tests #508

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pkg/epp/server/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
)

Expand All @@ -39,9 +38,9 @@ func init() {
utilruntime.Must(v1alpha2.AddToScheme(scheme))
}

// NewDefaultManager creates a new controller manager with default configuration.
func NewDefaultManager(namespace, name string, restConfig *rest.Config) (ctrl.Manager, error) {
defaultOpts := ctrl.Options{
// DefaultManagerOptions returns the default options used to create the manager.
func DefaultManagerOptions(namespace, name string) ctrl.Options {
return ctrl.Options{
Scheme: scheme,
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{
Expand All @@ -67,12 +66,11 @@ func NewDefaultManager(namespace, name string, restConfig *rest.Config) (ctrl.Ma
},
},
}
return NewManagerWithOptions(restConfig, defaultOpts)
}

// NewManagerWithOptions creates a new controller manager with injectable options.
func NewManagerWithOptions(restConfig *rest.Config, opts manager.Options) (ctrl.Manager, error) {
manager, err := ctrl.NewManager(restConfig, opts)
// NewDefaultManager creates a new controller manager with default configuration.
func NewDefaultManager(namespace, name string, restConfig *rest.Config) (ctrl.Manager, error) {
manager, err := ctrl.NewManager(restConfig, DefaultManagerOptions(namespace, name))
if err != nil {
return nil, fmt.Errorf("failed to create controller manager: %v", err)
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/epp/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func (p *PodWrapper) Labels(labels map[string]string) *PodWrapper {
return p
}

// Labels sets the pod labels.
func (p *PodWrapper) LabelsFromPoolSelector(selector map[v1alpha2.LabelKey]v1alpha2.LabelValue) *PodWrapper {
if p.ObjectMeta.Labels == nil {
p.ObjectMeta.Labels = map[string]string{}
}
for k, v := range selector {
p.ObjectMeta.Labels[string(k)] = string(v)
}
return p
}

// SetReadyCondition sets a PodReay=true condition.
func (p *PodWrapper) ReadyCondition() *PodWrapper {
p.Status.Conditions = []corev1.PodCondition{{
Expand Down
35 changes: 33 additions & 2 deletions test/integration/epp/hermetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,42 @@ import (
"google.golang.org/protobuf/types/known/structpb"
"k8s.io/component-base/metrics/legacyregistry"
metricsutils "k8s.io/component-base/metrics/testutil"
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
utiltesting "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/testing"
)

var models = []*v1alpha2.InferenceModel{
utiltesting.MakeInferenceModel("sample").
Namespace(pool.Namespace).
ModelName("sql-lora").
Criticality(v1alpha2.Critical).
PoolName(pool.Name).
TargetModel("sql-lora-1fdg2").
ObjRef(),
utiltesting.MakeInferenceModel("sheddable").
Namespace(pool.Namespace).
ModelName("sql-lora-sheddable").
Criticality(v1alpha2.Sheddable).
PoolName(pool.Name).
TargetModel("sql-lora-1fdg3").
ObjRef(),
utiltesting.MakeInferenceModel("generic").
Namespace(pool.Namespace).
ModelName("my-model").
Criticality(v1alpha2.Critical).
PoolName(pool.Name).
TargetModel("my-model-12345").
ObjRef(),
utiltesting.MakeInferenceModel("direct-model").
Namespace(pool.Namespace).
ModelName("direct-model").
Criticality(v1alpha2.Critical).
PoolName(pool.Name).
ObjRef(),
}

func TestMain(m *testing.M) {
cleanup := BeforeSuite()
code := m.Run()
Expand Down Expand Up @@ -304,7 +335,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client, cleanup := setUpHermeticServer(t, test.pods, false)
client, cleanup := startEPPServer(t, &eppOptions{podMetrics: test.pods, models: models})
t.Cleanup(cleanup)
want := &extProcPb.ProcessingResponse{
Response: &extProcPb.ProcessingResponse_RequestBody{
Expand Down Expand Up @@ -1336,7 +1367,7 @@ func TestFullDuplexStreamed_KubeInferenceModelRequest(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client, cleanup := setUpHermeticServer(t, test.pods, true)
client, cleanup := startEPPServer(t, &eppOptions{podMetrics: test.pods, models: models, streamed: true})
t.Cleanup(cleanup)
responses, err := streamedRequest(t, client, test.requests, len(test.wantResponses))

Expand Down
Loading