Skip to content

Commit 37b361d

Browse files
committed
Add model label to Playground
Signed-off-by: kerthcet <[email protected]>
1 parent fec135b commit 37b361d

File tree

9 files changed

+60
-10
lines changed

9 files changed

+60
-10
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
8-
newTag: main
7+
newName: inftyai/llmaz-test
8+
newTag: 0829-03

pkg/controller/inference/playground_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8383

8484
var serviceApplyConfiguration *inferenceclientgo.ServiceApplyConfiguration
8585

86+
model := &coreapi.OpenModel{}
8687
if playground.Spec.ModelClaim != nil {
8788
modelName := playground.Spec.ModelClaim.ModelName
88-
model := &coreapi.OpenModel{}
8989

9090
if err := r.Get(ctx, types.NamespacedName{Name: string(modelName)}, model); err != nil {
9191
return ctrl.Result{}, err

pkg/webhook/playground_webhook.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/webhook"
2727
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2828

29+
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
2930
inferenceapi "github.com/inftyai/llmaz/api/inference/v1alpha1"
3031
)
3132

@@ -46,6 +47,19 @@ var _ webhook.CustomDefaulter = &PlaygroundWebhook{}
4647

4748
// Default implements webhook.Defaulter so a webhook will be registered for the type
4849
func (w *PlaygroundWebhook) Default(ctx context.Context, obj runtime.Object) error {
50+
playground := obj.(*inferenceapi.Playground)
51+
52+
var modelName string
53+
if playground.Spec.ModelClaim != nil {
54+
modelName = string(playground.Spec.ModelClaim.ModelName)
55+
}
56+
// TODO: handle MultiModelsClaims in the future.
57+
58+
if playground.Labels == nil {
59+
playground.Labels = map[string]string{}
60+
}
61+
playground.Labels[coreapi.ModelNameLabelKey] = modelName
62+
4963
return nil
5064
}
5165

test/e2e/playground_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ var _ = ginkgo.Describe("playground e2e tests", func() {
5656

5757
playground := wrapper.MakePlayground("qwen2-0-5b-gguf", ns.Name).ModelClaim("qwen2-0-5b-gguf").Backend("llamacpp").Replicas(3).Obj()
5858
gomega.Expect(k8sClient.Create(ctx, playground)).To(gomega.Succeed())
59+
validation.ValidatePlayground(ctx, k8sClient, playground)
5960
validation.ValidatePlaygroundStatusEqualTo(ctx, k8sClient, playground, inferenceapi.PlaygroundAvailable, "PlaygroundReady", metav1.ConditionTrue)
6061

6162
service := &inferenceapi.Service{}
6263
gomega.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service)).To(gomega.Succeed())
64+
validation.ValidateService(ctx, k8sClient, service)
6365
validation.ValidateServiceStatusEqualTo(ctx, k8sClient, service, inferenceapi.ServiceAvailable, "ServiceReady", metav1.ConditionTrue)
6466
validation.ValidateServicePods(ctx, k8sClient, service)
6567
})

test/integration/controller/inference/playground_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ var _ = ginkgo.Describe("playground controller test", func() {
121121
}),
122122
ginkgo.Entry("advance configured Playground with sglang", &testValidatingCase{
123123
makePlayground: func() *inferenceapi.Playground {
124-
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).
124+
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).Label(coreapi.ModelNameLabelKey, model.Name).
125125
Backend("sglang").BackendVersion("main").BackendArgs([]string{"--foo", "bar"}).BackendEnv("FOO", "BAR").BackendRequest("cpu", "1").BackendLimit("cpu", "10").
126126
Obj()
127127
},
@@ -139,7 +139,7 @@ var _ = ginkgo.Describe("playground controller test", func() {
139139
}),
140140
ginkgo.Entry("advance configured Playground with llamacpp", &testValidatingCase{
141141
makePlayground: func() *inferenceapi.Playground {
142-
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).
142+
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).Label(coreapi.ModelNameLabelKey, model.Name).
143143
Backend("llamacpp").BackendVersion("main").BackendArgs([]string{"--foo", "bar"}).BackendEnv("FOO", "BAR").BackendRequest("cpu", "1").BackendLimit("cpu", "10").
144144
Obj()
145145
},

test/integration/webhook/playground_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ limitations under the License.
1717
package webhook
1818

1919
import (
20+
"github.com/google/go-cmp/cmp/cmpopts"
2021
"github.com/onsi/ginkgo/v2"
2122
"github.com/onsi/gomega"
2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425

26+
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
2527
inferenceapi "github.com/inftyai/llmaz/api/inference/v1alpha1"
2628
"github.com/inftyai/llmaz/test/util/wrapper"
2729
)
@@ -47,7 +49,6 @@ var _ = ginkgo.Describe("playground default and validation", func() {
4749
playground func() *inferenceapi.Playground
4850
failed bool
4951
}
50-
// TODO: Add more testCases to cover updating.
5152
ginkgo.DescribeTable("test validating",
5253
func(tc *testValidatingCase) {
5354
if tc.failed {
@@ -93,4 +94,26 @@ var _ = ginkgo.Describe("playground default and validation", func() {
9394
failed: true,
9495
}),
9596
)
97+
98+
type testDefaultingCase struct {
99+
playground func() *inferenceapi.Playground
100+
wantPlayground func() *inferenceapi.Playground
101+
}
102+
ginkgo.DescribeTable("test validating",
103+
func(tc *testDefaultingCase) {
104+
playground := tc.playground()
105+
gomega.Expect(k8sClient.Create(ctx, playground)).To(gomega.Succeed())
106+
gomega.Expect(playground).To(gomega.BeComparableTo(tc.wantPlayground(),
107+
cmpopts.IgnoreTypes(inferenceapi.PlaygroundStatus{}),
108+
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "UID", "ResourceVersion", "Generation", "CreationTimestamp", "ManagedFields")))
109+
},
110+
ginkgo.Entry("defaulting label with modelClaim", &testDefaultingCase{
111+
playground: func() *inferenceapi.Playground {
112+
return wrapper.MakePlayground("playground", ns.Name).ModelClaim("llama3-8b").Replicas(1).Obj()
113+
},
114+
wantPlayground: func() *inferenceapi.Playground {
115+
return wrapper.MakePlayground("playground", ns.Name).ModelClaim("llama3-8b").Replicas(1).Label(coreapi.ModelNameLabelKey, "llama3-8b").Obj()
116+
},
117+
}),
118+
)
96119
})

test/util/mock.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
package util
1717

1818
import (
19-
api "github.com/inftyai/llmaz/api/core/v1alpha1"
19+
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
2020
inferenceapi "github.com/inftyai/llmaz/api/inference/v1alpha1"
2121
"github.com/inftyai/llmaz/test/util/wrapper"
2222
)
@@ -25,12 +25,12 @@ const (
2525
sampleModelName = "llama3-8b"
2626
)
2727

28-
func MockASampleModel() *api.OpenModel {
28+
func MockASampleModel() *coreapi.OpenModel {
2929
return wrapper.MakeModel(sampleModelName).FamilyName("llama3").ModelSourceWithModelHub("Huggingface").ModelSourceWithModelID("meta-llama/Meta-Llama-3-8B", "").Obj()
3030
}
3131

3232
func MockASamplePlayground(ns string) *inferenceapi.Playground {
33-
return wrapper.MakePlayground("playground-llama3-8b", ns).ModelClaim(sampleModelName).Obj()
33+
return wrapper.MakePlayground("playground-llama3-8b", ns).ModelClaim(sampleModelName).Label(coreapi.ModelNameLabelKey, sampleModelName).Obj()
3434
}
3535

3636
func MockASampleService(ns string) *inferenceapi.Service {

test/util/validation/validate_playground.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func ValidatePlayground(ctx context.Context, k8sClient client.Client, playground
6060
if diff := cmp.Diff(playground.Spec.ModelClaim.InferenceFlavors, service.Spec.MultiModelsClaims[0].InferenceFlavors); diff != "" {
6161
return fmt.Errorf("unexpected flavors, want %v, got %v", playground.Spec.ModelClaim.InferenceFlavors, service.Spec.MultiModelsClaims[0].InferenceFlavors)
6262
}
63+
if playground.Labels[coreapi.ModelNameLabelKey] != model.Name {
64+
return fmt.Errorf("unexpected Playground label value, want %v, got %v", model.Name, playground.Labels[coreapi.ModelNameLabelKey])
65+
}
6366
}
6467

6568
// TODO: MultiModelsClaim

test/util/wrapper/playground.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ func (w *PlaygroundWrapper) Obj() *inferenceapi.Playground {
4343
return &w.Playground
4444
}
4545

46+
func (w *PlaygroundWrapper) Label(k, v string) *PlaygroundWrapper {
47+
if w.Labels == nil {
48+
w.Labels = map[string]string{}
49+
}
50+
w.Labels[k] = v
51+
return w
52+
}
53+
4654
func (w *PlaygroundWrapper) Replicas(replicas int32) *PlaygroundWrapper {
4755
w.Spec.Replicas = &replicas
4856
return w
4957
}
5058

5159
func (w *PlaygroundWrapper) ModelClaim(modelName string, flavorNames ...string) *PlaygroundWrapper {
52-
names := []coreapi.FlavorName{}
60+
var names []coreapi.FlavorName
5361
for _, name := range flavorNames {
5462
names = append(names, coreapi.FlavorName(name))
5563
}

0 commit comments

Comments
 (0)