Skip to content

Replacing endpointSlice Reconciler with a direct Pod Reconciler #300

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 16 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 2 additions & 5 deletions pkg/ext-proc/backend/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,16 @@ func (ds *K8sDatastore) flushPodsAndRefetch(ctx context.Context, ctrlClient clie
}); err != nil {
klog.Error(err, "error listing clients")
}
podMap := sync.Map{}
ds.pods.Clear()

for _, k8sPod := range podList.Items {
pod := Pod{
Name: k8sPod.Name,
Address: k8sPod.Status.PodIP + ":" + strconv.Itoa(int(newServerPool.Spec.TargetPortNumber)),
}
podMap.Store(pod, true)
ds.pods.Store(pod, true)
}

// Clear is thread-safe, so if there are any in-flight accesses this should prevent odd data behavior. Then we replace after.
ds.pods.Clear()
ds.pods = &podMap
}

func selectorFromInferencePoolSelector(selector map[v1alpha1.LabelKey]v1alpha1.LabelValue) labels.Selector {
Expand Down
4 changes: 3 additions & 1 deletion pkg/ext-proc/backend/inferencepool_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ func (c *InferencePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, err
}
if c.Datastore.inferencePool == nil || !reflect.DeepEqual(serverPool.Spec.Selector, c.Datastore.inferencePool.Spec.Selector) {
c.updateDatastore(serverPool)
c.Datastore.flushPodsAndRefetch(ctx, c.Client, serverPool)
} else {
c.updateDatastore(serverPool)
}
c.updateDatastore(serverPool)

return ctrl.Result{}, nil
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/ext-proc/backend/pod_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package backend
import (
"context"
"strconv"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -26,7 +25,10 @@ func (c *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
inferencePool, err := c.Datastore.getInferencePool()
if err != nil {
klog.V(logutil.DEFAULT).Infof("Skipping reconciling Pod because the InferencePool is not available yet: %v", err)
return ctrl.Result{Requeue: true, RequeueAfter: time.Second}, nil
// 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
}

klog.V(logutil.VERBOSE).Info("reconciling Pod", req.NamespacedName)
Expand All @@ -53,7 +55,7 @@ func (c *PodReconciler) updateDatastore(k8sPod *corev1.Pod, inferencePool *v1alp
Name: k8sPod.Name,
Address: k8sPod.Status.PodIP + ":" + strconv.Itoa(int(inferencePool.Spec.TargetPortNumber)),
}
if !c.Datastore.LabelsMatch(k8sPod.ObjectMeta.Labels) || !podIsReady(k8sPod) {
if !k8sPod.DeletionTimestamp.IsZero() || !c.Datastore.LabelsMatch(k8sPod.ObjectMeta.Labels) || !podIsReady(k8sPod) {
c.Datastore.pods.Delete(pod)
} else {
c.Datastore.pods.Store(pod, true)
Expand Down