Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNB command-line should only be rewritten if changed #4176

Merged
merged 1 commit into from
May 14, 2020
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
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)
}
})
}
}