Skip to content

Commit c51ee51

Browse files
committed
feature(BackendRuntime): support lifeCycle hook fields for BackendRuntime
1 parent a3a05fd commit c51ee51

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-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/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)