Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 14 additions & 9 deletions api/v1alpha1/sandbox_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ const (
// Sandbox Manager or Sandbox Claim creates high-priority sandboxes by default.
SandboxAnnotationPriority = "agents.kruise.io/sandbox-priority"

// ShouldInjectCsiMount is the annotation key for inject csi mount plugin container.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should also add runtimes fields in sandboxset and sandboxtemplate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

YES done

// If set, the csi sidecar will be injected into the pod when the sandbox is created.
// The csi mount sidecar is used to mount the remote oss/nas storage to the sandbox container.
ShouldInjectCsiMount = "agents.kruise.io/inject-csi-plugin"

// ShouldInjectAgentRuntime is the annotation key for inject agent runtime sidecar in init container.
// If set, the agent runtime sidecar will be injected into the pod when the sandbox is created.
// Some binary tools which are contained in the init agent runtime container. These are the basic tools for sandbox running.
ShouldInjectAgentRuntime = "agents.kruise.io/inject-agent-runtime"
// RuntimeConfigForInjectCsiMount is a valid value for RuntimeConfig.Name.
// When set, enables CSI mount sidecar injection for the sandbox.
RuntimeConfigForInjectCsiMount = "csi"
// RuntimeConfigForInjectAgentRuntime is a valid value for RuntimeConfig.Name.
// When set, enables agent runtime sidecar injection for the sandbox.
RuntimeConfigForInjectAgentRuntime = "agent-runtime"
)

type RuntimeConfig struct {
Name string `json:"name"`
}

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

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

// Runtimes - Runtime configuration for sandbox object
// +optional
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`

// PauseTime - Absolute time when the sandbox will be paused automatically.
// +kubebuilder:validation:Format="date-time"
PauseTime *metav1.Time `json:"pauseTime,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/sandboxclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ type SandboxClaimSpec struct {
// +optional
DynamicVolumesMount []CSIMountConfig `json:"dynamicVolumesMount"`

// Runtimes - Runtime configuration for sandbox object
// +optional
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`

// Set ReserveFailedSandbox to true to reserve failed sandboxes
// +optional
ReserveFailedSandbox bool `json:"reserveFailedSandbox,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/sandboxset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type SandboxSetSpec struct {
// PersistentContents indicates resume pod with persistent content, Enum: ip, memory, filesystem
PersistentContents []string `json:"persistentContents,omitempty"`

// Runtimes - Runtime configuration for sandbox object
// +optional
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`

EmbeddedSandboxTemplate `json:",inline"`

// ScaleStrategy indicates the ScaleStrategy that will be employed to
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/sandboxtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type SandboxTemplateSpec struct {

// PersistentContents indicates resume pod with persistent content, Enum: ip, memory, filesystem
PersistentContents []string `json:"persistentContents,omitempty"`

// Runtimes - Runtime configuration for sandbox object
// +optional
Runtimes []RuntimeConfig `json:"runtimes,omitempty"`
}

// +genclient
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions config/crd/bases/agents.kruise.io_sandboxclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ spec:
reserveFailedSandbox:
description: Set ReserveFailedSandbox to true to reserve failed sandboxes
type: boolean
runtimes:
description: Runtimes - Runtime configuration for sandbox object
items:
properties:
name:
type: string
required:
- name
type: object
type: array
shutdownTime:
description: |-
ShutdownTime specifies the absolute time when the sandbox should be shut down
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/agents.kruise.io_sandboxes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ spec:
items:
type: string
type: array
runtimes:
description: Runtimes - Runtime configuration for sandbox object
items:
properties:
name:
type: string
required:
- name
type: object
type: array
shutdownTime:
description: |-
ShutdownTime - Absolute time when the sandbox is deleted.
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/agents.kruise.io_sandboxsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ spec:
available and creating ones.
format: int32
type: integer
runtimes:
description: Runtimes - Runtime configuration for sandbox object
items:
properties:
name:
type: string
required:
- name
type: object
type: array
scaleStrategy:
description: |-
ScaleStrategy indicates the ScaleStrategy that will be employed to
Expand Down
28 changes: 18 additions & 10 deletions pkg/controller/sandbox/core/common_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1305,11 +1305,13 @@ func TestCommonControl_createPod_WithSidecarInjection(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-sandbox",
Namespace: "default",
Annotations: map[string]string{
agentsv1alpha1.ShouldInjectAgentRuntime: "true",
},
},
Spec: agentsv1alpha1.SandboxSpec{
Runtimes: []agentsv1alpha1.RuntimeConfig{
{
Name: agentsv1alpha1.RuntimeConfigForInjectAgentRuntime,
},
},
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
Template: &corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -1359,11 +1361,13 @@ func TestCommonControl_createPod_WithSidecarInjection(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-sandbox",
Namespace: "default",
Annotations: map[string]string{
agentsv1alpha1.ShouldInjectCsiMount: "true",
},
},
Spec: agentsv1alpha1.SandboxSpec{
Runtimes: []agentsv1alpha1.RuntimeConfig{
{
Name: agentsv1alpha1.RuntimeConfigForInjectCsiMount,
},
},
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
Template: &corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -1416,12 +1420,16 @@ func TestCommonControl_createPod_WithSidecarInjection(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-sandbox",
Namespace: "default",
Annotations: map[string]string{
agentsv1alpha1.ShouldInjectAgentRuntime: "true",
agentsv1alpha1.ShouldInjectCsiMount: "true",
},
},
Spec: agentsv1alpha1.SandboxSpec{
Runtimes: []agentsv1alpha1.RuntimeConfig{
{
Name: agentsv1alpha1.RuntimeConfigForInjectAgentRuntime,
},
{
Name: agentsv1alpha1.RuntimeConfigForInjectCsiMount,
},
},
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
Template: &corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/sandboxclaim/core/common_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func (c *commonControl) buildClaimOptions(ctx context.Context, claim *agentsv1al
}
}

if len(claim.Spec.Runtimes) > 0 {
opts.RuntimeConfig = claim.Spec.Runtimes
}

// Validate and initialize
return sandboxcr.ValidateAndInitClaimOptions(opts)
}
Expand Down
94 changes: 94 additions & 0 deletions pkg/controller/sandboxclaim/core/common_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,100 @@ func TestCommonControl_buildClaimOptions(t *testing.T) {
}
},
},
{
name: "claim with runtimes",
claim: &agentsv1alpha1.SandboxClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "test-claim-runtimes",
Namespace: "default",
UID: "test-uid-runtimes",
},
Spec: agentsv1alpha1.SandboxClaimSpec{
TemplateName: "test-template",
Runtimes: []agentsv1alpha1.RuntimeConfig{
{Name: agentsv1alpha1.RuntimeConfigForInjectCsiMount},
{Name: agentsv1alpha1.RuntimeConfigForInjectAgentRuntime},
},
},
},
sandboxSet: &agentsv1alpha1.SandboxSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-template",
Namespace: "default",
},
},
expectError: false,
validate: func(t *testing.T, opts infra.ClaimSandboxOptions) {
if opts.User != "test-uid-runtimes" {
t.Errorf("User = %v, want %v", opts.User, "test-uid-runtimes")
}
if len(opts.RuntimeConfig) != 2 {
t.Errorf("RuntimeConfig length = %v, want %v", len(opts.RuntimeConfig), 2)
}
if opts.RuntimeConfig[0].Name != agentsv1alpha1.RuntimeConfigForInjectCsiMount {
t.Errorf("RuntimeConfig[0].Name = %v, want %v", opts.RuntimeConfig[0].Name, agentsv1alpha1.RuntimeConfigForInjectCsiMount)
}
if opts.RuntimeConfig[1].Name != agentsv1alpha1.RuntimeConfigForInjectAgentRuntime {
t.Errorf("RuntimeConfig[1].Name = %v, want %v", opts.RuntimeConfig[1].Name, agentsv1alpha1.RuntimeConfigForInjectAgentRuntime)
}
},
},
{
name: "claim with single runtime",
claim: &agentsv1alpha1.SandboxClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "test-claim-single-runtime",
Namespace: "default",
UID: "test-uid-single-runtime",
},
Spec: agentsv1alpha1.SandboxClaimSpec{
TemplateName: "test-template",
Runtimes: []agentsv1alpha1.RuntimeConfig{
{Name: agentsv1alpha1.RuntimeConfigForInjectCsiMount},
},
},
},
sandboxSet: &agentsv1alpha1.SandboxSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-template",
Namespace: "default",
},
},
expectError: false,
validate: func(t *testing.T, opts infra.ClaimSandboxOptions) {
if len(opts.RuntimeConfig) != 1 {
t.Errorf("RuntimeConfig length = %v, want %v", len(opts.RuntimeConfig), 1)
}
if opts.RuntimeConfig[0].Name != agentsv1alpha1.RuntimeConfigForInjectCsiMount {
t.Errorf("RuntimeConfig[0].Name = %v, want %v", opts.RuntimeConfig[0].Name, agentsv1alpha1.RuntimeConfigForInjectCsiMount)
}
},
},
{
name: "claim without runtimes should have nil RuntimeConfig",
claim: &agentsv1alpha1.SandboxClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "test-claim-no-runtime",
Namespace: "default",
UID: "test-uid-no-runtime",
},
Spec: agentsv1alpha1.SandboxClaimSpec{
TemplateName: "test-template",
},
},
sandboxSet: &agentsv1alpha1.SandboxSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-template",
Namespace: "default",
},
},
expectError: false,
validate: func(t *testing.T, opts infra.ClaimSandboxOptions) {
if opts.RuntimeConfig != nil {
t.Errorf("RuntimeConfig should be nil when Runtimes is not specified, got %v", opts.RuntimeConfig)
}
},
},
}

for _, tt := range tests {
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/sandboxset/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"strings"
"time"

agentsv1alpha1 "github.com/openkruise/agents/api/v1alpha1"
"github.com/openkruise/agents/pkg/utils/expectations"
apps "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
logf "sigs.k8s.io/controller-runtime/pkg/log"

agentsv1alpha1 "github.com/openkruise/agents/api/v1alpha1"
"github.com/openkruise/agents/pkg/utils/expectations"
)

var (
Expand Down Expand Up @@ -167,6 +168,7 @@ func NewSandboxFromSandboxSet(sbs *agentsv1alpha1.SandboxSet) *agentsv1alpha1.Sa
},
Spec: agentsv1alpha1.SandboxSpec{
PersistentContents: sbs.Spec.PersistentContents,
Runtimes: sbs.Spec.Runtimes,
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
TemplateRef: sbs.Spec.TemplateRef,
Template: template,
Expand Down
Loading
Loading