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
17 changes: 10 additions & 7 deletions .github/workflows/chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5
- run: helm lint helm/mogenius-agent-sandbox
- name: render with default, GKE and multi-profile values
- name: render with default, GKE and apiserver-block values
run: |
helm template t helm/mogenius-agent-sandbox -n agent-sandbox-system >/dev/null
# GKE: a non-RFC1918 apiserver ClusterIP, blocked via the toggle, plus shm.
helm template t helm/mogenius-agent-sandbox -n agent-sandbox-system \
--set sandboxes.runtimeClassName=gvisor \
--set 'sandboxes.networkPolicy.additionalBlockedCidrs={34.118.224.0/20}' \
--set sandboxes.profiles.opencode.enabled=true \
--set sandboxes.profiles.platform-test.enabled=true >/dev/null
--set sandboxes.template.shmSizeLimit=1Gi \
--set sandboxes.networkPolicy.blockApiServer=true \
--set 'sandboxes.networkPolicy.apiServerCidrs={34.118.224.0/20}' \
--set 'sandboxes.networkPolicy.additionalBlockedCidrs={10.0.0.1/32}' >/dev/null
# Controller-default fallback: no explicit policy rendered.
helm template t helm/mogenius-agent-sandbox -n agent-sandbox-system \
--set sandboxes.networkPolicy.explicit=false >/dev/null
# A broken image string (whitespace, template leftovers) only shows up as
# InvalidImageName at runtime; catch it here for every profile.
# InvalidImageName at runtime; catch it here.
- name: image references parse
run: |
set -euo pipefail
helm template t helm/mogenius-agent-sandbox -n agent-sandbox-system \
--set sandboxes.profiles.opencode.enabled=true \
--set sandboxes.profiles.platform-test.enabled=true \
| grep -E '^[[:space:]]*image:' | sed -E 's/^[[:space:]]*image:[[:space:]]*//; s/"//g' | tee /tmp/images.txt
! grep -vE '^[a-z0-9]+([._-][a-z0-9]+)*(:[0-9]+)?(/[a-z0-9]+([._-][a-z0-9]+)*)*(:[A-Za-z0-9._-]+)?(@sha256:[0-9a-f]{64})?$' /tmp/images.txt
- name: CRDs match appVersion
Expand Down
4 changes: 2 additions & 2 deletions helm/mogenius-agent-sandbox/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: mogenius-agent-sandbox
description: >-
Complete agent-sandbox setup for a mogenius cluster: the kubernetes-sigs/agent-sandbox
controller with extensions (SandboxTemplate, SandboxClaim, SandboxWarmPool), plus a
sandbox namespace, a locked-down runtime ServiceAccount and configurable sandbox
profiles, each with its own SandboxTemplate and warm pool.
sandbox namespace, a locked-down runtime ServiceAccount, the default SandboxTemplate and
warm pool the SDK claims from, and a per-sandbox NetworkPolicy.
type: application
# Chart version — bump on every change to templates or values.
version: 1.2.1
Expand Down
8 changes: 3 additions & 5 deletions helm/mogenius-agent-sandbox/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ mogenius-agent-sandbox {{ .Chart.Version }} (agent-sandbox {{ include "mogenius-

Controller: {{ .Release.Namespace }}/agent-sandbox-controller
Sandboxes in: {{ include "mogenius-agent-sandbox.sandboxNamespace" . }}
{{- range $name, $p := .Values.sandboxes.profiles }}
{{- if $p.enabled }}
Profile "{{ $name }}": image {{ $p.image }}, warm pool {{ default 0 $p.warmPool.replicas }}{{ with (default $.Values.sandboxes.runtimeClassName $p.runtimeClassName) }}, runtimeClass {{ . }}{{ end }}
{{- end }}
{{- end }}
{{- $t := .Values.sandboxes.template }}
{{- $wp := default (dict) .Values.sandboxes.warmPool }}
Template "{{ default "default" $t.name }}": image {{ $t.image }}, warm pool {{ default 0 $wp.replicas }}{{ with (default .Values.sandboxes.runtimeClassName $t.runtimeClassName) }}, runtimeClass {{ . }}{{ end }}

Check the pool:
kubectl -n {{ include "mogenius-agent-sandbox.sandboxNamespace" . }} get sandboxwarmpool,sandboxes,pods
Expand Down
52 changes: 47 additions & 5 deletions helm/mogenius-agent-sandbox/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,53 @@ Namespace the sandbox pods live in.
{{- end }}

{{/*
Whether an explicit NetworkPolicy must be rendered into the template: only when
the operator adds ingress peers or blocks extra CIDRs. Otherwise the controller's
built-in default policy applies, which is what upstream tests against.
The NetworkPolicy spec body (ingress + egress) rendered into a managed
SandboxTemplate when networkPolicy.explicit is set. Egress allows the internet
minus the toggled blocks (RFC1918, the metadata endpoint, optionally the
apiserver, plus any additionalBlockedCidrs) and keeps DNS reachable.
*/}}
{{- define "mogenius-agent-sandbox.explicitNetworkPolicy" -}}
{{- define "mogenius-agent-sandbox.sandboxNetworkPolicy" -}}
{{- $np := .Values.sandboxes.networkPolicy -}}
{{- if and $np.managed (or $np.ingressFrom $np.additionalBlockedCidrs) -}}true{{- end -}}
{{- $except := list -}}
{{- if $np.blockRfc1918 -}}{{- $except = concat $except $np.rfc1918Cidrs -}}{{- end -}}
{{- if $np.blockMetadataEndpoint -}}{{- $except = concat $except $np.metadataCidrs -}}{{- end -}}
{{- if $np.blockApiServer -}}{{- $except = concat $except $np.apiServerCidrs -}}{{- end -}}
{{- if $np.additionalBlockedCidrs -}}{{- $except = concat $except $np.additionalBlockedCidrs -}}{{- end -}}
{{- /*
The CRD has no policyTypes: the controller always sets Ingress and Egress, so an
empty ingress list would deny all ingress. Without ingressFrom, keep the
controller's own default peer (the upstream sandbox router).
*/ -}}
{{- $ingressFrom := $np.ingressFrom -}}
{{- if not $ingressFrom -}}
{{- $ingressFrom = list (dict "namespaceSelector" (dict "matchLabels" (dict "kubernetes.io/metadata.name" "agent-sandbox-system")) "podSelector" (dict "matchLabels" (dict "app" "sandbox-router"))) -}}
{{- end }}
ingress:
- from:
{{- toYaml $ingressFrom | nindent 6 }}
egress:
{{- if $np.allowDns }}
- ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
{{- end }}
- to:
- ipBlock:
cidr: 0.0.0.0/0
{{- with $except }}
except:
{{- range . }}
- {{ . }}
{{- end }}
{{- end }}
{{- with $np.blockedCidrsV6 }}
- ipBlock:
cidr: ::/0
except:
{{- range . }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
{{- /*
One SandboxTemplate per enabled profile. The pod spec is assembled from the
profile's flat values (image, port, probes, storage, …) plus free-form
`podSpecExtra` / `containerExtra` for anything not modelled.
The default SandboxTemplate. The pod spec is assembled from the template's flat
values (image, port, probes, storage, …) plus free-form podSpecExtra /
containerExtra for anything not modelled. Additional templates are managed as
standalone objects by the platform UI (MOG-4749 / MOG-4756), not here.
*/ -}}
{{- $root := . }}
{{- $sb := .Values.sandboxes }}
{{- range $name, $p := .Values.sandboxes.profiles }}
{{- if $p.enabled }}
{{- $rtc := default $sb.runtimeClassName $p.runtimeClassName }}
{{- $containerName := default "sandbox" $p.containerName }}
{{- $port := int (default 0 $p.port) }}
{{- $t := $sb.template }}
{{- $np := $sb.networkPolicy }}
{{- $name := default "default" $t.name }}
{{- $rtc := default $sb.runtimeClassName $t.runtimeClassName }}
{{- $containerName := default "sandbox" $t.containerName }}
{{- $port := int (default 0 $t.port) }}
{{- /* Volumes and mounts from the modelled values come first, the ones from the
extras are appended, so both can be used without duplicate keys. */}}
{{- $mounts := list }}
{{- if and $p.storage $p.storage.enabled $p.storage.mountPath }}
{{- $mounts = append $mounts (dict "name" "workspace" "mountPath" $p.storage.mountPath) }}
{{- if and $t.storage $t.storage.enabled $t.storage.mountPath }}
{{- $mounts = append $mounts (dict "name" "workspace" "mountPath" $t.storage.mountPath) }}
{{- end }}
{{- $volumes := list }}
{{- with $p.shmSizeLimit }}
{{- with $t.shmSizeLimit }}
{{- $mounts = append $mounts (dict "name" "dshm" "mountPath" "/dev/shm") }}
{{- $volumes = append $volumes (dict "name" "dshm" "emptyDir" (dict "medium" "Memory" "sizeLimit" .)) }}
{{- end }}
{{- $containerExtra := default dict $p.containerExtra }}
{{- $podSpecExtra := default dict $p.podSpecExtra }}
{{- $containerExtra := default dict $t.containerExtra }}
{{- $podSpecExtra := default dict $t.podSpecExtra }}
{{- $mounts = concat $mounts (default list $containerExtra.volumeMounts) }}
{{- $volumes = concat $volumes (default list $podSpecExtra.volumes) }}
{{- $containerExtra = omit $containerExtra "volumeMounts" }}
{{- $podSpecExtra = omit $podSpecExtra "volumes" }}
---
apiVersion: extensions.agents.x-k8s.io/v1beta1
kind: SandboxTemplate
metadata:
Expand All @@ -44,52 +45,52 @@ spec:
{{- end }}
serviceAccountName: {{ $sb.serviceAccount.name }}
automountServiceAccountToken: false
{{- with $p.podSecurityContext }}
{{- with $t.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ $containerName }}
image: {{ required (printf "sandboxes.profiles.%s.image is required" $name) $p.image }}
{{- with $p.imagePullPolicy }}
image: {{ required "sandboxes.template.image is required" $t.image }}
{{- with $t.imagePullPolicy }}
imagePullPolicy: {{ . }}
{{- end }}
{{- with $p.command }}
{{- with $t.command }}
command:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $p.args }}
{{- with $t.args }}
args:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $p.env }}
{{- with $t.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if gt $port 0 }}
ports:
- containerPort: {{ $port }}
name: http
{{- if and $p.probes $p.probes.enabled }}
{{- if and $t.probes $t.probes.enabled }}
readinessProbe:
httpGet:
path: {{ default "/" $p.probes.path | quote }}
path: {{ default "/" $t.probes.path | quote }}
port: {{ $port }}
initialDelaySeconds: 0
periodSeconds: 1
livenessProbe:
httpGet:
path: {{ default "/" $p.probes.path | quote }}
path: {{ default "/" $t.probes.path | quote }}
port: {{ $port }}
initialDelaySeconds: 2
periodSeconds: 10
{{- end }}
{{- end }}
{{- with $p.securityContext }}
{{- with $t.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $p.resources }}
{{- with $t.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
Expand All @@ -100,7 +101,7 @@ spec:
{{- with $containerExtra }}
{{- toYaml . | nindent 10 }}
{{- end }}
restartPolicy: {{ default "OnFailure" $p.restartPolicy }}
restartPolicy: {{ default "OnFailure" $t.restartPolicy }}
{{- with $volumes }}
volumes:
{{- toYaml . | nindent 8 }}
Expand All @@ -109,49 +110,26 @@ spec:
{{- toYaml . | nindent 6 }}
{{- end }}
service: {{ $sb.service }}
{{- if $sb.networkPolicy.managed }}
{{- if $np.managed }}
networkPolicyManagement: Managed
{{- if include "mogenius-agent-sandbox.explicitNetworkPolicy" $root }}
{{- if $np.explicit }}
networkPolicy:
{{- with $sb.networkPolicy.ingressFrom }}
ingress:
- from:
{{- toYaml . | nindent 10 }}
{{- end }}
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
{{- range $sb.networkPolicy.blockedCidrs }}
- {{ . }}
{{- end }}
{{- range $sb.networkPolicy.additionalBlockedCidrs }}
- {{ . }}
{{- end }}
- ipBlock:
cidr: ::/0
except:
{{- range $sb.networkPolicy.blockedCidrsV6 }}
- {{ . }}
{{- end }}
{{- include "mogenius-agent-sandbox.sandboxNetworkPolicy" $root | trim | nindent 4 }}
{{- end }}
{{- else }}
networkPolicyManagement: Disabled
networkPolicyManagement: Unmanaged
{{- end }}
{{- if and $p.storage $p.storage.enabled }}
{{- if and $t.storage $t.storage.enabled }}
volumeClaimTemplatesPolicy: Overrides
volumeClaimTemplates:
- metadata:
name: workspace
spec:
accessModes: [ReadWriteOnce]
{{- with $p.storage.storageClassName }}
{{- with $t.storage.storageClassName }}
storageClassName: {{ . }}
{{- end }}
resources:
requests:
storage: {{ default "1Gi" $p.storage.size }}
storage: {{ default "1Gi" $t.storage.size }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{{- /*
One SandboxWarmPool per enabled profile, also with 0 replicas: SandboxClaims
reference the pool, so it has to exist for a profile to be claimable at all.
With replicas > 0 the pool keeps sandboxes pre-warmed so a claim binds in
The warm pool for the default SandboxTemplate. Rendered even at 0 replicas:
SandboxClaims reference the pool, so it has to exist for the template to be
claimable at all. replicas > 0 keeps sandboxes pre-warmed so a claim binds in
seconds instead of waiting for a pod to start.
*/ -}}
{{- $root := . }}
{{- range $name, $p := .Values.sandboxes.profiles }}
{{- if $p.enabled }}
---
{{- $sb := .Values.sandboxes }}
{{- $t := $sb.template }}
{{- $wp := default (dict) $sb.warmPool }}
{{- $name := default "default" $t.name }}
apiVersion: extensions.agents.x-k8s.io/v1beta1
kind: SandboxWarmPool
metadata:
Expand All @@ -17,12 +18,10 @@ metadata:
{{- include "mogenius-agent-sandbox.labels" $root | nindent 4 }}
mogenius.io/sandbox-profile: {{ $name }}
spec:
replicas: {{ int (default 0 (default (dict) $p.warmPool).replicas) }}
replicas: {{ int (default 0 $wp.replicas) }}
sandboxTemplateRef:
name: {{ $name }}
{{- with (default (dict) $p.warmPool).updateStrategy }}
{{- with $wp.updateStrategy }}
updateStrategy:
type: {{ . }}
{{- end }}
{{- end }}
{{- end }}
Loading
Loading