Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions api/inference/v1alpha1/backendruntime_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type BackendRuntimeSpec struct {
// Envs represents the environments set to the container.
// +optional
Envs []corev1.EnvVar `json:"envs,omitempty"`
// Lifecycle represents hooks executed during the lifecycle of the container.
// +optional
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
// Periodic probe of backend liveness.
// Backend will be restarted if the probe fails.
// Cannot be updated.
Expand Down
5 changes: 5 additions & 0 deletions api/inference/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/controller/inference/playground_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func buildTemplate(models []*coreapi.OpenModel, playground *inferenceapi.Playgro
// commands
commands := parser.Commands()

// lifecycle
lifecycle := parser.Lifecycle()

// probe
var livenessProbe, readinessProbe, startupProbe *corev1.Probe
if backendRuntime.Spec.StartupProbe != nil {
Expand All @@ -337,6 +340,7 @@ func buildTemplate(models []*coreapi.OpenModel, playground *inferenceapi.Playgro
Command: commands,
Args: args,
Env: envs,
Lifecycle: lifecycle,
Ports: []corev1.ContainerPort{
{
Name: "http",
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller_helper/backendruntime/backendruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (p *BackendRuntimeParser) Envs() []corev1.EnvVar {
return p.backendRuntime.Spec.Envs
}

func (p *BackendRuntimeParser) Lifecycle() *corev1.Lifecycle {
return p.backendRuntime.Spec.Lifecycle
}

func (p *BackendRuntimeParser) Args() ([]string, error) {
mainModel := p.models[0]

Expand Down
13 changes: 13 additions & 0 deletions test/config/backends/fake_backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ spec:
- echo "hello"
image: busybox
version: latest
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- echo "Container started."
preStop:
exec:
command:
- /bin/sh
- -c
- echo "Container stopped."
recommendedConfigs:
- name: default
args:
Expand Down
27 changes: 27 additions & 0 deletions test/integration/controller/inference/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,32 @@ var _ = ginkgo.Describe("playground controller test", func() {
},
},
}),
ginkgo.Entry("Playground with Playground with fake-backend", &testValidatingCase{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ginkgo.Entry("Playground with Playground with fake-backend", &testValidatingCase{
ginkgo.Entry("Playground with fake-backend", &testValidatingCase{

Copy link
Member Author

Choose a reason for hiding this comment

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

opos.... my bad

makePlayground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).Label(coreapi.ModelNameLabelKey, model.Name).
BackendRuntime("fake-backend").
Obj()
},
updates: []*update{
{
updateFunc: func(playground *inferenceapi.Playground) {
gomega.Expect(k8sClient.Create(ctx, playground)).To(gomega.Succeed())
},
checkFunc: 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)
},
},
{
updateFunc: func(playground *inferenceapi.Playground) {
util.UpdateLwsToReady(ctx, k8sClient, playground.Name, playground.Namespace)
},
checkFunc: func(ctx context.Context, k8sClient client.Client, playground *inferenceapi.Playground) {
validation.ValidatePlayground(ctx, k8sClient, playground)
validation.ValidatePlaygroundStatusEqualTo(ctx, k8sClient, playground, inferenceapi.PlaygroundAvailable, "PlaygroundReady", metav1.ConditionTrue)
},
},
},
}),
)
})
5 changes: 5 additions & 0 deletions test/util/validation/validate_playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ func ValidatePlayground(ctx context.Context, k8sClient client.Client, playground
return errors.New("command not right")
}

// compare lifecycle
if diff := cmp.Diff(parser.Lifecycle(), service.Spec.WorkloadTemplate.WorkerTemplate.Spec.Containers[0].Lifecycle); diff != "" {
return errors.New("lifecycle not right")
}

// compare fields only can be configured in backend.

if backendRuntime.Spec.StartupProbe != nil {
Expand Down
5 changes: 5 additions & 0 deletions test/util/wrapper/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (w *BackendRuntimeWrapper) Command(commands []string) *BackendRuntimeWrappe
return w
}

func (w *BackendRuntimeWrapper) Lifecycle(lifecycle *corev1.Lifecycle) *BackendRuntimeWrapper {
w.Spec.Lifecycle = lifecycle
return w
}

func (w *BackendRuntimeWrapper) Arg(name string, args []string) *BackendRuntimeWrapper {
if w.Spec.RecommendedConfigs == nil {
w.Spec.RecommendedConfigs = []inferenceapi.RecommendedConfig{
Expand Down
Loading