Skip to content

Commit

Permalink
cmd/operator-sdk/build: fix handling of spaces within quotes
Browse files Browse the repository at this point in the history
Before when running `operator-sdk build` with an `--image-build-arg` of
something like `--label some.name="First Last"` then `operator-sdk`
would invoke the builder with ["--label", "some.name=First", "Last"],
when it was actually desired to be ["--label", "some.name=First Last"].

Using `shlex` handles all the appropriate parsing of spaces within quotes
unlike `strings.Fields` which just splits on any spaces regardless of
context like quotes.

Switching to `shlex` enables `operator-sdk build` to now properly handle
spaces within quotes.
  • Loading branch information
dustinspecker committed Dec 10, 2019
1 parent 76b9041 commit 6d8048e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Fix scorecard behavior such that a CSV file is read correctly when `olm-deployed` is set to `true`. ([#2274](https://github.com/operator-framework/operator-sdk/pull/2274))
- A CSV config's `operator-name` field will be used if `--operator-name` is not set. ([#2297](https://github.com/operator-framework/operator-sdk/pull/2297))
- Populates a CSV's `spec.install` strategy if either name or strategy body are missing with a deployment-type strategy. ([#2298](https://github.com/operator-framework/operator-sdk/pull/2298))
- Fix `operator-sdk build`'s `--image-build-arg` to support spaces within quotes like `--label some.name="First Last"`.

## v0.12.0

Expand Down
6 changes: 5 additions & 1 deletion cmd/operator-sdk/build/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/operator-framework/operator-sdk/internal/scaffold"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

"github.com/google/shlex"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -73,7 +74,10 @@ func createBuildCommand(imageBuilder, context, dockerFile, image string, imageBu

for _, bargs := range imageBuildArgs {
if bargs != "" {
splitArgs := strings.Fields(bargs)
splitArgs, err := shlex.Split(bargs)
if err != nil {
return nil, fmt.Errorf("image-build-args is not parseable (%v)", err)
}
args = append(args, splitArgs...)
}
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/go-logr/zapr v0.1.1
github.com/gobuffalo/packr v1.30.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down

0 comments on commit 6d8048e

Please sign in to comment.