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 9 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
42 changes: 42 additions & 0 deletions pkg/ext-proc/backend/datastore.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package backend

import (
"context"
"errors"
"math/rand"
"strconv"
"sync"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha1"
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/ext-proc/util/logging"
)
Expand Down Expand Up @@ -111,3 +115,41 @@ func IsCritical(model *v1alpha1.InferenceModel) bool {
}
return false
}

func (ds *K8sDatastore) LabelsMatch(podLabels map[string]string) bool {
poolSelector := selectorFromInferencePoolSelector(ds.inferencePool.Spec.Selector)
podSet := labels.Set(podLabels)
return poolSelector.Matches(podSet)
}

func (ds *K8sDatastore) flushPodsAndRefetch(ctx context.Context, ctrlClient client.Client, newServerPool *v1alpha1.InferencePool) {
podList := &corev1.PodList{}
if err := ctrlClient.List(ctx, podList, selectorFromInferencePoolSelector(newServerPool.Spec.Selector).(client.MatchingLabelsSelector)); err != nil {
klog.Error(err, "error listing clients")
}
podMap := sync.Map{}

for _, k8sPod := range podList.Items {
pod := Pod{
Name: k8sPod.Name,
Address: k8sPod.Status.PodIP + ":" + strconv.Itoa(int(newServerPool.Spec.TargetPortNumber)),
}
podMap.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 {
return labels.SelectorFromSet(stripLabelKeyAliasFromLabelMap(selector))
}

func stripLabelKeyAliasFromLabelMap(labels map[v1alpha1.LabelKey]v1alpha1.LabelValue) map[string]string {
outMap := make(map[string]string)
for k, v := range labels {
outMap[string(k)] = string(v)
}
return outMap
}
109 changes: 0 additions & 109 deletions pkg/ext-proc/backend/endpointslice_reconciler.go

This file was deleted.

202 changes: 0 additions & 202 deletions pkg/ext-proc/backend/endpointslice_reconcilier_test.go

This file was deleted.

21 changes: 21 additions & 0 deletions pkg/ext-proc/backend/inferencemodel_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,24 @@ func populateServiceMap(services ...*v1alpha1.InferenceModel) *sync.Map {
}
return returnVal
}

func mapsEqual(map1, map2 *sync.Map) bool {
equal := true

map1.Range(func(k, v any) bool {
if _, ok := map2.Load(k); !ok {
equal = false
return false
}
return true
})
map2.Range(func(k, v any) bool {
if _, ok := map1.Load(k); !ok {
equal = false
return false
}
return true
})

return equal
}
Loading