You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/06/20 07:27:14 UTC
[camel-k] branch release-1.8.x updated: Enable parsing pod template as a modeline.
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch release-1.8.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/release-1.8.x by this push:
new 4aa3643b0 Enable parsing pod template as a modeline.
4aa3643b0 is described below
commit 4aa3643b06cb78ebeb640cb5fa441870d45a7bf2
Author: Adriano Machado <unknown>
AuthorDate: Tue May 31 19:34:13 2022 -0400
Enable parsing pod template as a modeline.
---
go.mod | 3 ++-
go.sum | 5 +++--
pkg/cmd/modeline_test.go | 21 +++++++++++++++++++++
pkg/util/modeline/parser.go | 5 ++---
4 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/go.mod b/go.mod
index 231367315..e3c63cfc8 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,8 @@ require (
github.com/google/go-github/v32 v32.1.0
github.com/google/uuid v1.3.0
github.com/jpillora/backoff v1.0.0
- github.com/magiconair/properties v1.8.5
+ github.com/magiconair/properties v1.8.6
+ github.com/mattn/go-shellwords v1.0.3
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.4.1
github.com/onsi/gomega v1.16.0
diff --git a/go.sum b/go.sum
index 9aaf7452a..a230b3538 100644
--- a/go.sum
+++ b/go.sum
@@ -755,8 +755,9 @@ github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
-github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
+github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
+github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@@ -774,6 +775,7 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
+github.com/mattn/go-shellwords v1.0.3 h1:K/VxK7SZ+cvuPgFSLKi5QPI9Vr/ipOf4C1gN+ntueUk=
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -1803,7 +1805,6 @@ k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRV
k8s.io/code-generator v0.18.6/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
k8s.io/code-generator v0.19.2/go.mod h1:moqLn7w0t9cMs4+5CQyxnfA/HV8MF6aAVENF+WZZhgk=
k8s.io/code-generator v0.21.1/go.mod h1:hUlps5+9QaTrKx+jiM4rmq7YmH8wPOIko64uZCHDh6Q=
-k8s.io/code-generator v0.21.4 h1:vO8jVuEGV4UF+/2s/88Qg05MokE/1QUFi/Q2YDgz++A=
k8s.io/code-generator v0.21.4/go.mod h1:K3y0Bv9Cz2cOW2vXUrNZlFbflhuPvuadW6JdnN6gGKo=
k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM=
k8s.io/component-base v0.18.6/go.mod h1:knSVsibPR5K6EW2XOjEHik6sdU5nCvKMrzMt2D4In14=
diff --git a/pkg/cmd/modeline_test.go b/pkg/cmd/modeline_test.go
index 3907dc392..854bd52a9 100644
--- a/pkg/cmd/modeline_test.go
+++ b/pkg/cmd/modeline_test.go
@@ -507,3 +507,24 @@ func TestModelineInspectMultipleDeps(t *testing.T) {
assert.NoError(t, err)
}
+
+func TestModelineQuotedPodTemplate(t *testing.T) {
+ err := util.WithTempDir("camel-k-test-", func(dir string) error {
+
+ file := `
+ // camel-k: pod-template='{ "containers": [], "securityContext": { "supplementalGroups": [ 553 ] }, "volumes": [] } }'
+ `
+ fileName := path.Join(dir, "simple.groovy")
+ err := ioutil.WriteFile(fileName, []byte(file), 0o400)
+ assert.NoError(t, err)
+
+ cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+ assert.NoError(t, err)
+ assert.NotNil(t, cmd)
+ assert.Equal(t, []string{"run", fileName, "--pod-template={ \"containers\": [], \"securityContext\": { \"supplementalGroups\": [ 553 ] }, \"volumes\": [] } }"}, flags)
+
+ return nil
+ })
+
+ assert.NoError(t, err)
+}
diff --git a/pkg/util/modeline/parser.go b/pkg/util/modeline/parser.go
index 627f496b9..ab1eab580 100644
--- a/pkg/util/modeline/parser.go
+++ b/pkg/util/modeline/parser.go
@@ -24,14 +24,13 @@ import (
"strings"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/mattn/go-shellwords"
)
var (
commonModelineRegexp = regexp.MustCompile(`^\s*//\s*camel-k\s*:\s*([^\s]+.*)$`)
yamlModelineRegexp = regexp.MustCompile(`^\s*#+\s*camel-k\s*:\s*([^\s]+.*)$`)
xmlModelineRegexp = regexp.MustCompile(`^.*<!--\s*camel-k\s*:\s*([^\s]+[^>]*)-->.*$`)
-
- delimiter = regexp.MustCompile(`\s+`)
)
func Parse(name, content string) (res []Option, err error) {
@@ -53,7 +52,7 @@ func getModelineOptions(line string, lang v1.Language) (res []Option) {
}
strs := reg.FindStringSubmatch(line)
if len(strs) == 2 {
- tokens := delimiter.Split(strs[1], -1)
+ tokens, _ := shellwords.Parse(strs[1])
for _, token := range tokens {
if len(strings.Trim(token, "\t\n\f\r ")) == 0 {
continue