Skip to content

Commit b5129b6

Browse files
BH4AWSfurykerry
authored andcommitted
update using sandbox spec runtimeconfig instend of annotation flag
Signed-off-by: jicheng.sk <jicheng.sk@alibaba-inc.com>
1 parent 632bb4f commit b5129b6

20 files changed

+714
-95
lines changed

api/v1alpha1/sandbox_types.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ const (
3636
// Sandbox Manager or Sandbox Claim creates high-priority sandboxes by default.
3737
SandboxAnnotationPriority = "agents.kruise.io/sandbox-priority"
3838

39-
// ShouldInjectCsiMount is the annotation key for inject csi mount plugin container.
40-
// If set, the csi sidecar will be injected into the pod when the sandbox is created.
41-
// The csi mount sidecar is used to mount the remote oss/nas storage to the sandbox container.
42-
ShouldInjectCsiMount = "agents.kruise.io/inject-csi-plugin"
43-
44-
// ShouldInjectAgentRuntime is the annotation key for inject agent runtime sidecar in init container.
45-
// If set, the agent runtime sidecar will be injected into the pod when the sandbox is created.
46-
// Some binary tools which are contained in the init agent runtime container. These are the basic tools for sandbox running.
47-
ShouldInjectAgentRuntime = "agents.kruise.io/inject-agent-runtime"
39+
// RuntimeConfigForInjectCsiMount is a valid value for RuntimeConfig.Name.
40+
// When set, enables CSI mount sidecar injection for the sandbox.
41+
RuntimeConfigForInjectCsiMount = "csi"
42+
// RuntimeConfigForInjectAgentRuntime is a valid value for RuntimeConfig.Name.
43+
// When set, enables agent runtime sidecar injection for the sandbox.
44+
RuntimeConfigForInjectAgentRuntime = "agent-runtime"
4845
)
4946

47+
type RuntimeConfig struct {
48+
Name string `json:"name"`
49+
}
50+
5051
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
5152
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
5253

@@ -69,6 +70,10 @@ type SandboxSpec struct {
6970
// +kubebuilder:validation:Format="date-time"
7071
ShutdownTime *metav1.Time `json:"shutdownTime,omitempty"`
7172

73+
// Runtimes - Runtime configuration for sandbox object
74+
// +optional
75+
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`
76+
7277
// PauseTime - Absolute time when the sandbox will be paused automatically.
7378
// +kubebuilder:validation:Format="date-time"
7479
PauseTime *metav1.Time `json:"pauseTime,omitempty"`

api/v1alpha1/sandboxclaim_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ type SandboxClaimSpec struct {
7878
// +optional
7979
DynamicVolumesMount []CSIMountConfig `json:"dynamicVolumesMount"`
8080

81+
// Runtimes - Runtime configuration for sandbox object
82+
// +optional
83+
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`
84+
8185
// Set ReserveFailedSandbox to true to reserve failed sandboxes
8286
// +optional
8387
ReserveFailedSandbox bool `json:"reserveFailedSandbox,omitempty"`

api/v1alpha1/sandboxset_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ type SandboxSetSpec struct {
6060
// PersistentContents indicates resume pod with persistent content, Enum: ip, memory, filesystem
6161
PersistentContents []string `json:"persistentContents,omitempty"`
6262

63+
// Runtimes - Runtime configuration for sandbox object
64+
// +optional
65+
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`
66+
6367
EmbeddedSandboxTemplate `json:",inline"`
6468

6569
// ScaleStrategy indicates the ScaleStrategy that will be employed to

api/v1alpha1/sandboxtemplate_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type SandboxTemplateSpec struct {
3838

3939
// PersistentContents indicates resume pod with persistent content, Enum: ip, memory, filesystem
4040
PersistentContents []string `json:"persistentContents,omitempty"`
41+
42+
// Runtimes - Runtime configuration for sandbox object
43+
// +optional
44+
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`
4145
}
4246

4347
// +genclient

api/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/agents.kruise.io_sandboxclaims.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ spec:
136136
reserveFailedSandbox:
137137
description: Set ReserveFailedSandbox to true to reserve failed sandboxes
138138
type: boolean
139+
runtimes:
140+
description: Runtimes - Runtime configuration for sandbox object
141+
items:
142+
properties:
143+
name:
144+
type: string
145+
required:
146+
- name
147+
type: object
148+
type: array
139149
shutdownTime:
140150
description: |-
141151
ShutdownTime specifies the absolute time when the sandbox should be shut down

config/crd/bases/agents.kruise.io_sandboxes.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ spec:
7171
items:
7272
type: string
7373
type: array
74+
runtimes:
75+
description: Runtimes - Runtime configuration for sandbox object
76+
items:
77+
properties:
78+
name:
79+
type: string
80+
required:
81+
- name
82+
type: object
83+
type: array
7484
shutdownTime:
7585
description: |-
7686
ShutdownTime - Absolute time when the sandbox is deleted.

config/crd/bases/agents.kruise.io_sandboxsets.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ spec:
6666
available and creating ones.
6767
format: int32
6868
type: integer
69+
runtimes:
70+
description: Runtimes - Runtime configuration for sandbox object
71+
items:
72+
properties:
73+
name:
74+
type: string
75+
required:
76+
- name
77+
type: object
78+
type: array
6979
scaleStrategy:
7080
description: |-
7181
ScaleStrategy indicates the ScaleStrategy that will be employed to

pkg/controller/sandbox/core/common_control_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,13 @@ func TestCommonControl_createPod_WithSidecarInjection(t *testing.T) {
13051305
ObjectMeta: metav1.ObjectMeta{
13061306
Name: "test-sandbox",
13071307
Namespace: "default",
1308-
Annotations: map[string]string{
1309-
agentsv1alpha1.ShouldInjectAgentRuntime: "true",
1310-
},
13111308
},
13121309
Spec: agentsv1alpha1.SandboxSpec{
1310+
Runtimes: []agentsv1alpha1.RuntimeConfig{
1311+
{
1312+
Name: agentsv1alpha1.RuntimeConfigForInjectAgentRuntime,
1313+
},
1314+
},
13131315
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
13141316
Template: &corev1.PodTemplateSpec{
13151317
Spec: corev1.PodSpec{
@@ -1359,11 +1361,13 @@ func TestCommonControl_createPod_WithSidecarInjection(t *testing.T) {
13591361
ObjectMeta: metav1.ObjectMeta{
13601362
Name: "test-sandbox",
13611363
Namespace: "default",
1362-
Annotations: map[string]string{
1363-
agentsv1alpha1.ShouldInjectCsiMount: "true",
1364-
},
13651364
},
13661365
Spec: agentsv1alpha1.SandboxSpec{
1366+
Runtimes: []agentsv1alpha1.RuntimeConfig{
1367+
{
1368+
Name: agentsv1alpha1.RuntimeConfigForInjectCsiMount,
1369+
},
1370+
},
13671371
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
13681372
Template: &corev1.PodTemplateSpec{
13691373
Spec: corev1.PodSpec{
@@ -1416,12 +1420,16 @@ func TestCommonControl_createPod_WithSidecarInjection(t *testing.T) {
14161420
ObjectMeta: metav1.ObjectMeta{
14171421
Name: "test-sandbox",
14181422
Namespace: "default",
1419-
Annotations: map[string]string{
1420-
agentsv1alpha1.ShouldInjectAgentRuntime: "true",
1421-
agentsv1alpha1.ShouldInjectCsiMount: "true",
1422-
},
14231423
},
14241424
Spec: agentsv1alpha1.SandboxSpec{
1425+
Runtimes: []agentsv1alpha1.RuntimeConfig{
1426+
{
1427+
Name: agentsv1alpha1.RuntimeConfigForInjectAgentRuntime,
1428+
},
1429+
{
1430+
Name: agentsv1alpha1.RuntimeConfigForInjectCsiMount,
1431+
},
1432+
},
14251433
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
14261434
Template: &corev1.PodTemplateSpec{
14271435
Spec: corev1.PodSpec{

pkg/controller/sandboxclaim/core/common_control.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ func (c *commonControl) buildClaimOptions(ctx context.Context, claim *agentsv1al
319319
}
320320
}
321321

322+
if len(claim.Spec.Runtimes) > 0 {
323+
opts.RuntimeConfig = claim.Spec.Runtimes
324+
}
325+
322326
// Validate and initialize
323327
return sandboxcr.ValidateAndInitClaimOptions(opts)
324328
}

0 commit comments

Comments
 (0)