Skip to content
Draft
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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ generate-proto: protoc-gen-go protoc-gen-go-grpc ## Generate Golang code from pr
--go-grpc_out=module=sigs.k8s.io/gateway-api-inference-extension:. \
pkg/epp/framework/plugins/requesthandling/parsers/vllmgrpc/api/proto/*.proto

.PHONY: generate-proto-light
generate-proto-light: protoc-gen-go protoc-gen-go-grpc ## Generate Golang code from light EPP protobuf files.
PATH="$(LOCALBIN):$$PATH" $(PROTOC) \
-I pkg/epp-light/proto \
-I . \
--go_out=module=sigs.k8s.io/gateway-api-inference-extension:. \
--go-grpc_out=module=sigs.k8s.io/gateway-api-inference-extension:. \
pkg/epp-light/proto/*.proto

# Use same code-generator version as k8s.io/api
CODEGEN_VERSION := $(shell go list -m -f '{{.Version}}' k8s.io/api)
CODEGEN = $(shell pwd)/bin/code-generator
Expand Down
33 changes: 33 additions & 0 deletions cmd/epp-light/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
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.
*/

// The epp-light binary is a minimal, reference Endpoint Picker (EPP) implementation.
// To use a custom picker, call runner.NewRunner().WithPicker(myPicker).Run(...).
package main

import (
"os"

ctrl "sigs.k8s.io/controller-runtime"

"sigs.k8s.io/gateway-api-inference-extension/cmd/epp-light/runner"
)

func main() {
if err := runner.NewRunner().Run(ctrl.SetupSignalHandler()); err != nil {
os.Exit(1)
}
}
118 changes: 118 additions & 0 deletions cmd/epp-light/runner/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
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 runner

import (
"context"
"fmt"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
epplight "sigs.k8s.io/gateway-api-inference-extension/pkg/epp-light"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp-light/server"
)

var scheme = runtime.NewScheme()

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1.Install(scheme))
}

// Runner encapsulates the light EPP server lifecycle.
// External projects can import this, swap in a custom EndpointPicker via
// WithPicker(), and call Run().
type Runner struct {
picker epplight.EndpointPicker
}

// NewRunner creates a Runner with the default RandomPicker.
func NewRunner() *Runner {
return &Runner{
picker: epplight.NewRandomPicker(),
}
}

// WithPicker sets a custom EndpointPicker implementation.
func (r *Runner) WithPicker(picker epplight.EndpointPicker) *Runner {
r.picker = picker
return r
}

// Run parses flags, creates the controller manager, wires everything together,
// and blocks until the context is cancelled.
func (r *Runner) Run(ctx context.Context) error {
opts := server.NewOptions()
opts.AddFlags(pflag.CommandLine)
pflag.Parse()

ctrl.SetLogger(zap.New())
logger := ctrl.Log.WithName("epp-light")

if err := opts.Validate(); err != nil {
return fmt.Errorf("invalid options: %w", err)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
})
if err != nil {
return fmt.Errorf("unable to create controller manager: %w", err)
}

datastore := epplight.NewDatastore()

// Use remote gRPC picker if --picker-address is set, otherwise use in-process picker.
picker := r.picker
if opts.PickerAddress != "" {
logger.Info("Using remote gRPC picker", "address", opts.PickerAddress)
grpcPicker, err := epplight.NewGRPCPicker(opts.PickerAddress)
if err != nil {
return fmt.Errorf("failed to create gRPC picker: %w", err)
}
picker = grpcPicker
}

serverRunner := &server.ExtProcServerRunner{
GRPCPort: opts.GRPCPort,
PoolNamespace: opts.PoolNamespace,
PoolName: opts.PoolName,
Datastore: datastore,
Picker: picker,
SecureServing: opts.SecureServing,
CertPath: opts.CertPath,
}

if err := serverRunner.SetupWithManager(mgr); err != nil {
return fmt.Errorf("failed to setup controllers: %w", err)
}

if err := mgr.Add(serverRunner.AsRunnable(logger)); err != nil {
return fmt.Errorf("failed to add ext-proc server runnable: %w", err)
}

logger.Info(fmt.Sprintf("Starting light EPP for pool %s/%s on port %d",
opts.PoolNamespace, opts.PoolName, opts.GRPCPort))

return mgr.Start(ctx)
}
Loading
Loading