Skip to content
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

Cache bug fix in update pod and model mapping #259

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
$(KUSTOMIZE) build config/default | $(KUBECTL) create -f -

.PHONY: undeploy
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand Down
23 changes: 19 additions & 4 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,20 @@ func (c *Cache) deletePod(obj interface{}) {
defer c.mu.Unlock()

pod := obj.(*v1.Pod)
modelName, ok := pod.Labels[modelIdentifier]
_, ok := pod.Labels[modelIdentifier]
if !ok {
return
}

// delete base model and associated lora models on this pod
if models, ok := c.podToModelMapping[pod.Name]; ok {
for modelName := range models {
c.deletePodAndModelMapping(pod.Name, modelName)
}
}
delete(c.podToModelMapping, pod.Name)
delete(c.pods, pod.Name)
c.deletePodAndModelMapping(pod.Name, modelName)

klog.V(4).Infof("POD DELETED: %s/%s", pod.Namespace, pod.Name)
c.debugInfo()
}
Expand Down Expand Up @@ -223,6 +230,7 @@ func (c *Cache) deleteModelAdapter(obj interface{}) {
for _, pod := range model.Status.Instances {
c.deletePodAndModelMapping(pod, model.Name)
}
delete(c.modelToPodMapping, model.Name)

klog.V(4).Infof("MODELADAPTER DELETED: %s/%s", model.Namespace, model.Name)
c.debugInfo()
Expand Down Expand Up @@ -257,8 +265,15 @@ func (c *Cache) addPodAndModelMapping(podName, modelName string) {
}

func (c *Cache) deletePodAndModelMapping(podName, modelName string) {
delete(c.podToModelMapping, podName)
delete(c.modelToPodMapping, modelName)
if models, ok := c.podToModelMapping[podName]; ok {
delete(models, modelName)
c.podToModelMapping[podName] = models
}

if pods, ok := c.modelToPodMapping[modelName]; ok {
delete(pods, podName)
c.modelToPodMapping[modelName] = pods
}
}

func (c *Cache) debugInfo() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/modelrouter/modelrouter_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (m *ModelRouter) createHTTPRoute(namespace string, labels map[string]string
}
if err := m.Client.Create(context.Background(), &httpRoute); err != nil {
klog.Errorln(err)
return
}
klog.Infof("httproute: %v created for model: %v", httpRoute.Name, modelName)
}
Expand All @@ -181,6 +182,7 @@ func (m *ModelRouter) deleteHTTPRoute(namespace string, labels map[string]string

if err := m.Client.Delete(context.Background(), &httpRoute); err != nil {
klog.Errorln(err)
return
}
klog.Infof("httproute: %v deleted for model: %v", httpRoute.Name, modelName)
}
Loading