generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 88
Refactor ext-proc Main with Server Package Add Hermetic Test with k8s API Client for EPP #222
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
42b4cbb
Add updated hermetic test with k8s client API, these pull from exampl…
BenjaminBraunDev 87d2786
Fix linting errors, remove unused variables and whitespace, remove co…
BenjaminBraunDev cfea9ff
Pre-allocate inferenceModels in hermetic test.
BenjaminBraunDev a58b77c
Fix import order for linting in hermetic test.
BenjaminBraunDev be989bf
Move test object yamls to test/artifacts directory in ext-proc, make …
BenjaminBraunDev e7f561e
move hermetic test for extproc into a new integration package and mov…
BenjaminBraunDev c8bde9a
Set up constants for main flags in extproc server package, improve fo…
BenjaminBraunDev ea4a531
rebase fork with main
BenjaminBraunDev 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 |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3" | ||
"google.golang.org/grpc" | ||
"inference.networking.x-k8s.io/gateway-api-inference-extension/pkg/ext-proc/backend" | ||
"inference.networking.x-k8s.io/gateway-api-inference-extension/pkg/ext-proc/handlers" | ||
"inference.networking.x-k8s.io/gateway-api-inference-extension/pkg/ext-proc/scheduling" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/client-go/rest" | ||
klog "k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
// ExtProcServerRunner provides methods to manage an external process server. | ||
type ExtProcServerRunner struct { | ||
GrpcPort int | ||
TargetPodHeader string | ||
PoolName string | ||
PoolNamespace string | ||
ServiceName string | ||
Zone string | ||
RefreshPodsInterval time.Duration | ||
RefreshMetricsInterval time.Duration | ||
Scheme *runtime.Scheme | ||
Config *rest.Config | ||
Datastore *backend.K8sDatastore | ||
manager ctrl.Manager | ||
} | ||
|
||
// Default values for CLI flags in main | ||
const ( | ||
DefaultGrpcPort = 9002 // default for --grpcPort | ||
DefaultTargetPodHeader = "target-pod" // default for --targetPodHeader | ||
DefaultPoolName = "" // required but no default | ||
DefaultPoolNamespace = "default" // default for --poolNamespace | ||
DefaultServiceName = "" // required but no default | ||
DefaultZone = "" // default for --zone | ||
DefaultRefreshPodsInterval = 10 * time.Second // default for --refreshPodsInterval | ||
DefaultRefreshMetricsInterval = 50 * time.Millisecond // default for --refreshMetricsInterval | ||
) | ||
|
||
func NewDefaultExtProcServerRunner() *ExtProcServerRunner { | ||
return &ExtProcServerRunner{ | ||
GrpcPort: DefaultGrpcPort, | ||
TargetPodHeader: DefaultTargetPodHeader, | ||
PoolName: DefaultPoolName, | ||
PoolNamespace: DefaultPoolNamespace, | ||
ServiceName: DefaultServiceName, | ||
Zone: DefaultZone, | ||
RefreshPodsInterval: DefaultRefreshPodsInterval, | ||
RefreshMetricsInterval: DefaultRefreshMetricsInterval, | ||
// Scheme, Config, and Datastore can be assigned later. | ||
} | ||
} | ||
|
||
// Setup creates the reconcilers for pools, models, and endpointSlices and starts the manager. | ||
func (r *ExtProcServerRunner) Setup() { | ||
// Create a new manager to manage controllers | ||
mgr, err := ctrl.NewManager(r.Config, ctrl.Options{Scheme: r.Scheme}) | ||
if err != nil { | ||
klog.Fatalf("Failed to create controller manager: %v", err) | ||
} | ||
r.manager = mgr | ||
|
||
// Create the controllers and register them with the manager | ||
if err := (&backend.InferencePoolReconciler{ | ||
Datastore: r.Datastore, | ||
Scheme: mgr.GetScheme(), | ||
Client: mgr.GetClient(), | ||
PoolNamespacedName: types.NamespacedName{ | ||
Name: r.PoolName, | ||
Namespace: r.PoolNamespace, | ||
}, | ||
Record: mgr.GetEventRecorderFor("InferencePool"), | ||
}).SetupWithManager(mgr); err != nil { | ||
klog.Fatalf("Failed setting up InferencePoolReconciler: %v", err) | ||
} | ||
|
||
if err := (&backend.InferenceModelReconciler{ | ||
Datastore: r.Datastore, | ||
Scheme: mgr.GetScheme(), | ||
Client: mgr.GetClient(), | ||
PoolNamespacedName: types.NamespacedName{ | ||
Name: r.PoolName, | ||
Namespace: r.PoolNamespace, | ||
}, | ||
Record: mgr.GetEventRecorderFor("InferenceModel"), | ||
}).SetupWithManager(mgr); err != nil { | ||
klog.Fatalf("Failed setting up InferenceModelReconciler: %v", err) | ||
} | ||
|
||
if err := (&backend.EndpointSliceReconciler{ | ||
Datastore: r.Datastore, | ||
Scheme: mgr.GetScheme(), | ||
Client: mgr.GetClient(), | ||
Record: mgr.GetEventRecorderFor("endpointslice"), | ||
ServiceName: r.ServiceName, | ||
Zone: r.Zone, | ||
}).SetupWithManager(mgr); err != nil { | ||
klog.Fatalf("Failed setting up EndpointSliceReconciler: %v", err) | ||
} | ||
} | ||
|
||
// Start starts the Envoy external processor server in a goroutine. | ||
func (r *ExtProcServerRunner) Start( | ||
podDatastore *backend.K8sDatastore, | ||
podMetricsClient backend.PodMetricsClient, | ||
) *grpc.Server { | ||
svr := grpc.NewServer() | ||
|
||
go func() { | ||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", r.GrpcPort)) | ||
if err != nil { | ||
klog.Fatalf("Ext-proc server failed to listen: %v", err) | ||
} | ||
klog.Infof("Ext-proc server listening on port: %d", r.GrpcPort) | ||
|
||
// Initialize backend provider | ||
pp := backend.NewProvider(podMetricsClient, podDatastore) | ||
if err := pp.Init(r.RefreshPodsInterval, r.RefreshMetricsInterval); err != nil { | ||
klog.Fatalf("Failed to initialize backend provider: %v", err) | ||
} | ||
|
||
// Register ext_proc handlers | ||
extProcPb.RegisterExternalProcessorServer( | ||
svr, | ||
handlers.NewServer(pp, scheduling.NewScheduler(pp), r.TargetPodHeader, r.Datastore), | ||
) | ||
|
||
// Blocking and will return when shutdown is complete. | ||
if err := svr.Serve(lis); err != nil && err != grpc.ErrServerStopped { | ||
klog.Fatalf("Ext-proc server failed: %v", err) | ||
} | ||
klog.Info("Ext-proc server shutting down") | ||
}() | ||
return svr | ||
} | ||
|
||
func (r *ExtProcServerRunner) StartManager() { | ||
if r.manager == nil { | ||
klog.Fatalf("Runner has no manager setup to run: %v", r) | ||
} | ||
// Start the controller manager. Blocking and will return when shutdown is complete. | ||
klog.Infof("Starting controller manager") | ||
mgr := r.manager | ||
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { | ||
klog.Fatalf("Error starting controller manager: %v", err) | ||
} | ||
klog.Info("Controller manager shutting down") | ||
} |
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.