Skip to content

Commit 2ce47cf

Browse files
authored
pod overrides now work as expected (#7)
corev1.PodSpec has attributes that are not omitempty (presuambly because they are mandatory) which meant that the override spec would have nil on those attributes, resulting in a broken podspec. This PR also adds a symbolic e2e test because overrides was not tested at all in a real cluster.
1 parent bb27711 commit 2ce47cf

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

pkg/resources/pod.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,25 @@ func applyPodOverrides(base, overrides corev1.PodSpec) corev1.PodSpec {
378378
return base
379379
}
380380

381+
// We diff overrides against an empty PodSpec to produce a patch containing only
382+
// fields the user explicitly set (avoiding null fields from zero-value slices/maps
383+
// that would otherwise wipe out base fields like Containers).
384+
emptyJSON, err := json.Marshal(corev1.PodSpec{})
385+
if err != nil {
386+
return base
387+
}
388+
patch, err := strategicpatch.CreateTwoWayMergePatch(emptyJSON, overridesJSON, corev1.PodSpec{})
389+
if err != nil {
390+
return base
391+
}
392+
381393
patchMeta, err := strategicpatch.NewPatchMetaFromStruct(&corev1.PodSpec{})
382394
if err != nil {
383395
return base
384396
}
385397

386398
merged, err := strategicpatch.StrategicMergePatchUsingLookupPatchMeta(
387-
baseJSON, overridesJSON, patchMeta)
399+
baseJSON, patch, patchMeta)
388400
if err != nil {
389401
return base
390402
}

pkg/resources/pod_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ func TestBuildPod_PodOverrides(t *testing.T) {
310310
if pod.Spec.NodeSelector["gpu"] != "true" {
311311
t.Errorf("expected nodeSelector gpu='true', got '%s'", pod.Spec.NodeSelector["gpu"])
312312
}
313+
if pod.Spec.Containers == nil {
314+
t.Errorf("expected overrides not to touch container")
315+
}
313316
}
314317

315318
func TestBuildPod_CustomPort(t *testing.T) {

test/e2e/e2e_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,49 @@ spec:
441441
_, _ = utils.Run(cmd)
442442
})
443443

444+
It("should add volumes from podOverrides", func() {
445+
notebookName := "e2e-pod-overrides"
446+
447+
By("creating a MarimoNotebook with podOverrides volumes")
448+
notebookYAML := fmt.Sprintf(`
449+
apiVersion: marimo.io/v1alpha1
450+
kind: MarimoNotebook
451+
metadata:
452+
name: %s
453+
namespace: %s
454+
spec:
455+
source: "https://github.com/marimo-team/marimo.git"
456+
podOverrides:
457+
volumes:
458+
- name: ssh-pubkey
459+
secret:
460+
secretName: ssh-pubkey
461+
defaultMode: 0600
462+
`, notebookName, testNamespace)
463+
464+
yamlFile := filepath.Join("/tmp", notebookName+".yaml")
465+
err := os.WriteFile(yamlFile, []byte(notebookYAML), 0644)
466+
Expect(err).NotTo(HaveOccurred())
467+
468+
cmd := exec.Command("kubectl", "apply", "-f", yamlFile)
469+
_, err = utils.Run(cmd)
470+
Expect(err).NotTo(HaveOccurred(), "Failed to create MarimoNotebook")
471+
472+
By("verifying Pod has the overridden volume")
473+
verifyVolumePresent := func(g Gomega) {
474+
cmd := exec.Command("kubectl", "get", "pod", notebookName, "-n", testNamespace,
475+
"-o", `jsonpath={.spec.volumes[?(@.name=="ssh-pubkey")].secret.secretName}`)
476+
output, err := utils.Run(cmd)
477+
g.Expect(err).NotTo(HaveOccurred())
478+
g.Expect(output).To(Equal("ssh-pubkey"))
479+
}
480+
Eventually(verifyVolumePresent, 2*time.Minute, time.Second).Should(Succeed())
481+
482+
By("cleaning up")
483+
cmd = exec.Command("kubectl", "delete", "marimo", notebookName, "-n", testNamespace)
484+
_, _ = utils.Run(cmd)
485+
})
486+
444487
It("should create sidecar containers with exposed ports", func() {
445488
notebookName := "e2e-sidecar"
446489

0 commit comments

Comments
 (0)