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
5 changes: 0 additions & 5 deletions hack/kind-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ featureGates:
MaxUnavailableStatefulSet: true
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30000
hostPort: 30000
listenAddress: "0.0.0.0"
protocol: tcp
- role: worker
- role: worker
- role: worker
2 changes: 1 addition & 1 deletion pkg/controller/inference/playground_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)

var serviceApplyConfiguration *inferenceclientgo.ServiceApplyConfiguration

model := &coreapi.OpenModel{}
if playground.Spec.ModelClaim != nil {
modelName := playground.Spec.ModelClaim.ModelName
model := &coreapi.OpenModel{}

if err := r.Get(ctx, types.NamespacedName{Name: string(modelName)}, model); err != nil {
return ctrl.Result{}, err
Expand Down
14 changes: 14 additions & 0 deletions pkg/webhook/playground_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
inferenceapi "github.com/inftyai/llmaz/api/inference/v1alpha1"
)

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

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (w *PlaygroundWebhook) Default(ctx context.Context, obj runtime.Object) error {
playground := obj.(*inferenceapi.Playground)

var modelName string
if playground.Spec.ModelClaim != nil {
modelName = string(playground.Spec.ModelClaim.ModelName)
}
// TODO: handle MultiModelsClaims in the future.

if playground.Labels == nil {
playground.Labels = map[string]string{}
}
playground.Labels[coreapi.ModelNameLabelKey] = modelName

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ var _ = ginkgo.Describe("playground e2e tests", func() {

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

service := &inferenceapi.Service{}
gomega.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service)).To(gomega.Succeed())
validation.ValidateService(ctx, k8sClient, service)
validation.ValidateServiceStatusEqualTo(ctx, k8sClient, service, inferenceapi.ServiceAvailable, "ServiceReady", metav1.ConditionTrue)
validation.ValidateServicePods(ctx, k8sClient, service)
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration/controller/inference/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var _ = ginkgo.Describe("playground controller test", func() {
}),
ginkgo.Entry("advance configured Playground with sglang", &testValidatingCase{
makePlayground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).Label(coreapi.ModelNameLabelKey, model.Name).
Backend("sglang").BackendVersion("main").BackendArgs([]string{"--foo", "bar"}).BackendEnv("FOO", "BAR").BackendRequest("cpu", "1").BackendLimit("cpu", "10").
Obj()
},
Expand All @@ -139,7 +139,7 @@ var _ = ginkgo.Describe("playground controller test", func() {
}),
ginkgo.Entry("advance configured Playground with llamacpp", &testValidatingCase{
makePlayground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).Label(coreapi.ModelNameLabelKey, model.Name).
Backend("llamacpp").BackendVersion("main").BackendArgs([]string{"--foo", "bar"}).BackendEnv("FOO", "BAR").BackendRequest("cpu", "1").BackendLimit("cpu", "10").
Obj()
},
Expand Down
25 changes: 24 additions & 1 deletion test/integration/webhook/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package webhook

import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
inferenceapi "github.com/inftyai/llmaz/api/inference/v1alpha1"
"github.com/inftyai/llmaz/test/util/wrapper"
)
Expand All @@ -47,7 +49,6 @@ var _ = ginkgo.Describe("playground default and validation", func() {
playground func() *inferenceapi.Playground
failed bool
}
// TODO: Add more testCases to cover updating.
ginkgo.DescribeTable("test validating",
func(tc *testValidatingCase) {
if tc.failed {
Expand Down Expand Up @@ -93,4 +94,26 @@ var _ = ginkgo.Describe("playground default and validation", func() {
failed: true,
}),
)

type testDefaultingCase struct {
playground func() *inferenceapi.Playground
wantPlayground func() *inferenceapi.Playground
}
ginkgo.DescribeTable("test validating",
func(tc *testDefaultingCase) {
playground := tc.playground()
gomega.Expect(k8sClient.Create(ctx, playground)).To(gomega.Succeed())
gomega.Expect(playground).To(gomega.BeComparableTo(tc.wantPlayground(),
cmpopts.IgnoreTypes(inferenceapi.PlaygroundStatus{}),
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "UID", "ResourceVersion", "Generation", "CreationTimestamp", "ManagedFields")))
},
ginkgo.Entry("defaulting label with modelClaim", &testDefaultingCase{
playground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).ModelClaim("llama3-8b").Replicas(1).Obj()
},
wantPlayground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).ModelClaim("llama3-8b").Replicas(1).Label(coreapi.ModelNameLabelKey, "llama3-8b").Obj()
},
}),
)
})
6 changes: 3 additions & 3 deletions test/util/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
package util

import (
api "github.com/inftyai/llmaz/api/core/v1alpha1"
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
inferenceapi "github.com/inftyai/llmaz/api/inference/v1alpha1"
"github.com/inftyai/llmaz/test/util/wrapper"
)
Expand All @@ -25,12 +25,12 @@ const (
sampleModelName = "llama3-8b"
)

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

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

func MockASampleService(ns string) *inferenceapi.Service {
Expand Down
4 changes: 4 additions & 0 deletions test/util/validation/validate_playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func ValidatePlayground(ctx context.Context, k8sClient client.Client, playground
}
}

if playground.Labels[coreapi.ModelNameLabelKey] != model.Name {
return fmt.Errorf("unexpected Playground label value, want %v, got %v", model.Name, playground.Labels[coreapi.ModelNameLabelKey])
}

// TODO: MultiModelsClaim

backendName := inferenceapi.DefaultBackend
Expand Down
16 changes: 13 additions & 3 deletions test/util/wrapper/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func (w *PlaygroundWrapper) Obj() *inferenceapi.Playground {
return &w.Playground
}

func (w *PlaygroundWrapper) Label(k, v string) *PlaygroundWrapper {
if w.Labels == nil {
w.Labels = map[string]string{}
}
w.Labels[k] = v
return w
}

func (w *PlaygroundWrapper) Replicas(replicas int32) *PlaygroundWrapper {
w.Spec.Replicas = &replicas
return w
Expand All @@ -53,10 +61,12 @@ func (w *PlaygroundWrapper) ModelClaim(modelName string, flavorNames ...string)
for _, name := range flavorNames {
names = append(names, coreapi.FlavorName(name))
}

w.Spec.ModelClaim = &coreapi.ModelClaim{
ModelName: coreapi.ModelName(modelName),
InferenceFlavors: names,
ModelName: coreapi.ModelName(modelName),
}

if len(names) > 0 {
w.Spec.ModelClaim.InferenceFlavors = names
}
return w
}
Expand Down