/
state.go
43 lines (34 loc) · 1.05 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Copyright 2023 Lawrence Livermore National Security, LLC
(c.f. AUTHORS, NOTICE.LLNS, COPYING)
This is part of the Flux resource manager framework.
For details, see https://github.com/flux-framework.
SPDX-License-Identifier: Apache-2.0
*/
package controllers
import (
corev1 "k8s.io/api/core/v1"
api "github.com/flux-framework/flux-operator/api/v1alpha2"
)
// createContainerLifecycle adds lifecycle commands to help with moving cluster state
func createContainerLifecycle(
container api.MiniClusterContainer) *corev1.Lifecycle {
// Empty Lifecycle by default
lifecycle := corev1.Lifecycle{}
// Manual lifecycles from the user before container start
if container.LifeCycle.PostStartExec != "" {
lifecycle.PostStart = &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{container.LifeCycle.PostStartExec},
},
}
}
if container.LifeCycle.PreStopExec != "" {
lifecycle.PreStop = &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{container.LifeCycle.PreStopExec},
},
}
}
return &lifecycle
}