Skip to content

Commit

Permalink
fix: allow dashes in kaniko options (#6149)
Browse files Browse the repository at this point in the history
* fix: allow dashes in kaniko options

Fixes #5689

* test: fix test assertion

* chore: satisfy prettier

* chore: satisfy linter
  • Loading branch information
stefreak authored Jun 6, 2024
1 parent 98a5504 commit 5eaffa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/container/build/kaniko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ export const getKanikoFlags = (flags?: string[], topLevelFlags?: string[]): stri
return DEFAULT_KANIKO_FLAGS
}
const flagToKey = (flag: string) => {
const found = flag.match(/--([a-zA-Z]*)/)
const found = flag.match(/--([a-zA-Z-]*)/)
if (found === null) {
throw new ConfigurationError({
message: `Invalid format for a kaniko flag. Expected it to match /--([a-zA-Z]*)/, actually got: ${flag}`,
message: `Invalid format for a kaniko flag. Expected it to match /--([a-zA-Z-]*)/, actually got: ${flag}`,
})
}
return found[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ describe("kaniko build", () => {
expect(getKanikoFlags(["--myToggle"])).to.deep.equal(["--myToggle", "--cache=true"])
})

it("should allow options with dashes", () => {
expect(getKanikoFlags(["--my-toggle", "--my-name=banana"])).to.deep.equal([
"--my-toggle",
"--my-name=banana",
"--cache=true",
])
})

it("should throw if a flag is malformed", () => {
expect(() => getKanikoFlags(["--here=first", "-my-flag"])).to.throw(/Invalid format for a kaniko flag/)
})
Expand Down

0 comments on commit 5eaffa3

Please sign in to comment.