Skip to content

Commit

Permalink
CNB command-line should only be rewritten if changed (#4176)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandealwis authored May 14, 2020
1 parent dcf7574 commit 650e618
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
7 changes: 5 additions & 2 deletions pkg/skaffold/debug/cnb.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ func updateForCNBImage(container *v1.Container, ic imageConfiguration, transform
return ContainerDebugConfiguration{}, "", fmt.Errorf("buildpacks metadata has no processes")
}

// the buildpacks launcher is retained as the entrypoint
// The buildpacks launcher is retained as the entrypoint
ic, rewriter := adjustCommandLine(m, ic)
c, img, err := transformer(container, ic)
if err == nil && rewriter != nil {

// Only rewrite the container.Args if set: some transforms only alter env vars,
// and the image's arguments are not changed.
if err == nil && container.Args != nil && rewriter != nil {
container.Args = rewriter(container.Args)
}
return c, img, err
Expand Down
23 changes: 19 additions & 4 deletions pkg/skaffold/debug/cnb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,30 @@ func TestUpdateForCNBImage(t *testing.T) {
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
dummyTransform := func(c *v1.Container, ic imageConfiguration) (ContainerDebugConfiguration, string, error) {
// Test that when a transform modifies the command-line arguments, then
// the changes are reflected to the launcher command-line
testutil.Run(t, test.description+" (args changed)", func(t *testutil.T) {
argsChangedTransform := func(c *v1.Container, ic imageConfiguration) (ContainerDebugConfiguration, string, error) {
c.Args = ic.arguments
return ContainerDebugConfiguration{}, "", nil
}

copy := v1.Container{}
_, _, err := updateForCNBImage(&copy, test.input, dummyTransform)
_, _, err := updateForCNBImage(&copy, test.input, argsChangedTransform)
t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, copy)
})

// Test that when the arguments are left unchanged, that the container is unchanged
testutil.Run(t, test.description+" (args unchanged)", func(t *testutil.T) {
argsUnchangedTransform := func(c *v1.Container, ic imageConfiguration) (ContainerDebugConfiguration, string, error) {
return ContainerDebugConfiguration{}, "", nil
}

copy := v1.Container{}
_, _, err := updateForCNBImage(&copy, test.input, argsUnchangedTransform)
t.CheckError(test.shouldErr, err)
if copy.Args != nil {
t.Errorf("args not nil: %v", copy.Args)
}
})
}
}

0 comments on commit 650e618

Please sign in to comment.