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
40 changes: 37 additions & 3 deletions charts/theia-cloud/templates/image-preloading.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,47 @@ spec:
# The pod can be killed instantly because it doesn't do any work requiring graceful shutdown
terminationGracePeriodSeconds: 0
initContainers:
{{- range $index, $image := $images }}
{{- range $index, $entry := $images }}
{{- $imageRef := "" }}
{{- $isMap := kindIs "map" $entry }}
{{- if $isMap }}
{{- $imageRef = tpl ($entry.image | toString) $ }}
{{- else }}
{{- $imageRef = tpl ($entry | toString) $ }}
{{- end }}
{{- $useShell := true }}
{{- $customCmd := list }}
{{- $customArgs := list }}
{{- $hasArgsKey := false }}
{{- if $isMap }}
{{- if or $entry.command (hasKey $entry "args") }}
{{- $useShell = false }}
{{- end }}
{{- with $entry.command }}
{{- $customCmd = . }}
{{- end }}
{{- if hasKey $entry "args" }}
{{- $hasArgsKey = true }}
{{- $customArgs = $entry.args }}
{{- end }}
Comment on lines +68 to +71
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Edge case: args: null would produce invalid YAML.

If a user explicitly sets args: ~ (null) in a map entry, hasKey returns true but $customArgs becomes nil. The toYaml call would render null, producing invalid YAML. This is a minor edge case but could cause confusing errors.

🛡️ Optional guard against nil args
        {{- if hasKey $entry "args" }}
          {{- $hasArgsKey = true }}
-         {{- $customArgs = $entry.args }}
+         {{- $customArgs = $entry.args | default list }}
        {{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/theia-cloud/templates/image-preloading.yaml` around lines 68 - 71, The
template currently treats a present but null args value as valid because hasKey
$entry "args" will be true even when $entry.args is nil; change the logic around
hasKey/$customArgs so you only set $hasArgsKey and $customArgs when $entry.args
is non-nil (e.g., test $entry.args or use an if ne $entry.args nil) and
otherwise leave $customArgs unset or set to an empty list; update any subsequent
toYaml usage to rely on $hasArgsKey or the non-nil $customArgs so you never call
toYaml on a nil value (inspect the same block using hasKey, $entry, $hasArgsKey,
and $customArgs to apply the guard).

{{- end }}
- name: image-preload-{{ $index }}
image: {{ $image }}
image: {{ $imageRef | quote }}
imagePullPolicy: {{ $imagePullPolicy }}
{{- if $useShell }}
command: ["/bin/sh", "-c"]
args:
- "echo 'Loaded image {{ $image }}'; exit 0"
- {{ printf "echo 'Loaded image %s'; exit 0" $imageRef | quote }}
{{- else }}
{{- with $customCmd }}
command:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- if $hasArgsKey }}
args:
{{- toYaml $customArgs | nindent 10 }}
{{- end }}
{{- end }}
{{- end }}
# Run the pause container to make the Pod go into the Running state without consuming resources
containers:
Expand Down
8 changes: 5 additions & 3 deletions charts/theia-cloud/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,11 @@ monitor:
preloading:
# -- Is image preloading enabled.
enable: true
# -- Images to preload. Images must support running /bin/sh.
# If the list is empty and demoApplication.install == true,
# demoApplication.name is automatically added.
# -- Images to preload. Each item is either an image reference string or a map:
# `{ image: "...", args: ["--version"] }` to use the image entrypoint (distroless-friendly),
# or `{ image: "...", command: [...], args: [...] }` for a full override. If only strings are used,
# the chart runs `/bin/sh -c 'echo …; exit 0'` (shell required in the image).
# If the list is empty and demoApplication.install == true, demoApplication.name is automatically added.
images: []
# -- Optional: Override the imagePullPolicy for the image preloading containers.
# If this is omitted or empty, the root at .Values.imagePullPolicy is used.
Expand Down
Loading