forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Problem
The
SetContainerImageFromRegistry
function incomponents/odh-notebook-controller/controllers/notebook_webhook.go
has a bug where it operates on the wrong slice element and drops environment variable edits.Details
Inside the
for _, container := range notebook.Spec.Template.Spec.Containers
loop (around lines 756-770), the code:
- Writes the image to
notebook.Spec.Template.Spec.Containers[0]
, irrespective of which container actually matched the notebook name- Modifies the copied
container
variable'sEnv
slice, but never writes it back to the parent slice, so theJUPYTER_IMAGE
update is lostSolution
Refactor to iterate with index and update in place:
-for _, container := range notebook.Spec.Template.Spec.Containers {
- if container.Name == notebook.Name {
+for idx, container := range notebook.Spec.Template.Spec.Containers {
- if container.Name == notebook.Name {
…
notebook.Spec.Template.Spec.Containers[0].Image = imageHash
notebook.Spec.Template.Spec.Containers[idx].Image = imageHash …
for i, envVar := range container.Env {
for i, envVar := range notebook.Spec.Template.Spec.Containers[idx].Env { if envVar.Name == "JUPYTER_IMAGE" {
container.Env[i].Value = imageSelection
}notebook.Spec.Template.Spec.Containers[idx].Env[i].Value = imageSelection break } } …
}
This guarantees the correct container is mutated and the environment variable change is persisted.Context
This issue was identified during review of PR #625 but is a pre-existing bug unrelated to that PR's changes.
Backlinks:
Metadata
Metadata
Assignees
Labels
No labels