Skip to content

Use server side namespace filter #429

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 8 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
31 changes: 30 additions & 1 deletion cmd/epp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ import (
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
healthPb "google.golang.org/grpc/health/grpc_health_v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/component-base/metrics/legacyregistry"
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/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
Expand Down Expand Up @@ -140,7 +144,32 @@ func run() error {
return err
}

mgr, err := ctrl.NewManager(cfg, ctrl.Options{Scheme: scheme})
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we create a CreateDefaultManager func perhaps under the server pkg (https://github.com/kubernetes-sigs/gateway-api-inference-extension/tree/main/pkg/epp/server) so that we can invoke it from our integration tests, which would allow us to test this configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Scheme: scheme,
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Pod{}: {
Namespaces: map[string]cache.Config{
*poolNamespace: {},
},
},
&v1alpha2.InferencePool{}: {
Namespaces: map[string]cache.Config{
*poolNamespace: {
FieldSelector: fields.SelectorFromSet(fields.Set{
"metadata.name": *poolName,
}),
},
},
},
&v1alpha2.InferenceModel{}: {
Namespaces: map[string]cache.Config{
*poolNamespace: {},
},
},
},
},
})
if err != nil {
setupLog.Error(err, "Failed to create controller manager", "config", cfg)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/epp/controller/inferencemodel_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ func (c *InferenceModelReconciler) SetupWithManager(ctx context.Context, mgr ctr
}

func (c *InferenceModelReconciler) eventPredicate(infModel *v1alpha2.InferenceModel) bool {
return (infModel.Spec.PoolRef.Name == v1alpha2.ObjectName(c.PoolNamespacedName.Name)) && (infModel.GetNamespace() == c.PoolNamespacedName.Namespace)
return string(infModel.Spec.PoolRef.Name) == c.PoolNamespacedName.Name
}
4 changes: 0 additions & 4 deletions pkg/epp/controller/inferencepool_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
Expand Down Expand Up @@ -90,8 +89,5 @@ func (c *InferencePoolReconciler) updateDatastore(ctx context.Context, newPool *
func (c *InferencePoolReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha2.InferencePool{}).
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool {
return (object.GetNamespace() == c.PoolNamespacedName.Namespace) && (object.GetName() == c.PoolNamespacedName.Name)
})).
Complete(c)
}
12 changes: 5 additions & 7 deletions pkg/epp/controller/pod_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -35,19 +34,18 @@ import (
type PodReconciler struct {
client.Client
Datastore datastore.Datastore
Scheme *runtime.Scheme
// namespace of the InferencePool
// we donot support cross namespace pod selection
Namespace string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this anymore, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goodcatch

Record record.EventRecorder
}

func (c *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
inferencePool, err := c.Datastore.PoolGet()
if err != nil {
logger.V(logutil.TRACE).Info("Skipping reconciling Pod because the InferencePool is not available yet", "error", err)
if !c.Datastore.PoolHasSynced() {
logger.V(logutil.TRACE).Info("Skipping reconciling Pod because the InferencePool is not available yet")
// When the inferencePool is initialized it lists the appropriate pods and populates the datastore, so no need to requeue.
return ctrl.Result{}, nil
} else if inferencePool.Namespace != req.Namespace {
return ctrl.Result{}, nil
}

logger.V(logutil.VERBOSE).Info("Pod being reconciled", "name", req.NamespacedName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/epp/server/runserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (r *ExtProcServerRunner) SetupWithManager(ctx context.Context, mgr ctrl.Man

if err := (&controller.PodReconciler{
Datastore: r.Datastore,
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Namespace: r.PoolNamespace,
Record: mgr.GetEventRecorderFor("pod"),
}).SetupWithManager(mgr); err != nil {
return fmt.Errorf("failed setting up EndpointSliceReconciler: %v", err)
Expand Down