generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 247
adds integration test validation for CRD watchers and small refactor on EPP runner #2351
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
Open
zetxqx
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
zetxqx:integrationtest-crdwatcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+160
−25
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -24,13 +24,17 @@ import ( | |
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| configPb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" | ||
| extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3" | ||
| envoyTypePb "github.com/envoyproxy/go-control-plane/envoy/type/v3" | ||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/protobuf/testing/protocmp" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| "k8s.io/apimachinery/pkg/util/yaml" | ||
|
|
@@ -41,8 +45,10 @@ import ( | |
|
|
||
| v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1" | ||
| "sigs.k8s.io/gateway-api-inference-extension/apix/v1alpha2" | ||
| eppRunner "sigs.k8s.io/gateway-api-inference-extension/cmd/epp/runner" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metadata" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics" | ||
| eppServer "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server" | ||
| requtil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/request" | ||
| "sigs.k8s.io/gateway-api-inference-extension/test/integration" | ||
| ) | ||
|
|
@@ -454,3 +460,124 @@ func loadBaseResources() []*unstructured.Unstructured { | |
| } | ||
| return objs | ||
| } | ||
|
|
||
| // TestCRDWatchers verifies that the EPP correctly populates its internal datastore | ||
| // by watching InferenceModelRewrite and InferenceObjective resources. | ||
| func TestCRDWatchers(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| // Create dedicated namespace for the whole test | ||
| uid := uuid.New().String()[:8] | ||
| testNamespaceName := "epp-test-" + uid | ||
| ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: testNamespaceName}} | ||
| require.NoError(t, k8sClient.Create(ctx, ns), "failed to create test namespace") | ||
| defer func() { | ||
| if err := k8sClient.Delete(context.Background(), ns); err != nil { | ||
| t.Logf("failed to cleanup namespace %s: %v", testNamespaceName, err) | ||
| } | ||
| }() | ||
|
|
||
| const testPoolName = "test-pool" | ||
| opts := eppServer.NewOptions() | ||
| opts.PoolName = testPoolName | ||
| opts.PoolNamespace = testNamespaceName | ||
|
|
||
| metricsPort, err := integration.GetFreePort() | ||
| require.NoError(t, err) | ||
| opts.MetricsPort = metricsPort | ||
|
|
||
| grpcPort, err := integration.GetFreePort() | ||
| require.NoError(t, err) | ||
| opts.GRPCPort = grpcPort | ||
|
|
||
| healthPort, err := integration.GetFreePort() | ||
| require.NoError(t, err) | ||
| opts.GRPCHealthPort = healthPort | ||
| opts.EndpointTargetPorts = []int{8000} | ||
|
|
||
| mgr, dataStore, err := eppRunner.NewRunner().Setup(ctx, testEnv.Config, opts) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have this test invoke |
||
| if err != nil { | ||
| t.Fatalf("Error getting the epp manager") | ||
| } | ||
| go func() { | ||
| err := mgr.Start(ctx) | ||
| if err != nil && !strings.Contains(err.Error(), "context canceled") { | ||
| t.Errorf("RunInternal failed: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| // Create the Pool and CRs | ||
| pool := &v1.InferencePool{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: testPoolName, Namespace: testNamespaceName}, | ||
| Spec: v1.InferencePoolSpec{ | ||
| TargetPorts: []v1.Port{{Number: 8000}}, | ||
| Selector: v1.LabelSelector{ | ||
| MatchLabels: map[v1.LabelKey]v1.LabelValue{ | ||
| "app": "test", | ||
| }, | ||
| }, | ||
| EndpointPickerRef: v1.EndpointPickerRef{ | ||
| Name: v1.ObjectName("epp"), | ||
| Port: &v1.Port{Number: 8080}, | ||
| }, | ||
| }, | ||
| } | ||
| require.NoError(t, k8sClient.Create(ctx, pool)) | ||
|
|
||
| rewrite := &v1alpha2.InferenceModelRewrite{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test-rewrite", Namespace: testNamespaceName}, | ||
| Spec: v1alpha2.InferenceModelRewriteSpec{ | ||
| PoolRef: &v1alpha2.PoolObjectReference{ | ||
| Name: v1alpha2.ObjectName("test-pool"), | ||
| Group: v1alpha2.Group(v1.GroupVersion.Group), // Make sure this is set to the correct group version | ||
| Kind: v1alpha2.Kind("InferencePool"), | ||
| }, | ||
| Rules: []v1alpha2.InferenceModelRewriteRule{ | ||
| { | ||
| Matches: []v1alpha2.Match{ | ||
| { | ||
| Model: &v1alpha2.ModelMatch{ | ||
| Value: "source-model", | ||
| }, | ||
| }, | ||
| }, | ||
| Targets: []v1alpha2.TargetModel{ | ||
| { | ||
| ModelRewrite: "target-model", | ||
| Weight: 1, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| require.NoError(t, k8sClient.Create(ctx, rewrite)) | ||
|
|
||
| objective := &v1alpha2.InferenceObjective{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test-objective", Namespace: testNamespaceName}, | ||
| Spec: v1alpha2.InferenceObjectiveSpec{ | ||
| PoolRef: v1alpha2.PoolObjectReference{ | ||
| Name: v1alpha2.ObjectName("test-pool"), | ||
| Group: v1alpha2.Group(v1.GroupVersion.Group), // Make sure this is set to the correct group version | ||
| Kind: v1alpha2.Kind("InferencePool"), | ||
| }, | ||
| }, | ||
| } | ||
| require.NoError(t, k8sClient.Create(ctx, objective)) | ||
|
|
||
| require.Eventually(t, func() bool { | ||
| if dataStore == nil { | ||
| return false | ||
| } | ||
| // Verify Rewrite | ||
| if rule, _ := dataStore.ModelRewriteGet("source-model"); rule == nil { | ||
| return false | ||
| } | ||
| // Verify Objective | ||
| if obj := dataStore.ObjectiveGet("test-objective"); obj == nil { | ||
| return false | ||
| } | ||
| return true | ||
| }, 10*time.Second, 100*time.Millisecond, "Failed to watch InferenceModelRewrite or InferenceObjective") | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls add a comment here that we split the set up into a separate function to enable integration testing of the set up.