diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc index f4dd43691a..01437c2716 100644 --- a/docs/modules/ROOT/pages/cli/modeline.adoc +++ b/docs/modules/ROOT/pages/cli/modeline.adoc @@ -70,7 +70,7 @@ The following is a partial list of useful options: |Add a build time property or properties file (syntax: _[my-key=my-value\|file:/path/to/my-conf.properties]_ |config -|Add runtime configuration from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name)_ +|Add a runtime configuration from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name)_ |dependency |An external library that should be included, e.g. for Maven dependencies `dependency=mvn:org.my:app:1.0` @@ -94,7 +94,7 @@ The following is a partial list of useful options: |Add a runtime property or properties file (syntax: _[my-key=my-value\|file:/path/to/my-conf.properties]_) |resource -|Add a resource +|Add a runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name)_ |trait |Configure a trait, e.g. `trait=service.enabled=false` diff --git a/examples/modeline/modeline-secret-route.groovy b/examples/modeline/modeline-config-secret-route.groovy similarity index 95% rename from examples/modeline/modeline-secret-route.groovy rename to examples/modeline/modeline-config-secret-route.groovy index 0107b289f3..e6b9dab8eb 100644 --- a/examples/modeline/modeline-secret-route.groovy +++ b/examples/modeline/modeline-config-secret-route.groovy @@ -20,7 +20,7 @@ // To run this integrations use: // // kubectl create secret generic my-sec --from-literal=my-secret-key="very top secret" -// kamel run secret-route.groovy --dev +// kamel run modeline-config-secret-route.groovy --dev // // camel-k: config=secret:my-sec diff --git a/examples/modeline/modeline-resource-file-route.groovy b/examples/modeline/modeline-resource-file-route.groovy new file mode 100644 index 0000000000..e02777a4db --- /dev/null +++ b/examples/modeline/modeline-resource-file-route.groovy @@ -0,0 +1,27 @@ +// camel-k: language=groovy +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// To run this integrations use: +// kamel run modeline-resource-file-route.groovy --dev +// + +// camel-k: resource=file:resources-data.txt + +from('file:/etc/camel/data/resources/?fileName=resources-data.txt&noop=true&idempotent=false') + .log('resource file content is: ${body}') diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go index 0f540f85a3..cae66f6511 100644 --- a/pkg/cmd/modeline.go +++ b/pkg/cmd/modeline.go @@ -52,7 +52,6 @@ var ( // file options must be considered relative to the source files they belong to fileOptions = map[string]bool{ - "resource": true, "kube-config": true, "open-api": true, "property-file": true, @@ -60,6 +59,7 @@ var ( // file format options are those options that admit multiple values, not only files (ie, key=value|configmap|secret|file syntax) fileFormatOptions = map[string]bool{ + "resource": true, "config": true, "property": true, "build-property": true, diff --git a/pkg/cmd/modeline_test.go b/pkg/cmd/modeline_test.go index 6592939739..8b82d492b4 100644 --- a/pkg/cmd/modeline_test.go +++ b/pkg/cmd/modeline_test.go @@ -277,6 +277,79 @@ func TestModelineRunConfigFile(t *testing.T) { assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--config=file:%s", propFileName)}, flags) } +func TestModelineRunResourceConfigmap(t *testing.T) { + dir, err := ioutil.TempDir("", "camel-k-test-") + assert.NoError(t, err) + defer os.RemoveAll(dir) + + subDir := path.Join(dir, "sub") + err = os.Mkdir(subDir, 0777) + assert.NoError(t, err) + + file := ` + // camel-k: resource=configmap:my-cm + ` + fileName := path.Join(subDir, "simple.groovy") + err = ioutil.WriteFile(fileName, []byte(file), 0777) + 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, "--resource=configmap:my-cm"}, flags) +} + +func TestModelineRunResourceSecret(t *testing.T) { + dir, err := ioutil.TempDir("", "camel-k-test-") + assert.NoError(t, err) + defer os.RemoveAll(dir) + + subDir := path.Join(dir, "sub") + err = os.Mkdir(subDir, 0777) + assert.NoError(t, err) + + file := ` + // camel-k: resource=secret:my-secret + ` + fileName := path.Join(subDir, "simple.groovy") + err = ioutil.WriteFile(fileName, []byte(file), 0777) + 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, "--resource=secret:my-secret"}, flags) +} + +func TestModelineRunResourceFile(t *testing.T) { + dir, err := ioutil.TempDir("", "camel-k-test-") + assert.NoError(t, err) + defer os.RemoveAll(dir) + + subDir := path.Join(dir, "sub") + err = os.Mkdir(subDir, 0777) + assert.NoError(t, err) + + file := ` + // camel-k: resource=file:application.properties + ` + fileName := path.Join(subDir, "simple.groovy") + err = ioutil.WriteFile(fileName, []byte(file), 0777) + assert.NoError(t, err) + + propFile := ` + a=b + ` + propFileName := path.Join(subDir, "application.properties") + err = ioutil.WriteFile(propFileName, []byte(propFile), 0777) + 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, fmt.Sprintf("--resource=file:%s", propFileName)}, flags) +} + func TestModelineInspectSimple(t *testing.T) { dir, err := ioutil.TempDir("", "camel-k-test-") assert.NoError(t, err) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 971df2b156..b304800ca3 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -79,8 +79,8 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions) cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration") cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])") cmd.Flags().StringArray("build-property", nil, "Add a build time property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])") - cmd.Flags().StringArray("config", nil, "Add runtime configuration from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name)") - cmd.Flags().StringArray("resource", nil, "Add runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name)") + cmd.Flags().StringArray("config", nil, "Add a runtime configuration from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name)") + cmd.Flags().StringArray("resource", nil, "Add a runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name)") cmd.Flags().StringArray("configmap", nil, "[Deprecated] Add a ConfigMap") cmd.Flags().StringArray("secret", nil, "[Deprecated] Add a Secret") cmd.Flags().StringArray("maven-repository", nil, "Add a maven repository")