Skip to content

Commit 4f9d28c

Browse files
authored
feature(BackendRuntime): support lifecycle hook fields for BackendRuntime (#303)
* feature(BackendRuntime): support lifeCycle hook fields for BackendRuntime Signed-off-by: googs1025 <[email protected]> * fix integration name --------- Signed-off-by: googs1025 <[email protected]>
1 parent 7bca83f commit 4f9d28c

File tree

8 files changed

+66
-0
lines changed

8 files changed

+66
-0
lines changed

api/inference/v1alpha1/backendruntime_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ type BackendRuntimeSpec struct {
8888
// Envs represents the environments set to the container.
8989
// +optional
9090
Envs []corev1.EnvVar `json:"envs,omitempty"`
91+
// Lifecycle represents hooks executed during the lifecycle of the container.
92+
// +optional
93+
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
9194
// Periodic probe of backend liveness.
9295
// Backend will be restarted if the probe fails.
9396
// Cannot be updated.

api/inference/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/inference/playground_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ func buildTemplate(models []*coreapi.OpenModel, playground *inferenceapi.Playgro
313313
// commands
314314
commands := parser.Commands()
315315

316+
// lifecycle
317+
lifecycle := parser.Lifecycle()
318+
316319
// probe
317320
var livenessProbe, readinessProbe, startupProbe *corev1.Probe
318321
if backendRuntime.Spec.StartupProbe != nil {
@@ -337,6 +340,7 @@ func buildTemplate(models []*coreapi.OpenModel, playground *inferenceapi.Playgro
337340
Command: commands,
338341
Args: args,
339342
Env: envs,
343+
Lifecycle: lifecycle,
340344
Ports: []corev1.ContainerPort{
341345
{
342346
Name: "http",

pkg/controller_helper/backendruntime/backendruntime.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (p *BackendRuntimeParser) Envs() []corev1.EnvVar {
5656
return p.backendRuntime.Spec.Envs
5757
}
5858

59+
func (p *BackendRuntimeParser) Lifecycle() *corev1.Lifecycle {
60+
return p.backendRuntime.Spec.Lifecycle
61+
}
62+
5963
func (p *BackendRuntimeParser) Args() ([]string, error) {
6064
mainModel := p.models[0]
6165

test/config/backends/fake_backend.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ spec:
1313
- echo "hello"
1414
image: busybox
1515
version: latest
16+
lifecycle:
17+
postStart:
18+
exec:
19+
command:
20+
- /bin/sh
21+
- -c
22+
- echo "Container started."
23+
preStop:
24+
exec:
25+
command:
26+
- /bin/sh
27+
- -c
28+
- echo "Container stopped."
1629
recommendedConfigs:
1730
- name: default
1831
args:

test/integration/controller/inference/playground_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,32 @@ var _ = ginkgo.Describe("playground controller test", func() {
455455
},
456456
},
457457
}),
458+
ginkgo.Entry("Playground with fake-backend", &testValidatingCase{
459+
makePlayground: func() *inferenceapi.Playground {
460+
return wrapper.MakePlayground("playground", ns.Name).ModelClaim(model.Name).Label(coreapi.ModelNameLabelKey, model.Name).
461+
BackendRuntime("fake-backend").
462+
Obj()
463+
},
464+
updates: []*update{
465+
{
466+
updateFunc: func(playground *inferenceapi.Playground) {
467+
gomega.Expect(k8sClient.Create(ctx, playground)).To(gomega.Succeed())
468+
},
469+
checkFunc: func(ctx context.Context, k8sClient client.Client, playground *inferenceapi.Playground) {
470+
validation.ValidatePlayground(ctx, k8sClient, playground)
471+
validation.ValidatePlaygroundStatusEqualTo(ctx, k8sClient, playground, inferenceapi.PlaygroundProgressing, "Pending", metav1.ConditionTrue)
472+
},
473+
},
474+
{
475+
updateFunc: func(playground *inferenceapi.Playground) {
476+
util.UpdateLwsToReady(ctx, k8sClient, playground.Name, playground.Namespace)
477+
},
478+
checkFunc: func(ctx context.Context, k8sClient client.Client, playground *inferenceapi.Playground) {
479+
validation.ValidatePlayground(ctx, k8sClient, playground)
480+
validation.ValidatePlaygroundStatusEqualTo(ctx, k8sClient, playground, inferenceapi.PlaygroundAvailable, "PlaygroundReady", metav1.ConditionTrue)
481+
},
482+
},
483+
},
484+
}),
458485
)
459486
})

test/util/validation/validate_playground.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func ValidatePlayground(ctx context.Context, k8sClient client.Client, playground
164164
return errors.New("command not right")
165165
}
166166

167+
// compare lifecycle
168+
if diff := cmp.Diff(parser.Lifecycle(), service.Spec.WorkloadTemplate.WorkerTemplate.Spec.Containers[0].Lifecycle); diff != "" {
169+
return errors.New("lifecycle not right")
170+
}
171+
167172
// compare fields only can be configured in backend.
168173

169174
if backendRuntime.Spec.StartupProbe != nil {

test/util/wrapper/backend.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (w *BackendRuntimeWrapper) Command(commands []string) *BackendRuntimeWrappe
6262
return w
6363
}
6464

65+
func (w *BackendRuntimeWrapper) Lifecycle(lifecycle *corev1.Lifecycle) *BackendRuntimeWrapper {
66+
w.Spec.Lifecycle = lifecycle
67+
return w
68+
}
69+
6570
func (w *BackendRuntimeWrapper) Arg(name string, args []string) *BackendRuntimeWrapper {
6671
if w.Spec.RecommendedConfigs == nil {
6772
w.Spec.RecommendedConfigs = []inferenceapi.RecommendedConfig{

0 commit comments

Comments
 (0)