Skip to content

Commit 6e9b3a8

Browse files
committed
Add new conditions
Signed-off-by: kerthcet <[email protected]>
1 parent a0b1925 commit 6e9b3a8

File tree

9 files changed

+298
-89
lines changed

9 files changed

+298
-89
lines changed

config/manager/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
66
- name: controller
7-
newName: inftyai/llmaz-test
8-
newTag: 0901-04
7+
newName: inftyai/llmaz
8+
newTag: main

docs/examples/llamacpp/playground.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apiVersion: inference.llmaz.io/v1alpha1
22
kind: Playground
33
metadata:
4-
name: qwen2-0-5b
4+
name: qwen2-0--5b
55
spec:
66
replicas: 1
77
modelClaim:
8-
modelName: qwen2-0-5b-gguf
8+
modelName: qwen2-0--5b-gguf
99
backendConfig:
1010
name: llamacpp
1111
args:

pkg/controller/inference/playground_controller.go

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"reflect"
2323

2424
corev1 "k8s.io/api/core/v1"
25+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2526
apimeta "k8s.io/apimachinery/pkg/api/meta"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
@@ -84,19 +85,8 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8485

8586
service := &inferenceapi.Service{}
8687
if err := r.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service); err == nil {
87-
if !controllerutil.HasControllerReference(service) {
88-
condition := metav1.Condition{
89-
Type: inferenceapi.PlaygroundProgressing,
90-
Status: metav1.ConditionFalse,
91-
Reason: "AbortProcessing",
92-
Message: "Playground owns the same name with an existing Service",
93-
}
94-
apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
95-
if err := r.Client.Status().Update(ctx, playground); err != nil {
96-
return ctrl.Result{}, err
97-
}
98-
// No need to requeue. Once the Service is deleted, the Playground will be reconciled.
99-
return ctrl.Result{}, nil
88+
if changed := handleUnexpectedCondition(playground, true, controllerutil.HasControllerReference(service)); changed {
89+
return ctrl.Result{}, r.Client.Status().Update(ctx, playground)
10090
}
10191
}
10292

@@ -106,13 +96,19 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
10696
if playground.Spec.ModelClaim != nil {
10797
model := &coreapi.OpenModel{}
10898
if err := r.Get(ctx, types.NamespacedName{Name: string(playground.Spec.ModelClaim.ModelName)}, model); err != nil {
99+
if apierrors.IsNotFound(err) && handleUnexpectedCondition(playground, false, true) {
100+
return ctrl.Result{}, r.Client.Status().Update(ctx, playground)
101+
}
109102
return ctrl.Result{}, err
110103
}
111104
models = append(models, model)
112105
} else if playground.Spec.MultiModelsClaim != nil {
113106
for _, modelName := range playground.Spec.MultiModelsClaim.ModelNames {
114107
model := &coreapi.OpenModel{}
115108
if err := r.Get(ctx, types.NamespacedName{Name: string(modelName)}, model); err != nil {
109+
if apierrors.IsNotFound(err) && handleUnexpectedCondition(playground, false, true) {
110+
return ctrl.Result{}, r.Client.Status().Update(ctx, playground)
111+
}
116112
return ctrl.Result{}, err
117113
}
118114
models = append(models, model)
@@ -130,11 +126,6 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
130126
}
131127

132128
// Handle status.
133-
service = &inferenceapi.Service{}
134-
if err := r.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service); err != nil {
135-
return ctrl.Result{}, err
136-
}
137-
138129
setPlaygroundCondition(playground, service)
139130
if err := r.Client.Status().Update(ctx, playground); err != nil {
140131
return ctrl.Result{}, err
@@ -308,17 +299,40 @@ func buildWorkerTemplate(models []*coreapi.OpenModel, playground *inferenceapi.P
308299
return template
309300
}
310301

311-
func setPlaygroundCondition(playground *inferenceapi.Playground, service *inferenceapi.Service) {
312-
// For the start up.
313-
if len(playground.Status.Conditions) == 0 || !apimeta.IsStatusConditionTrue(service.Status.Conditions, inferenceapi.PlaygroundProgressing) {
302+
func handleUnexpectedCondition(playground *inferenceapi.Playground, modelExists bool, serviceHasOwner bool) (changed bool) {
303+
// Put it in the first place as more serious.
304+
if !serviceHasOwner {
305+
condition := metav1.Condition{
306+
Type: inferenceapi.PlaygroundProgressing,
307+
Status: metav1.ConditionFalse,
308+
Reason: "AbortProcessing",
309+
Message: "Playground owns the same name with an existing Service",
310+
}
311+
return apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
312+
}
313+
314+
if !modelExists {
315+
condition := metav1.Condition{
316+
Type: inferenceapi.PlaygroundProgressing,
317+
Status: metav1.ConditionFalse,
318+
Reason: "AbortProcessing",
319+
Message: "Waiting for model creation",
320+
}
321+
return apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
322+
}
323+
return false
324+
}
325+
326+
func setPlaygroundCondition(playground *inferenceapi.Playground, service *inferenceapi.Service) (changed bool) {
327+
// For the start up or Playground is recovered from AbortProcessing.
328+
if len(playground.Status.Conditions) == 0 || apimeta.IsStatusConditionFalse(playground.Status.Conditions, inferenceapi.PlaygroundProgressing) {
314329
condition := metav1.Condition{
315330
Type: inferenceapi.PlaygroundProgressing,
316331
Status: metav1.ConditionTrue,
317332
Reason: "Pending",
318333
Message: "Waiting for inferenceService ready",
319334
}
320-
apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
321-
return
335+
return apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
322336
}
323337

324338
if apimeta.IsStatusConditionTrue(service.Status.Conditions, inferenceapi.ServiceAvailable) {
@@ -328,11 +342,11 @@ func setPlaygroundCondition(playground *inferenceapi.Playground, service *infere
328342
Reason: "PlaygroundReady",
329343
Message: "Playground is ready",
330344
}
331-
apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
345+
return apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
332346
} else {
333347
// Still in starting up, no need to populate the condition.
334348
if apimeta.FindStatusCondition(playground.Status.Conditions, inferenceapi.PlaygroundAvailable) == nil {
335-
return
349+
return false
336350
}
337351

338352
condition := metav1.Condition{
@@ -341,14 +355,16 @@ func setPlaygroundCondition(playground *inferenceapi.Playground, service *infere
341355
Reason: "PlaygroundInProgress",
342356
Message: "Playground is progressing",
343357
}
344-
apimeta.SetStatusCondition(&playground.Status.Conditions, condition)
358+
changed = apimeta.SetStatusCondition(&playground.Status.Conditions, condition) || changed
345359

346360
// Set the available to false
347361
new_condition := metav1.Condition{
348362
Type: inferenceapi.PlaygroundAvailable,
349363
Status: metav1.ConditionFalse,
364+
Reason: "PlaygroundNotReady",
350365
}
351-
apimeta.SetStatusCondition(&playground.Status.Conditions, new_condition)
366+
changed = apimeta.SetStatusCondition(&playground.Status.Conditions, new_condition) || changed
367+
return changed
352368
}
353369
}
354370

test/e2e/suit_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package e2e
1717

1818
import (
1919
"context"
20+
"os"
2021
"testing"
2122
"time"
2223

@@ -81,6 +82,7 @@ var _ = BeforeSuite(func() {
8182
Expect(k8sClient).NotTo(BeNil())
8283

8384
readyForTesting(k8sClient)
85+
os.Setenv("TEST_TYPE", "E2E")
8486
})
8587

8688
var _ = AfterSuite(func() {

0 commit comments

Comments
 (0)