Skip to content

Commit 650e618

Browse files
authored
CNB command-line should only be rewritten if changed (#4176)
1 parent dcf7574 commit 650e618

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

pkg/skaffold/debug/cnb.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ func updateForCNBImage(container *v1.Container, ic imageConfiguration, transform
6969
return ContainerDebugConfiguration{}, "", fmt.Errorf("buildpacks metadata has no processes")
7070
}
7171

72-
// the buildpacks launcher is retained as the entrypoint
72+
// The buildpacks launcher is retained as the entrypoint
7373
ic, rewriter := adjustCommandLine(m, ic)
7474
c, img, err := transformer(container, ic)
75-
if err == nil && rewriter != nil {
75+
76+
// Only rewrite the container.Args if set: some transforms only alter env vars,
77+
// and the image's arguments are not changed.
78+
if err == nil && container.Args != nil && rewriter != nil {
7679
container.Args = rewriter(container.Args)
7780
}
7881
return c, img, err

pkg/skaffold/debug/cnb_test.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,30 @@ func TestUpdateForCNBImage(t *testing.T) {
110110
},
111111
}
112112
for _, test := range tests {
113-
testutil.Run(t, test.description, func(t *testutil.T) {
114-
dummyTransform := func(c *v1.Container, ic imageConfiguration) (ContainerDebugConfiguration, string, error) {
113+
// Test that when a transform modifies the command-line arguments, then
114+
// the changes are reflected to the launcher command-line
115+
testutil.Run(t, test.description+" (args changed)", func(t *testutil.T) {
116+
argsChangedTransform := func(c *v1.Container, ic imageConfiguration) (ContainerDebugConfiguration, string, error) {
115117
c.Args = ic.arguments
116118
return ContainerDebugConfiguration{}, "", nil
117119
}
118-
119120
copy := v1.Container{}
120-
_, _, err := updateForCNBImage(&copy, test.input, dummyTransform)
121+
_, _, err := updateForCNBImage(&copy, test.input, argsChangedTransform)
121122
t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, copy)
122123
})
124+
125+
// Test that when the arguments are left unchanged, that the container is unchanged
126+
testutil.Run(t, test.description+" (args unchanged)", func(t *testutil.T) {
127+
argsUnchangedTransform := func(c *v1.Container, ic imageConfiguration) (ContainerDebugConfiguration, string, error) {
128+
return ContainerDebugConfiguration{}, "", nil
129+
}
130+
131+
copy := v1.Container{}
132+
_, _, err := updateForCNBImage(&copy, test.input, argsUnchangedTransform)
133+
t.CheckError(test.shouldErr, err)
134+
if copy.Args != nil {
135+
t.Errorf("args not nil: %v", copy.Args)
136+
}
137+
})
123138
}
124139
}

0 commit comments

Comments
 (0)