Skip to content
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
32 changes: 32 additions & 0 deletions pkg/controller/inference/playground_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager sets up the controller with the Manager.
func (r *PlaygroundReconciler) SetupWithManager(mgr ctrl.Manager) error {
mapFn := func(ctx context.Context, obj client.Object) []ctrl.Request {
logger := log.FromContext(ctx)

modelName := obj.GetName()

playgrounds := &inferenceapi.PlaygroundList{}
err := r.List(ctx, playgrounds, client.MatchingLabels{coreapi.ModelNameLabelKey: modelName})
if err != nil {
logger.Error(err, "failed to list playgrounds")
return nil
}

var reqs []ctrl.Request
for _, playground := range playgrounds.Items {
reqs = append(reqs, ctrl.Request{
NamespacedName: types.NamespacedName{
Name: playground.Name,
},
})
}

// TODO: handle MultiModelsClaims in the future.

return reqs
}

return ctrl.NewControllerManagedBy(mgr).
For(&inferenceapi.Playground{}).
Watches(&inferenceapi.Service{}, &handler.EnqueueRequestForObject{},
Expand All @@ -129,6 +155,12 @@ func (r *PlaygroundReconciler) SetupWithManager(mgr ctrl.Manager) error {
return !reflect.DeepEqual(oldBar.Status, newBar.Status)
},
})).
Watches(&coreapi.OpenModel{}, handler.EnqueueRequestsFromMapFunc(mapFn),
builder.WithPredicates(predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool { return false },
DeleteFunc: func(e event.DeleteEvent) bool { return false },
GenericFunc: func(e event.GenericEvent) bool { return false },
})).
Complete(r)
}

Expand Down
51 changes: 51 additions & 0 deletions test/integration/controller/inference/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package inference

import (
"context"
"fmt"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -155,5 +157,54 @@ var _ = ginkgo.Describe("playground controller test", func() {
},
},
}),
ginkgo.Entry("create the model after playground is created", &testValidatingCase{
makePlayground: func() *inferenceapi.Playground {
return util.MockASamplePlayground(ns.Name)
},
updates: []*update{
{
playgroundUpdateFn: func(playground *inferenceapi.Playground) {
// Delete the pre-provision model before creating playground.
gomega.Expect(k8sClient.Delete(ctx, model)).To(gomega.Succeed())
// To make sure model not exists.
gomega.Eventually(func() error {
oldModel := &coreapi.OpenModel{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: model.Name, Namespace: model.Namespace}, oldModel); err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return err
}
return fmt.Errorf("model %s/%s still exists", model.Namespace, model.Name)
}, util.IntegrationTimeout, util.Interval).Should(gomega.Succeed())

gomega.Expect(k8sClient.Create(ctx, playground)).To(gomega.Succeed())
},
checkPlayground: func(ctx context.Context, k8sClient client.Client, playground *inferenceapi.Playground) {
gomega.Consistently(func() error {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if no condition is expected.

Copy link
Member

Choose a reason for hiding this comment

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

Yes for now, but this can be optimized like pending for model creation in the follow up if you're interested or together with this PR, whatever you like.

So when there's no condition with Playground or model is not created, Playground is Pending, but with different reasons, one is Waiting for inferenceService ready, another is Waiting for model to be created.

Copy link
Member Author

Choose a reason for hiding this comment

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

n the follow up if you're interested or together with this PR, whatever you like.

I will do it in another PR.

updatePlayground := inferenceapi.Playground{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, &updatePlayground); err != nil {
return err
}
if len(updatePlayground.Status.Conditions) != 0 {
return fmt.Errorf("playground status conditions should be empty, got %v", updatePlayground.Status.Conditions)
}
return nil
}, 3*util.Interval, util.Interval).Should(gomega.Succeed())
},
},
{
// create the model after playground is created.
playgroundUpdateFn: func(_ *inferenceapi.Playground) {
model = util.MockASampleModel()
gomega.Expect(k8sClient.Create(ctx, model)).To(gomega.Succeed())
},
checkPlayground: func(ctx context.Context, k8sClient client.Client, playground *inferenceapi.Playground) {
validation.ValidatePlayground(ctx, k8sClient, playground)
validation.ValidatePlaygroundStatusEqualTo(ctx, k8sClient, playground, inferenceapi.PlaygroundProgressing, "Pending", metav1.ConditionTrue)
},
},
},
}),
)
})