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
7 changes: 6 additions & 1 deletion pkg/sandboxcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@
return sid, false, nil
}

var hosts []string
if raw := ctx.String("allowed-hosts"); raw != "" {

Check failure on line 77 in pkg/sandboxcli/commands.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "allowed-hosts" 4 times.

See more on https://sonarcloud.io/project/issues?id=xiaods_k8e&issues=AZ6ax2V6AQ80L8fB6pQm&open=AZ6ax2V6AQ80L8fB6pQm&pullRequest=495
hosts = strings.Split(raw, ",")
}
resp, err := client.SandboxServiceClient.CreateSession(context.Background(), &pb.CreateSessionRequest{
TenantId: ctx.String("tenant"), RuntimeClass: "gvisor",
TenantId: ctx.String("tenant"), RuntimeClass: "gvisor", AllowedHosts: hosts,
})
if err != nil {
return "", false, fmt.Errorf("create session: %w", err)
Expand Down Expand Up @@ -159,6 +163,7 @@
cli.StringFlag{Name: "git-repo", Usage: "Git repo to clone (only when auto-creating session)"},
cli.StringFlag{Name: "git-ref", Value: "main", Usage: "Git ref for --git-repo"},
cli.StringFlag{Name: "git-path", Value: "repo", Usage: "Destination path for --git-repo"},
cli.StringFlag{Name: "allowed-hosts", Usage: "Comma-separated FQDN egress allowlist (only when auto-creating session)"},
},
Action: runAction,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sandboxmatrix/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func newWarmPod(cfg config.SandboxConfig, runtimeClass string) *corev1.Pod {
GenerateName: "sandbox-warm-",
Namespace: cfg.Namespace,
Labels: map[string]string{sandboxgrpc.LabelState: sandboxgrpc.StateWarm},
Annotations: sandboxgrpc.GvisorAnnotations(runtimeClass),
},
Spec: warmPodSpec(runtimeClass, cfg),
}
Expand Down
28 changes: 25 additions & 3 deletions pkg/sandboxmatrix/grpc/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,10 @@ func (o *Orchestrator) claimOrCreatePod(ctx context.Context, sessionID, runtimeC
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("sandbox-%s", sessionID),
Namespace: sandboxNS,
Labels: map[string]string{labelState: stateActive, labelSessionID: sessionID},
Name: fmt.Sprintf("sandbox-%s", sessionID),
Namespace: sandboxNS,
Labels: map[string]string{labelState: stateActive, labelSessionID: sessionID},
Annotations: GvisorAnnotations(runtimeClass),
},
Spec: sandboxPodSpec(runtimeClass, pvcName, cpu, memory),
}
Expand Down Expand Up @@ -671,6 +672,17 @@ func SandboxPodSpec(runtimeClass, pvcName, cpu, memory, image string) corev1.Pod

func boolPtr(b bool) *bool { return &b }

// GvisorAnnotations returns pod annotations required for gVisor to work with
// Cilium eBPF. The default netstack mode processes network in userspace,
// bypassing Cilium's eBPF programs attached to veth pairs. Host network mode
// forwards syscalls to the pod's kernel network namespace instead.
func GvisorAnnotations(runtimeClass string) map[string]string {
if runtimeClass == "gvisor" {
return map[string]string{"gvisor.dev/network": "host"}
}
return nil
}

// ensureWorkspacePVC creates a PVC for the session workspace if it doesn't exist.
func (o *Orchestrator) ensureWorkspacePVC(ctx context.Context, sessionID string) (string, error) {
pvcName := "workspace-" + sessionID
Expand Down Expand Up @@ -721,6 +733,16 @@ func (o *Orchestrator) applyCNP(ctx context.Context, session *sandboxv1.SandboxS
"endpointSelector": map[string]interface{}{
"matchLabels": map[string]interface{}{labelSessionID: session.Name},
},
"ingress": []interface{}{
map[string]interface{}{
"fromEntities": []interface{}{"host"},
"toPorts": []interface{}{
map[string]interface{}{
"ports": []interface{}{map[string]interface{}{"port": "2024", "protocol": "TCP"}},
},
},
},
},
"egress": []interface{}{
map[string]interface{}{
"toEndpoints": []interface{}{
Expand Down
Loading