You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/06/16 12:05:00 UTC
[camel-k] branch main updated (18e9916 -> 73339cf)
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from 18e9916 Updated CHANGELOG.md
new 890b4df feat(cmd/run): resource option refactoring
new 252eb52 refactor(crd): configuration resource type
new 95a51ef refactor(example): resource run option
new 44ba564 refactor(e2e): resource option integration test
new b9dbe12 feat(cmd/run): --resource filename compatibility
new 165fa3a feat(cmd/run): modeline resource support
new 1f95852 feat(cmd/run): resource @path support
new 573ea1b chore(crd): autogen update
new 1446a6c doc(example): resource @path
new 4697722 feat(cmd/run): file size limitation
new ba4a25f refactor(cmd/run): synch all option files
new ad5831a chore(e2e): run option with destination path
new 3cd69e4 feat(cmd/run): validate destination path
new fdf7fe4 fix(e2e): test name typo
new e938c50 feat(cmd/run): configmap/secret key filtering
new 7a31b30 chore(crd): configmap/secret eky filtering regen
new 90cbbda chore(e2e): configmap/secret key test
new 18f34ac doc(example): configmap/secret key selection
new 4465e1a feat(cmd/run): warn when using path on --config
new 73339cf chore(cmd/run): single resource dir and cli syntax description
The 20 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
config/crd/bases/camel.apache.org_builds.yaml | 4 +
.../bases/camel.apache.org_integrationkits.yaml | 6 +
.../camel.apache.org_integrationplatforms.yaml | 12 ++
.../crd/bases/camel.apache.org_integrations.yaml | 20 +++
.../bases/camel.apache.org_kameletbindings.yaml | 10 ++
config/crd/bases/camel.apache.org_kamelets.yaml | 2 +
.../1.5.0-snapshot/camel.apache.org_builds.yaml | 4 +
.../camel.apache.org_integrationkits.yaml | 6 +
.../camel.apache.org_integrationplatforms.yaml | 12 ++
.../camel.apache.org_integrations.yaml | 20 +++
.../camel.apache.org_kameletbindings.yaml | 10 ++
.../1.5.0-snapshot/camel.apache.org_kamelets.yaml | 2 +
docs/modules/ROOT/pages/cli/modeline.adoc | 4 +-
e2e/common/config/config_test.go | 120 +++++++++----
.../config/files/build-property-file-route.groovy | 8 -
.../config/files/build-property-route.groovy | 8 -
.../config/files/config-configmap-route.groovy | 7 +-
e2e/common/config/files/config-file-route.groovy | 5 -
.../common/config/files/config-secret-route.groovy | 7 +-
e2e/common/config/files/property-file-route.groovy | 6 -
e2e/common/config/files/property-route.groovy | 6 -
.../resource-configmap-key-location-route.groovy | 4 +-
.../resource-configmap-location-route.groovy} | 8 +-
.../files/resource-configmap-route.groovy} | 8 +-
.../resource-file-base64-encoded-route.groovy | 5 -
.../config/files/resource-file-binary-route.groovy | 5 -
.../files/resource-file-location-route.groovy | 4 +-
.../common/config/files/resource-file-route.groovy | 5 -
.../files/resource-secret-route.groovy} | 8 +-
....groovy => modeline-config-secret-route.groovy} | 2 +-
.../modeline/modeline-resource-file-route.groovy | 6 +-
...-route.groovy => config-configmap-route.groovy} | 2 +-
examples/user-config/config-file-route.groovy | 6 +-
.../config-secret-key-route.groovy} | 8 +-
.../user-config/config-secret-route.groovy | 2 +-
.../resource-configmap-key-location-route.groovy | 11 +-
.../resource-configmap-location-route.groovy | 11 +-
...oute.groovy => resource-configmap-route.groovy} | 11 +-
.../resource-file-base64-encoded-route.groovy | 2 +-
.../user-config/resource-file-binary-route.groovy | 2 +-
.../resource-file-location-route.groovy | 4 +-
.../user-config/resource-file-route.groovy | 2 +-
...roovy => resource-secret-location-route.groovy} | 11 +-
...t-route.groovy => resource-secret-route.groovy} | 11 +-
helm/camel-k/crds/crd-build.yaml | 4 +
helm/camel-k/crds/crd-integration-kit.yaml | 6 +
helm/camel-k/crds/crd-integration-platform.yaml | 12 ++
helm/camel-k/crds/crd-integration.yaml | 20 +++
helm/camel-k/crds/crd-kamelet-binding.yaml | 10 ++
helm/camel-k/crds/crd-kamelet.yaml | 2 +
pkg/apis/camel/v1/common_types.go | 14 +-
pkg/apis/camel/v1/integration_types_support.go | 12 ++
pkg/cmd/modeline.go | 2 +-
pkg/cmd/modeline_test.go | 73 ++++++++
pkg/cmd/run.go | 53 ++----
pkg/cmd/run_help.go | 196 ++++++++++++++++++---
pkg/cmd/run_help_test.go | 133 +++++++++++++-
pkg/cmd/run_test.go | 8 +-
pkg/cmd/util_content.go | 14 ++
pkg/trait/environment.go | 4 +-
pkg/trait/jvm.go | 3 +-
pkg/trait/jvm_test.go | 9 +-
pkg/trait/trait_test.go | 14 +-
pkg/trait/trait_types.go | 114 +++++++++---
pkg/trait/util.go | 30 ++++
65 files changed, 879 insertions(+), 271 deletions(-)
copy examples/cron/cron.groovy => e2e/common/config/files/config-configmap-route.groovy (85%)
copy examples/cron/cron.groovy => e2e/common/config/files/config-secret-route.groovy (85%)
copy examples/knative/reader.groovy => e2e/common/config/files/resource-configmap-key-location-route.groovy (89%)
copy e2e/common/{traits/files/PodTest.groovy => config/files/resource-configmap-location-route.groovy} (87%)
copy e2e/common/{traits/files/PodTest.groovy => config/files/resource-configmap-route.groovy} (85%)
rename examples/user-config/resources-base64-encoded-route.groovy => e2e/common/config/files/resource-file-base64-encoded-route.groovy (87%)
rename examples/user-config/resources-binary-route.groovy => e2e/common/config/files/resource-file-binary-route.groovy (88%)
copy examples/knative/reader.groovy => e2e/common/config/files/resource-file-location-route.groovy (88%)
rename examples/user-config/resources-route.groovy => e2e/common/config/files/resource-file-route.groovy (89%)
copy e2e/common/{traits/files/PodTest.groovy => config/files/resource-secret-route.groovy} (85%)
copy examples/modeline/{modeline-secret-route.groovy => modeline-config-secret-route.groovy} (95%)
copy e2e/common/config/files/resources-route.groovy => examples/modeline/modeline-resource-file-route.groovy (82%)
copy examples/user-config/{configmap-route.groovy => config-configmap-route.groovy} (93%)
rename examples/{modeline/modeline-secret-route.groovy => user-config/config-secret-key-route.groovy} (76%)
rename e2e/common/config/files/secret-route.groovy => examples/user-config/config-secret-route.groovy (94%)
copy e2e/common/config/files/config-file-route.groovy => examples/user-config/resource-configmap-key-location-route.groovy (66%)
rename e2e/common/config/files/configmap-route.groovy => examples/user-config/resource-configmap-location-route.groovy (80%)
rename examples/user-config/{configmap-route.groovy => resource-configmap-route.groovy} (80%)
rename e2e/common/config/files/resources-base64-encoded-route.groovy => examples/user-config/resource-file-base64-encoded-route.groovy (96%)
rename e2e/common/config/files/resources-binary-route.groovy => examples/user-config/resource-file-binary-route.groovy (91%)
copy e2e/common/config/files/resources-route.groovy => examples/user-config/resource-file-location-route.groovy (84%)
rename e2e/common/config/files/resources-route.groovy => examples/user-config/resource-file-route.groovy (92%)
copy examples/user-config/{secret-route.groovy => resource-secret-location-route.groovy} (81%)
rename examples/user-config/{secret-route.groovy => resource-secret-route.groovy} (81%)
[camel-k] 01/20: feat(cmd/run): resource option refactoring
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 890b4df49c71b08040373a74fc2f8b70d6ebedff
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 10:41:48 2021 +0200
feat(cmd/run): resource option refactoring
* Provide support for configmap, secret or local file
* Refactoring the structure of mount points to distinguish clearly between config and resource options
Ref #2003
---
pkg/apis/camel/v1/common_types.go | 11 ++--
pkg/apis/camel/v1/integration_types_support.go | 9 ++++
pkg/cmd/run.go | 46 +++-------------
pkg/cmd/run_help.go | 55 +++++++++++++++++---
pkg/cmd/run_test.go | 8 +--
pkg/trait/environment.go | 4 +-
pkg/trait/jvm.go | 1 -
pkg/trait/jvm_test.go | 8 +--
pkg/trait/trait_test.go | 24 +++++----
pkg/trait/trait_types.go | 72 +++++++++++++++++++-------
pkg/trait/util.go | 28 ++++++++++
11 files changed, 175 insertions(+), 91 deletions(-)
diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go
index aeedb75..6b2cda8 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -26,8 +26,9 @@ const TraitAnnotationPrefix = "trait.camel.apache.org/"
// ConfigurationSpec --
type ConfigurationSpec struct {
- Type string `json:"type"`
- Value string `json:"value"`
+ Type string `json:"type"`
+ Value string `json:"value"`
+ ResourceType string `json:"resourceType,omitempty"`
}
// Artifact --
@@ -196,9 +197,11 @@ type ResourceSpec struct {
}
const (
- // ResourceTypeData --
+ // ResourceTypeData represents a generic data resource
ResourceTypeData ResourceType = "data"
- // ResourceTypeOpenAPI --
+ // ResourceTypeConfig represents a config resource known to runtime
+ ResourceTypeConfig ResourceType = "config"
+ // ResourceTypeOpenAPI represents an OpenAPI config resource
ResourceTypeOpenAPI ResourceType = "openapi"
)
diff --git a/pkg/apis/camel/v1/integration_types_support.go b/pkg/apis/camel/v1/integration_types_support.go
index 1ba06f5..acf3bd6 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -109,6 +109,15 @@ func (in *IntegrationSpec) AddConfiguration(confType string, confValue string) {
})
}
+// AddConfigurationAsResourceType will set a configuration specified with a resource type
+func (in *IntegrationSpec) AddConfigurationAsResourceType(confType string, confValue string, resourceType string) {
+ in.Configuration = append(in.Configuration, ConfigurationSpec{
+ Type: confType,
+ Value: confValue,
+ ResourceType: resourceType,
+ })
+}
+
// AddDependency --
func (in *IntegrationSpec) AddDependency(dependency string) {
if in.Dependencies == nil {
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 403a799..69fcfe8 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -82,6 +82,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
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("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")
@@ -93,7 +94,6 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
cmd.Flags().StringArrayP("trait", "t", nil, "Configure a trait. E.g. \"-t service.enabled=false\"")
cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
cmd.Flags().Bool("compression", false, "Enable storage of sources and resources as a compressed binary blobs")
- cmd.Flags().StringArray("resource", nil, "Add a resource")
cmd.Flags().StringArray("open-api", nil, "Add an OpenAPI v2 spec")
cmd.Flags().StringArrayP("volume", "v", nil, "Mount a volume into the integration container. E.g \"-v pvcname:/container/path\"")
cmd.Flags().StringArrayP("env", "e", nil, "Set an environment variable in the integration container. E.g \"-e MY_VAR=my-value\"")
@@ -544,16 +544,13 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
}
for _, resource := range o.Resources {
- rawData, contentType, err := loadRawContent(resource)
- if err != nil {
- return nil, err
- }
-
- resourceSpec, err := binaryOrTextResource(path.Base(resource), rawData, contentType, o.Compression)
- if err != nil {
- return nil, err
+ if config, parseErr := ParseConfigOption(resource); parseErr == nil {
+ if applyResourceOptionErr := ApplyResourceOption(config, &integration.Spec, c, namespace, o.Compression); applyResourceOptionErr != nil {
+ return nil, applyResourceOptionErr
+ }
+ } else {
+ return nil, parseErr
}
- integration.Spec.AddResources(resourceSpec)
}
for _, resource := range o.OpenAPIs {
@@ -718,35 +715,6 @@ func keyValueProps(value string) (*properties.Properties, error) {
return properties.Load([]byte(value), properties.UTF8)
}
-func binaryOrTextResource(fileName string, data []byte, contentType string, base64Compression bool) (v1.ResourceSpec, error) {
- resourceSpec := v1.ResourceSpec{
- DataSpec: v1.DataSpec{
- Name: fileName,
- ContentKey: fileName,
- ContentType: contentType,
- Compression: false,
- },
- Type: v1.ResourceTypeData,
- }
-
- if !base64Compression && isBinary(contentType) {
- resourceSpec.RawContent = data
- return resourceSpec, nil
- }
- // either is a text resource or base64 compression is enabled
- if base64Compression {
- content, err := compressToString(data)
- if err != nil {
- return resourceSpec, err
- }
- resourceSpec.Content = content
- resourceSpec.Compression = true
- } else {
- resourceSpec.Content = string(data)
- }
- return resourceSpec, nil
-}
-
func (o *runCmdOptions) GetIntegrationName(sources []string) string {
name := ""
if o.IntegrationName != "" {
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index 2f78b79..927d7b8 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -76,43 +76,82 @@ func ParseConfigOption(item string) (*RunConfigOption, error) {
return newRunConfigOption(cot, groups[2]), nil
}
-// ApplyConfigOption will set the proper option behavior to the IntegrationSpec
-func ApplyConfigOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
+func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
+ c client.Client, namespace string, enableCompression bool, resourceType v1.ResourceType) error {
switch config.ConfigType {
case ConfigOptionTypeConfigmap:
cm := kubernetes.LookupConfigmap(context.Background(), c, namespace, config.Value)
if cm == nil {
fmt.Printf("Warn: %s Configmap not found in %s namespace, make sure to provide it before the Integration can run\n",
config.Value, namespace)
- } else if cm.BinaryData != nil {
+ } else if resourceType != v1.ResourceTypeData && cm.BinaryData != nil {
return fmt.Errorf("you cannot provide a binary config, use a text file instead")
}
- integrationSpec.AddConfiguration(string(config.ConfigType), config.Value)
+ integrationSpec.AddConfigurationAsResourceType(string(config.ConfigType), config.Value, string(resourceType))
case ConfigOptionTypeSecret:
secret := kubernetes.LookupSecret(context.Background(), c, namespace, config.Value)
if secret == nil {
fmt.Printf("Warn: %s Secret not found in %s namespace, make sure to provide it before the Integration can run\n",
config.Value, namespace)
}
- integrationSpec.AddConfiguration(string(config.ConfigType), config.Value)
+ integrationSpec.AddConfigurationAsResourceType(string(config.ConfigType), config.Value, string(resourceType))
case ConfigOptionTypeFile:
// Don't allow a binary non compressed resource
rawData, contentType, err := loadRawContent(config.Value)
if err != nil {
return err
}
- if !enableCompression && isBinary(contentType) {
+ if resourceType != v1.ResourceTypeData && !enableCompression && isBinary(contentType) {
return fmt.Errorf("you cannot provide a binary config, use a text file or check --resource flag instead")
}
- resourceSpec, err := binaryOrTextResource(path.Base(config.Value), rawData, contentType, enableCompression)
+ resourceSpec, err := binaryOrTextResource(path.Base(config.Value), rawData, contentType, enableCompression, resourceType)
if err != nil {
return err
}
integrationSpec.AddResources(resourceSpec)
default:
// Should never reach this
- return fmt.Errorf("invalid config option type %s", config.ConfigType)
+ return fmt.Errorf("invalid option type %s", config.ConfigType)
}
return nil
}
+
+// ApplyConfigOption will set the proper --config option behavior to the IntegrationSpec
+func ApplyConfigOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
+ return applyOption(config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeConfig)
+}
+
+// ApplyResourceOption will set the proper --resource option behavior to the IntegrationSpec
+func ApplyResourceOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
+ return applyOption(config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeData)
+}
+
+func binaryOrTextResource(fileName string, data []byte, contentType string, base64Compression bool, resourceType v1.ResourceType) (v1.ResourceSpec, error) {
+ resourceSpec := v1.ResourceSpec{
+ DataSpec: v1.DataSpec{
+ Name: fileName,
+ ContentKey: fileName,
+ ContentType: contentType,
+ Compression: false,
+ },
+ Type: resourceType,
+ }
+
+ if !base64Compression && isBinary(contentType) {
+ resourceSpec.RawContent = data
+ return resourceSpec, nil
+ }
+ // either is a text resource or base64 compression is enabled
+ if base64Compression {
+ content, err := compressToString(data)
+ if err != nil {
+ return resourceSpec, err
+ }
+ resourceSpec.Content = content
+ resourceSpec.Compression = true
+ } else {
+ resourceSpec.Content = string(data)
+ }
+ return resourceSpec, nil
+}
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index e15354d..7d1f8cd 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -487,7 +487,7 @@ func TestRunWithSavedValues(t *testing.T) {
}*/
func TestRunBinaryResource(t *testing.T) {
- binaryResourceSpec, err := binaryOrTextResource("file.ext", []byte{1, 2, 3, 4}, "application/octet-stream", false)
+ binaryResourceSpec, err := binaryOrTextResource("file.ext", []byte{1, 2, 3, 4}, "application/octet-stream", false, v1.ResourceTypeData)
assert.Nil(t, err)
assert.Equal(t, "", binaryResourceSpec.Content)
assert.NotNil(t, binaryResourceSpec.RawContent)
@@ -499,7 +499,7 @@ func TestRunBinaryResource(t *testing.T) {
func TestRunBinaryCompressedResource(t *testing.T) {
data := []byte{1, 2, 3, 4}
base64Compressed, _ := compressToString(data)
- binaryResourceSpec, err := binaryOrTextResource("file.ext", data, "application/octet-stream", true)
+ binaryResourceSpec, err := binaryOrTextResource("file.ext", data, "application/octet-stream", true, v1.ResourceTypeData)
assert.Nil(t, err)
assert.Equal(t, base64Compressed, binaryResourceSpec.Content)
assert.Nil(t, binaryResourceSpec.RawContent)
@@ -509,7 +509,7 @@ func TestRunBinaryCompressedResource(t *testing.T) {
}
func TestRunTextResource(t *testing.T) {
- textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello world"), "text/plain", false)
+ textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello world"), "text/plain", false, v1.ResourceTypeData)
assert.Nil(t, err)
assert.Equal(t, "hello world", textResourceSpec.Content)
assert.Nil(t, textResourceSpec.RawContent)
@@ -521,7 +521,7 @@ func TestRunTextResource(t *testing.T) {
func TestRunTextCompressedResource(t *testing.T) {
data := []byte("hello horld")
base64Compressed, _ := compressToString(data)
- textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello horld"), "text/plain", true)
+ textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello horld"), "text/plain", true, v1.ResourceTypeData)
assert.Nil(t, err)
assert.Equal(t, base64Compressed, textResourceSpec.Content)
assert.Nil(t, textResourceSpec.RawContent)
diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go
index 30b396e..bfc8cae 100644
--- a/pkg/trait/environment.go
+++ b/pkg/trait/environment.go
@@ -72,8 +72,8 @@ func (t *environmentTrait) Apply(e *Environment) error {
envvar.SetVal(&e.EnvVars, envVarCamelKIntegration, e.Integration.Name)
}
envvar.SetVal(&e.EnvVars, envVarCamelKRuntimeVersion, e.RuntimeVersion)
- envvar.SetVal(&e.EnvVars, envVarMountPathConfigMaps, configMapsMountPath)
- envvar.SetVal(&e.EnvVars, envVarMountPathSecrets, secretsMountPath)
+ envvar.SetVal(&e.EnvVars, envVarMountPathConfigMaps, configConfigmapsMountPath)
+ envvar.SetVal(&e.EnvVars, envVarMountPathSecrets, configSecretsMountPath)
if util.IsNilOrTrue(t.ContainerMeta) {
envvar.SetValFrom(&e.EnvVars, envVarNamespace, "metadata.namespace")
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 2d722e2..725f84c 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -95,7 +95,6 @@ func (t *jvmTrait) Apply(e *Environment) error {
classpath := strset.New()
- classpath.Add(resourcesMountPath)
classpath.Add("./resources")
for _, artifact := range kit.Status.Artifacts {
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index 2572dc1..cfa925c 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -103,12 +103,12 @@ func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("/etc/camel/resources", "./resources", "/mount/path").List()
+ cp := strset.New("./resources", "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- "./resources:/etc/camel/resources:/mount/path",
+ "./resources:/mount/path",
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, d.Spec.Template.Spec.Containers[0].Args)
}
@@ -135,12 +135,12 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("/etc/camel/resources", "./resources", "/mount/path").List()
+ cp := strset.New("./resources", "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- "./resources:/etc/camel/resources:/mount/path",
+ "./resources:/mount/path",
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, s.Spec.Template.Spec.Containers[0].Args)
}
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index e1bea3b..f49a5b0 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -253,12 +253,14 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
Value: "a=b",
},
{
- Type: "configmap",
- Value: "test-configmap",
+ Type: "configmap",
+ Value: "test-configmap",
+ ResourceType: "config",
},
{
- Type: "secret",
- Value: "test-secret",
+ Type: "secret",
+ Value: "test-secret",
+ ResourceType: "config",
},
{
Type: "volume",
@@ -313,7 +315,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "i-resource-001" })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/resources/res2.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/data/resources/res2.txt", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeploymentName+"-resource-002" })
assert.NotNil(t, v)
@@ -324,7 +326,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "i-resource-002" })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/resources/res3.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/data/resources/res3.txt", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeploymentName+"-resource-003" })
assert.NotNil(t, v)
@@ -335,7 +337,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "i-resource-003" })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/resources/res4.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/data/resources/res4.txt", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == "test-configmap" })
assert.NotNil(t, v)
@@ -345,7 +347,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "test-configmap" })
assert.NotNil(t, m)
- assert.Equal(t, path.Join(configMapsMountPath, "test-configmap"), m.MountPath)
+ assert.Equal(t, path.Join(configConfigmapsMountPath, "test-configmap"), m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.Name == "test-secret" })
assert.NotNil(t, v)
@@ -354,7 +356,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "test-secret" })
assert.NotNil(t, m)
- assert.Equal(t, path.Join(secretsMountPath, "test-secret"), m.MountPath)
+ assert.Equal(t, path.Join(configSecretsMountPath, "test-secret"), m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.Name == "testvolume-data" })
assert.NotNil(t, v)
@@ -478,7 +480,7 @@ func TestConfigureVolumesAndMountsBinaryAndTextResources(t *testing.T) {
m := findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == v.Name })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/resources/res1.bin", m.MountPath)
+ assert.Equal(t, "/etc/camel/data/resources/res1.bin", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == "my-cm2" })
assert.NotNil(t, v)
@@ -489,7 +491,7 @@ func TestConfigureVolumesAndMountsBinaryAndTextResources(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == v.Name })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/resources/res2.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/data/resources/res2.txt", m.MountPath)
}
func TestOnlySomeTraitsInfluenceBuild(t *testing.T) {
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 6e7426c..2786f25 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -48,13 +48,17 @@ import (
const True = "true"
var (
- basePath = "/etc/camel"
- confDPath = path.Join(basePath, "conf.d")
- sourcesMountPath = path.Join(basePath, "sources")
- resourcesMountPath = path.Join(basePath, "resources")
- configMapsMountPath = path.Join(confDPath, "_configmaps")
- secretsMountPath = path.Join(confDPath, "_secrets")
- serviceBindingsMountPath = path.Join(confDPath, "_servicebindings")
+ basePath = "/etc/camel"
+ confDPath = path.Join(basePath, "conf.d")
+ sourcesMountPath = path.Join(basePath, "sources")
+ dataDefaultMountPath = path.Join(basePath, "data")
+ dataResourcesMountPath = path.Join(dataDefaultMountPath, "resources")
+ dataConfigmapsMountPath = path.Join(dataDefaultMountPath, "configmaps")
+ dataSecretsMountPath = path.Join(dataDefaultMountPath, "secrets")
+ configResourcesMountPath = path.Join(confDPath, "_resources")
+ configConfigmapsMountPath = path.Join(confDPath, "_configmaps")
+ configSecretsMountPath = path.Join(confDPath, "_secrets")
+ serviceBindingsMountPath = path.Join(confDPath, "_servicebindings")
)
// Identifiable represent an identifiable type
@@ -463,7 +467,7 @@ func (e *Environment) computeConfigMaps() []ctrl.Object {
}
for i, r := range e.Integration.Spec.Resources {
- if r.Type != v1.ResourceTypeData {
+ if r.Type == v1.ResourceTypeOpenAPI {
continue
}
if r.ContentRef != "" {
@@ -601,7 +605,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
}
for i, r := range e.Integration.Resources() {
- if r.Type != v1.ResourceTypeData {
+ if r.Type == v1.ResourceTypeOpenAPI {
continue
}
@@ -609,7 +613,8 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
refName := fmt.Sprintf("i-resource-%03d", i)
resName := strings.TrimPrefix(r.Name, "/")
cmKey := "content"
- resPath := path.Join(resourcesMountPath, resName)
+ resourceMountPoint := getResourceMountPoint(r.Type)
+ resPath := path.Join(resourceMountPoint, resName)
if r.ContentRef != "" {
cmName = r.ContentRef
@@ -690,15 +695,15 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
//
// Volumes :: Additional ConfigMaps
//
- for _, cmName := range e.collectConfigurationValues("configmap") {
- refName := kubernetes.SanitizeLabel(cmName)
+ for _, configmaps := range e.collectConfigurations("configmap") {
+ refName := kubernetes.SanitizeLabel(configmaps["value"])
*vols = append(*vols, corev1.Volume{
Name: refName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
- Name: cmName,
+ Name: configmaps["value"],
},
},
},
@@ -706,7 +711,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
*mnts = append(*mnts, corev1.VolumeMount{
Name: refName,
- MountPath: path.Join(configMapsMountPath, strings.ToLower(cmName)),
+ MountPath: path.Join(getConfigmapMountPoint(configmaps["resourceType"]), strings.ToLower(configmaps["value"])),
ReadOnly: true,
})
}
@@ -732,21 +737,21 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
MountPath: path.Join(serviceBindingsMountPath, strings.ToLower(sb)),
})
}
- for _, secretName := range e.collectConfigurationValues("secret") {
- refName := kubernetes.SanitizeLabel(secretName)
+ for _, secret := range e.collectConfigurations("secret") {
+ refName := kubernetes.SanitizeLabel(secret["value"])
*vols = append(*vols, corev1.Volume{
Name: refName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
- SecretName: secretName,
+ SecretName: secret["value"],
},
},
})
*mnts = append(*mnts, corev1.VolumeMount{
Name: refName,
- MountPath: path.Join(secretsMountPath, strings.ToLower(secretName)),
+ MountPath: path.Join(getSecretMountPoint(secret["resourceType"]), strings.ToLower(secret["value"])),
ReadOnly: true,
})
}
@@ -781,6 +786,33 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
}
}
+func getResourceMountPoint(resourceType v1.ResourceType) string {
+ switch resourceType {
+ case v1.ResourceTypeData:
+ return dataResourcesMountPath
+ }
+ // Default, config type
+ return configResourcesMountPath
+}
+
+func getConfigmapMountPoint(resourceType string) string {
+ switch resourceType {
+ case "data":
+ return dataConfigmapsMountPath
+ }
+ // Default, config type
+ return configConfigmapsMountPath
+}
+
+func getSecretMountPoint(resourceType string) string {
+ switch resourceType {
+ case "data":
+ return dataSecretsMountPath
+ }
+ // Default, config type
+ return configSecretsMountPath
+}
+
func (e *Environment) collectConfigurationValues(configurationType string) []string {
return collectConfigurationValues(configurationType, e.Platform, e.IntegrationKit, e.Integration)
}
@@ -793,6 +825,10 @@ func (e *Environment) collectConfigurationPairs(configurationType string) []vari
return collectConfigurationPairs(configurationType, e.Platform, e.IntegrationKit, e.Integration)
}
+func (e *Environment) collectConfigurations(configurationType string) []map[string]string {
+ return collectConfigurations(configurationType, e.Platform, e.IntegrationKit, e.Integration)
+}
+
func (e *Environment) getIntegrationContainer() *corev1.Container {
containerName := defaultContainerName
dt := e.Catalog.GetTrait(containerTraitID)
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 366d594..4a2dc5d 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -77,6 +77,34 @@ func collectConfigurationValues(configurationType string, configurable ...v1.Con
return s
}
+func collectConfigurations(configurationType string, configurable ...v1.Configurable) []map[string]string {
+ var result []map[string]string
+
+ for _, c := range configurable {
+ c := c
+
+ if c == nil || reflect.ValueOf(c).IsNil() {
+ continue
+ }
+
+ entries := c.Configurations()
+ if entries == nil {
+ continue
+ }
+
+ for _, entry := range entries {
+ if entry.Type == configurationType {
+ var item = make(map[string]string)
+ item["value"] = entry.Value
+ item["resourceType"] = entry.ResourceType
+ result = append(result, item)
+ }
+ }
+ }
+
+ return result
+}
+
func collectConfigurationPairs(configurationType string, configurable ...v1.Configurable) []variable {
result := make([]variable, 0)
[camel-k] 14/20: fix(e2e): test name typo
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit fdf7fe4fec55db566f646cb145b548b961a52a13
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jun 3 16:43:56 2021 +0200
fix(e2e): test name typo
---
...source-configmap-route copy.groovy => resource-configmap-route.groovy} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
diff --git a/e2e/common/config/files/resource-configmap-route copy.groovy b/e2e/common/config/files/resource-configmap-route.groovy
similarity index 100%
rename from e2e/common/config/files/resource-configmap-route copy.groovy
rename to e2e/common/config/files/resource-configmap-route.groovy
[camel-k] 12/20: chore(e2e): run option with destination path
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ad5831aecdedd0f6d9a5878d67846ef9af361477
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jun 3 11:28:47 2021 +0200
chore(e2e): run option with destination path
Ref #2003
---
docs/modules/ROOT/pages/cli/modeline.adoc | 2 +-
e2e/common/config/config_test.go | 19 +++++++++++++++++++
...roovy => resource-configmap-location-route.groovy} | 2 +-
...te.groovy => resource-configmap-route copy.groovy} | 0
...ute.groovy => resource-file-location-route.groovy} | 2 +-
5 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc
index 01437c2..424a00b 100644
--- a/docs/modules/ROOT/pages/cli/modeline.adoc
+++ b/docs/modules/ROOT/pages/cli/modeline.adoc
@@ -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 runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name)_
+|Add a runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[@path])_
|trait
|Configure a trait, e.g. `trait=service.enabled=false`
diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index e2d16d4..9282fad 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -82,6 +82,16 @@ func TestRunConfigExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
+ t.Run("Resource configmap with destination", func(t *testing.T) {
+ // We can reuse the configmap created previously
+
+ Expect(Kamel("run", "-n", ns, "./files/resource-configmap-location-route.groovy", "--resource", "configmap:my-cm@/tmp/app").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-configmap-location-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-configmap-location-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-configmap-location-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"]))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
+
// Secret
// Store a secret on the cluster
@@ -125,6 +135,14 @@ func TestRunConfigExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
+ t.Run("Plain text resource file with destination path", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-location-route.groovy", "--resource", "file:./files/resources-data.txt@/tmp/file.txt").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-location-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-location-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-location-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
+
t.Run("Binary (zip) resource file", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/resource-file-binary-route.groovy", "--resource", "file:./files/resources-data.zip", "-d", "camel-zipfile").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "resource-file-binary-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
@@ -176,5 +194,6 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
+
})
}
diff --git a/e2e/common/config/files/resource-configmap-route.groovy b/e2e/common/config/files/resource-configmap-location-route.groovy
similarity index 89%
copy from e2e/common/config/files/resource-configmap-route.groovy
copy to e2e/common/config/files/resource-configmap-location-route.groovy
index 3df9e05..08c2f9c 100644
--- a/e2e/common/config/files/resource-configmap-route.groovy
+++ b/e2e/common/config/files/resource-configmap-location-route.groovy
@@ -16,5 +16,5 @@
* limitations under the License.
*/
-from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
+from('file:/tmp/app/?fileName=my-configmap-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resource-configmap-route.groovy b/e2e/common/config/files/resource-configmap-route copy.groovy
similarity index 100%
copy from e2e/common/config/files/resource-configmap-route.groovy
copy to e2e/common/config/files/resource-configmap-route copy.groovy
diff --git a/e2e/common/config/files/resource-configmap-route.groovy b/e2e/common/config/files/resource-file-location-route.groovy
similarity index 89%
rename from e2e/common/config/files/resource-configmap-route.groovy
rename to e2e/common/config/files/resource-file-location-route.groovy
index 3df9e05..076a2a9 100644
--- a/e2e/common/config/files/resource-configmap-route.groovy
+++ b/e2e/common/config/files/resource-file-location-route.groovy
@@ -16,5 +16,5 @@
* limitations under the License.
*/
-from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
+from('file:/tmp/?fileName=file.txt&noop=true&idempotent=false')
.log('resource file content is: ${body}')
[camel-k] 15/20: feat(cmd/run): configmap/secret key filtering
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit e938c50fc43db9ad9b3cb85f8d944dc354aa3511
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jun 7 12:37:25 2021 +0200
feat(cmd/run): configmap/secret key filtering
* Added support to specify a single key from a configmap/secret in --resource or --config flag
* Refactoring the RunConfigOption struct to include the new feature and hide the complexity to usage
Ref #2003
---
pkg/apis/camel/v1/common_types.go | 1 +
pkg/apis/camel/v1/integration_types_support.go | 4 +-
pkg/cmd/run.go | 4 +-
pkg/cmd/run_help.go | 76 +++++++++++++++-----
pkg/cmd/run_help_test.go | 99 +++++++++++++++++++++++---
pkg/trait/trait_types.go | 33 +++++++--
pkg/trait/util.go | 1 +
7 files changed, 184 insertions(+), 34 deletions(-)
diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go
index 42a23fa..d547159 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -30,6 +30,7 @@ type ConfigurationSpec struct {
Value string `json:"value"`
ResourceType string `json:"resourceType,omitempty"`
ResourceMountPoint string `json:"resourceMountPoint,omitempty"`
+ ResourceKey string `json:"resourceKey,omitempty"`
}
// Artifact --
diff --git a/pkg/apis/camel/v1/integration_types_support.go b/pkg/apis/camel/v1/integration_types_support.go
index 8c2d3e5..31f09d5 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -110,12 +110,14 @@ func (in *IntegrationSpec) AddConfiguration(confType string, confValue string) {
}
// AddConfigurationAsResource will set a configuration specified with a resource type
-func (in *IntegrationSpec) AddConfigurationAsResource(confType string, confValue string, resourceType string, resourceMountPoint string) {
+func (in *IntegrationSpec) AddConfigurationAsResource(
+ confType string, confValue string, resourceType string, resourceMountPoint string, resourceKey string) {
in.Configuration = append(in.Configuration, ConfigurationSpec{
Type: confType,
Value: confValue,
ResourceType: resourceType,
ResourceMountPoint: resourceMountPoint,
+ ResourceKey: resourceKey,
})
}
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index fe6b209..e6d42b4 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -81,8 +81,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 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[@path])")
+ cmd.Flags().StringArray("config", nil, "Add a runtime configuration from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key])")
+ cmd.Flags().StringArray("resource", nil, "Add a runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key][@path])")
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")
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index 9734dbd..d117bf8 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -33,8 +33,9 @@ var invalidPaths = []string{"/etc/camel", "/deployments/dependencies"}
// RunConfigOption represents a config option
type RunConfigOption struct {
- ConfigType configOptionType
- Value string
+ configType configOptionType
+ resourceName string
+ resourceKey string
destinationPath string
}
@@ -43,11 +44,28 @@ func (runConfigOption *RunConfigOption) DestinationPath() string {
return runConfigOption.destinationPath
}
-// Validate checks if the DestinationPath exists and in case if it's a valid path
+// Type is the type, converted as string
+func (runConfigOption *RunConfigOption) Type() string {
+ return string(runConfigOption.configType)
+}
+
+// Name is the name of the resource
+func (runConfigOption *RunConfigOption) Name() string {
+ return runConfigOption.resourceName
+}
+
+// Key is the key specified for the resource
+func (runConfigOption *RunConfigOption) Key() string {
+ return runConfigOption.resourceKey
+}
+
+// Validate checks if the DestinationPath is correctly configured
func (runConfigOption *RunConfigOption) Validate() error {
if runConfigOption.destinationPath == "" {
return nil
}
+
+ // Check for invalid path
for _, invalidPath := range invalidPaths {
if runConfigOption.destinationPath == invalidPath || strings.HasPrefix(runConfigOption.destinationPath, invalidPath+"/") {
return fmt.Errorf("you cannot mount a file under %s path", invalidPath)
@@ -68,17 +86,28 @@ const (
)
var validConfigRegexp = regexp.MustCompile(`^(configmap|secret|file)\:([\w\.\-\_\:\/@]+)$`)
+var validResourceRegexp = regexp.MustCompile(`^([\w\.\-\_\:]+)(\/([\w\.\-\_\:]+))?(\@([\w\.\-\_\:\/]+))?$`)
func newRunConfigOption(configType configOptionType, value string) *RunConfigOption {
- optionValue, maybeDestinationPath := parseFileValue(value)
+ rn, mk, mp := parseResourceValue(configType, value)
return &RunConfigOption{
- ConfigType: configType,
- Value: optionValue,
- destinationPath: maybeDestinationPath,
+ configType: configType,
+ resourceName: rn,
+ resourceKey: mk,
+ destinationPath: mp,
}
}
-func parseFileValue(value string) (string, string) {
+func parseResourceValue(configType configOptionType, value string) (resource string, maybeKey string, maybeDestinationPath string) {
+ if configType == ConfigOptionTypeFile {
+ resource, maybeDestinationPath = parseFileValue(value)
+ return resource, "", maybeDestinationPath
+ } else {
+ return parseCMOrSecretValue(value)
+ }
+}
+
+func parseFileValue(value string) (localPath string, maybeDestinationPath string) {
split := strings.SplitN(value, "@", 2)
if len(split) == 2 {
return split[0], split[1]
@@ -86,6 +115,15 @@ func parseFileValue(value string) (string, string) {
return value, ""
}
+func parseCMOrSecretValue(value string) (resource string, maybeKey string, maybeDestinationPath string) {
+ if !validResourceRegexp.MatchString(value) {
+ return value, "", ""
+ }
+ // Must have 3 values
+ groups := validResourceRegexp.FindStringSubmatch(value)
+ return groups[1], groups[3], groups[5]
+}
+
// ParseResourceOption will parse and return a runConfigOption
func ParseResourceOption(item string) (*RunConfigOption, error) {
// Deprecated: ensure backward compatibility with `--resource filename` format until version 1.5.x
@@ -133,26 +171,26 @@ func parseOption(item string) (*RunConfigOption, error) {
func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
c client.Client, namespace string, enableCompression bool, resourceType v1.ResourceType) error {
- switch config.ConfigType {
+ switch config.configType {
case ConfigOptionTypeConfigmap:
- cm := kubernetes.LookupConfigmap(context.Background(), c, namespace, config.Value)
+ cm := kubernetes.LookupConfigmap(context.Background(), c, namespace, config.Name())
if cm == nil {
fmt.Printf("Warn: %s Configmap not found in %s namespace, make sure to provide it before the Integration can run\n",
- config.Value, namespace)
+ config.Name(), namespace)
} else if resourceType != v1.ResourceTypeData && cm.BinaryData != nil {
return fmt.Errorf("you cannot provide a binary config, use a text file instead")
}
- integrationSpec.AddConfigurationAsResource(string(config.ConfigType), config.Value, string(resourceType), config.DestinationPath())
+ integrationSpec.AddConfigurationAsResource(config.Type(), config.Name(), string(resourceType), config.DestinationPath(), config.Key())
case ConfigOptionTypeSecret:
- secret := kubernetes.LookupSecret(context.Background(), c, namespace, config.Value)
+ secret := kubernetes.LookupSecret(context.Background(), c, namespace, config.Name())
if secret == nil {
fmt.Printf("Warn: %s Secret not found in %s namespace, make sure to provide it before the Integration can run\n",
- config.Value, namespace)
+ config.Name(), namespace)
}
- integrationSpec.AddConfigurationAsResource(string(config.ConfigType), config.Value, string(resourceType), config.DestinationPath())
+ integrationSpec.AddConfigurationAsResource(string(config.configType), config.Name(), string(resourceType), config.DestinationPath(), config.Key())
case ConfigOptionTypeFile:
// Don't allow a file size longer than 1 MiB
- fileSize, err := fileSize(config.Value)
+ fileSize, err := fileSize(config.Name())
printSize := fmt.Sprintf("%.2f", float64(fileSize)/Megabyte)
if err != nil {
return err
@@ -160,21 +198,21 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
return fmt.Errorf("you cannot provide a file larger than 1 MB (it was %s MB), check configmap option or --volume instead", printSize)
}
// Don't allow a binary non compressed resource
- rawData, contentType, err := loadRawContent(config.Value)
+ rawData, contentType, err := loadRawContent(config.Name())
if err != nil {
return err
}
if resourceType != v1.ResourceTypeData && !enableCompression && isBinary(contentType) {
return fmt.Errorf("you cannot provide a binary config, use a text file or check --resource flag instead")
}
- resourceSpec, err := binaryOrTextResource(path.Base(config.Value), rawData, contentType, enableCompression, resourceType, config.DestinationPath())
+ resourceSpec, err := binaryOrTextResource(path.Base(config.Name()), rawData, contentType, enableCompression, resourceType, config.DestinationPath())
if err != nil {
return err
}
integrationSpec.AddResources(resourceSpec)
default:
// Should never reach this
- return fmt.Errorf("invalid option type %s", config.ConfigType)
+ return fmt.Errorf("invalid option type %s", config.configType)
}
return nil
diff --git a/pkg/cmd/run_help_test.go b/pkg/cmd/run_help_test.go
index ebbff23..75e02f3 100644
--- a/pkg/cmd/run_help_test.go
+++ b/pkg/cmd/run_help_test.go
@@ -32,25 +32,108 @@ func TestParseConfigOption(t *testing.T) {
configmap, err := ParseConfigOption(validConfigMap)
assert.Nil(t, err)
- assert.Equal(t, ConfigOptionTypeConfigmap, configmap.ConfigType)
- assert.Equal(t, "my-config_map", configmap.Value)
+ assert.Equal(t, ConfigOptionTypeConfigmap, configmap.configType)
+ assert.Equal(t, "my-config_map", configmap.Name())
secret, err := ParseConfigOption(validSecret)
assert.Nil(t, err)
- assert.Equal(t, ConfigOptionTypeSecret, secret.ConfigType)
- assert.Equal(t, "my-secret", secret.Value)
+ assert.Equal(t, ConfigOptionTypeSecret, secret.configType)
+ assert.Equal(t, "my-secret", secret.Name())
file, err := ParseConfigOption(validFile)
assert.Nil(t, err)
- assert.Equal(t, ConfigOptionTypeFile, file.ConfigType)
- assert.Equal(t, "/tmp/my-file.txt", file.Value)
+ assert.Equal(t, ConfigOptionTypeFile, file.configType)
+ assert.Equal(t, "/tmp/my-file.txt", file.Name())
_, err = ParseConfigOption(notValid)
assert.NotNil(t, err)
location, err := ParseConfigOption(validLocation)
assert.Nil(t, err)
- assert.Equal(t, ConfigOptionTypeFile, location.ConfigType)
- assert.Equal(t, "my-file.txt", location.Value)
+ assert.Equal(t, ConfigOptionTypeFile, location.configType)
+ assert.Equal(t, "my-file.txt", location.Name())
assert.Equal(t, "/tmp/another-name.xml", location.DestinationPath())
}
+func TestParseConfigOptionAllParams(t *testing.T) {
+ cm1 := "configmap:my-config_map/key@/tmp/my"
+ cm2 := "configmap:my-config_map/key"
+ cm3 := "configmap:my-config_map@/tmp/my"
+ cm4 := "configmap:my-config_map"
+ sec1 := "secret:sec/key@/tmp/sec"
+ sec2 := "secret:sec/key"
+ sec3 := "secret:sec@/tmp/sec"
+ sec4 := "secret:sec"
+ file1 := "file:/path/to/my-file.txt@/tmp/file.txt"
+ file2 := "file:/path/to/my-file.txt"
+
+ parsedCm1, err := ParseConfigOption(cm1)
+ assert.Nil(t, err)
+ assert.Equal(t, "configmap", parsedCm1.Type())
+ assert.Equal(t, "my-config_map", parsedCm1.Name())
+ assert.Equal(t, "key", parsedCm1.Key())
+ assert.Equal(t, "/tmp/my", parsedCm1.DestinationPath())
+
+ parsedCm2, err := ParseConfigOption(cm2)
+ assert.Nil(t, err)
+ assert.Equal(t, "configmap", parsedCm2.Type())
+ assert.Equal(t, "my-config_map", parsedCm2.Name())
+ assert.Equal(t, "key", parsedCm2.Key())
+ assert.Equal(t, "", parsedCm2.DestinationPath())
+
+ parsedCm3, err := ParseConfigOption(cm3)
+ assert.Nil(t, err)
+ assert.Equal(t, "configmap", parsedCm3.Type())
+ assert.Equal(t, "my-config_map", parsedCm3.Name())
+ assert.Equal(t, "", parsedCm3.Key())
+ assert.Equal(t, "/tmp/my", parsedCm3.DestinationPath())
+
+ parsedCm4, err := ParseConfigOption(cm4)
+ assert.Nil(t, err)
+ assert.Equal(t, "configmap", parsedCm4.Type())
+ assert.Equal(t, "my-config_map", parsedCm4.Name())
+ assert.Equal(t, "", parsedCm4.Key())
+ assert.Equal(t, "", parsedCm4.DestinationPath())
+
+ parsedSec1, err := ParseConfigOption(sec1)
+ assert.Nil(t, err)
+ assert.Equal(t, "secret", parsedSec1.Type())
+ assert.Equal(t, "sec", parsedSec1.Name())
+ assert.Equal(t, "key", parsedSec1.Key())
+ assert.Equal(t, "/tmp/sec", parsedSec1.DestinationPath())
+
+ parsedSec2, err := ParseConfigOption(sec2)
+ assert.Nil(t, err)
+ assert.Equal(t, "secret", parsedSec2.Type())
+ assert.Equal(t, "sec", parsedSec2.Name())
+ assert.Equal(t, "key", parsedSec2.Key())
+ assert.Equal(t, "", parsedSec2.DestinationPath())
+
+ parsedSec3, err := ParseConfigOption(sec3)
+ assert.Nil(t, err)
+ assert.Equal(t, "secret", parsedSec3.Type())
+ assert.Equal(t, "sec", parsedSec3.Name())
+ assert.Equal(t, "", parsedSec3.Key())
+ assert.Equal(t, "/tmp/sec", parsedSec3.DestinationPath())
+
+ parsedSec4, err := ParseConfigOption(sec4)
+ assert.Nil(t, err)
+ assert.Equal(t, "secret", parsedSec4.Type())
+ assert.Equal(t, "sec", parsedSec4.Name())
+ assert.Equal(t, "", parsedSec4.Key())
+ assert.Equal(t, "", parsedSec4.DestinationPath())
+
+ parsedFile1, err := ParseConfigOption(file1)
+ assert.Nil(t, err)
+ assert.Equal(t, "file", parsedFile1.Type())
+ assert.Equal(t, "/path/to/my-file.txt", parsedFile1.Name())
+ assert.Equal(t, "", parsedFile1.Key())
+ assert.Equal(t, "/tmp/file.txt", parsedFile1.DestinationPath())
+
+ parsedFile2, err := ParseConfigOption(file2)
+ assert.Nil(t, err)
+ assert.Equal(t, "file", parsedFile2.Type())
+ assert.Equal(t, "/path/to/my-file.txt", parsedFile2.Name())
+ assert.Equal(t, "", parsedFile2.Key())
+ assert.Equal(t, "", parsedFile2.DestinationPath())
+}
+
func TestFilterFileLocation(t *testing.T) {
optionFileLocations := []string{
"file:/path/to/valid/file",
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 9049fe0..6b3a23d 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -697,7 +697,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
for _, configmaps := range e.collectConfigurations("configmap") {
refName := kubernetes.SanitizeLabel(configmaps["value"])
- *vols = append(*vols, corev1.Volume{
+ configmapVolume := corev1.Volume{
Name: refName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
@@ -706,7 +706,19 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
},
},
},
- })
+ }
+
+ // Filter the items selected, if specified
+ if configmaps["resourceKey"] != "" {
+ configmapVolume.VolumeSource.ConfigMap.Items = []corev1.KeyToPath{
+ {
+ Key: configmaps["resourceKey"],
+ Path: configmaps["resourceKey"],
+ },
+ }
+ }
+
+ *vols = append(*vols, configmapVolume)
*mnts = append(*mnts, corev1.VolumeMount{
Name: refName,
@@ -736,17 +748,30 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
MountPath: path.Join(serviceBindingsMountPath, strings.ToLower(sb)),
})
}
+
for _, secret := range e.collectConfigurations("secret") {
refName := kubernetes.SanitizeLabel(secret["value"])
- *vols = append(*vols, corev1.Volume{
+ secretVolume := corev1.Volume{
Name: refName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secret["value"],
},
},
- })
+ }
+
+ // Filter the items selected, if specified
+ if secret["resourceKey"] != "" {
+ secretVolume.VolumeSource.Secret.Items = []corev1.KeyToPath{
+ {
+ Key: secret["resourceKey"],
+ Path: secret["resourceKey"],
+ },
+ }
+ }
+
+ *vols = append(*vols, secretVolume)
*mnts = append(*mnts, corev1.VolumeMount{
Name: refName,
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 0f5d936..af88cc4 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -98,6 +98,7 @@ func collectConfigurations(configurationType string, configurable ...v1.Configur
item["value"] = entry.Value
item["resourceType"] = entry.ResourceType
item["resourceMountPoint"] = entry.ResourceMountPoint
+ item["resourceKey"] = entry.ResourceKey
result = append(result, item)
}
}
[camel-k] 10/20: feat(cmd/run): file size limitation
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 4697722476e3c2366578dc0b7eaae8ea4cc24487
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jun 3 10:01:23 2021 +0200
feat(cmd/run): file size limitation
Won't accept any resource/config file larger than 1MB, due to the limitation on K8S CustomResources
Ref #2003
---
pkg/cmd/run_help.go | 8 ++++++++
pkg/cmd/util_content.go | 14 ++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index 12264c2..c7f80e7 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -132,6 +132,14 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
}
integrationSpec.AddConfigurationAsResource(string(config.ConfigType), config.Value, string(resourceType), config.DestinationPath())
case ConfigOptionTypeFile:
+ // Don't allow a file size longer than 1 MiB
+ fileSize, err := fileSize(config.Value)
+ printSize := fmt.Sprintf("%.2f", float64(fileSize)/Megabyte)
+ if err != nil {
+ return err
+ } else if fileSize > Megabyte {
+ return fmt.Errorf("you cannot provide a file larger than 1 MB (it was %s MB), check configmap option or --volume instead", printSize)
+ }
// Don't allow a binary non compressed resource
rawData, contentType, err := loadRawContent(config.Value)
if err != nil {
diff --git a/pkg/cmd/util_content.go b/pkg/cmd/util_content.go
index 62cda96..5d35127 100644
--- a/pkg/cmd/util_content.go
+++ b/pkg/cmd/util_content.go
@@ -22,10 +22,24 @@ import (
"io/ioutil"
"net/http"
"net/url"
+ "os"
"regexp"
"strings"
)
+const (
+ Megabyte = 1 << 20
+ Kilobyte = 1 << 10
+)
+
+func fileSize(source string) (int64, error) {
+ fi, err := os.Stat(source)
+ if err != nil {
+ return -1, err
+ }
+ return fi.Size(), nil
+}
+
func loadRawContent(source string) ([]byte, string, error) {
var content []byte
var err error
[camel-k] 06/20: feat(cmd/run): modeline resource support
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 165fa3aa86075bcb59d44878dbe66d1ca25c8b91
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 16:23:26 2021 +0200
feat(cmd/run): modeline resource support
Ref #2003
---
docs/modules/ROOT/pages/cli/modeline.adoc | 4 +-
....groovy => modeline-config-secret-route.groovy} | 2 +-
....groovy => modeline-resource-file-route.groovy} | 13 ++--
pkg/cmd/modeline.go | 2 +-
pkg/cmd/modeline_test.go | 73 ++++++++++++++++++++++
pkg/cmd/run.go | 4 +-
6 files changed, 83 insertions(+), 15 deletions(-)
diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc
index f4dd436..01437c2 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%
copy from examples/modeline/modeline-secret-route.groovy
copy to examples/modeline/modeline-config-secret-route.groovy
index 0107b28..e6b9dab 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-secret-route.groovy b/examples/modeline/modeline-resource-file-route.groovy
similarity index 73%
rename from examples/modeline/modeline-secret-route.groovy
rename to examples/modeline/modeline-resource-file-route.groovy
index 0107b28..e02777a 100644
--- a/examples/modeline/modeline-secret-route.groovy
+++ b/examples/modeline/modeline-resource-file-route.groovy
@@ -18,15 +18,10 @@
//
// 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-resource-file-route.groovy --dev
//
-// camel-k: config=secret:my-sec
+// camel-k: resource=file:resources-data.txt
-from('timer:secret')
- .routeId('secret')
- .setBody()
- .simple("resource:classpath:my-secret-key")
- .log('secret content is: ${body}')
+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 0f540f8..cae66f6 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 6592939..8b82d49 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 9d8a0fe..ad0485d 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -81,8 +81,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")
[camel-k] 11/20: refactor(cmd/run): synch all option files
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ba4a25fc7ffdab51c14b99ffc10e7539ce84e609
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jun 3 11:07:57 2021 +0200
refactor(cmd/run): synch all option files
Ref #2003
---
pkg/cmd/run.go | 5 ++++-
pkg/cmd/run_help.go | 11 +++++++++++
pkg/cmd/run_help_test.go | 17 +++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 6e4c373..fe6b209 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -407,7 +407,10 @@ func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sou
// Let's watch all relevant files when in dev mode
var files []string
files = append(files, sources...)
- files = append(files, o.Resources...)
+ files = append(files, filterFileLocation(o.Resources)...)
+ files = append(files, filterFileLocation(o.Configs)...)
+ files = append(files, filterFileLocation(o.Properties)...)
+ files = append(files, filterFileLocation(o.BuildProperties)...)
files = append(files, o.PropertyFiles...)
files = append(files, o.OpenAPIs...)
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index c7f80e7..a1ab41e 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -200,3 +200,14 @@ func binaryOrTextResource(fileName string, data []byte, contentType string, base
}
return resourceSpec, nil
}
+
+func filterFileLocation(maybeFileLocations []string) []string {
+ filteredOptions := make([]string, 0)
+ for _, option := range maybeFileLocations {
+ if strings.HasPrefix(option, "file:") {
+ localPath, _ := parseFileValue(strings.Replace(option, "file:", "", 1))
+ filteredOptions = append(filteredOptions, localPath)
+ }
+ }
+ return filteredOptions
+}
diff --git a/pkg/cmd/run_help_test.go b/pkg/cmd/run_help_test.go
index 5eab301..abae91d 100644
--- a/pkg/cmd/run_help_test.go
+++ b/pkg/cmd/run_help_test.go
@@ -50,3 +50,20 @@ func TestParseConfigOption(t *testing.T) {
assert.Equal(t, "my-file.txt", location.Value)
assert.Equal(t, "/tmp/another-name.xml", location.DestinationPath())
}
+
+func TestFilterFileLocation(t *testing.T) {
+ optionFileLocations := []string{
+ "file:/path/to/valid/file",
+ "file:app.properties",
+ "configmap:my-configmap",
+ "secret:my-secret",
+ "file:/validfile@/tmp/destination",
+ }
+
+ filteredOptions := filterFileLocation(optionFileLocations)
+
+ assert.Equal(t, 3, len(filteredOptions))
+ assert.Equal(t, "/path/to/valid/file", filteredOptions[0])
+ assert.Equal(t, "app.properties", filteredOptions[1])
+ assert.Equal(t, "/validfile", filteredOptions[2])
+}
[camel-k] 04/20: refactor(e2e): resource option integration test
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 44ba5644a1a7ad73ab196505413f520df76ea3de
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 10:43:36 2021 +0200
refactor(e2e): resource option integration test
Ref #2003
---
e2e/common/config/config_test.go | 84 +++++++++++++---------
.../config/files/build-property-file-route.groovy | 8 ---
.../config/files/build-property-route.groovy | 8 ---
...-route.groovy => config-configmap-route.groovy} | 7 --
e2e/common/config/files/config-file-route.groovy | 5 --
...ret-route.groovy => config-secret-route.groovy} | 7 --
e2e/common/config/files/property-file-route.groovy | 6 --
e2e/common/config/files/property-route.groovy | 6 --
...oute.groovy => resource-configmap-route.groovy} | 7 +-
...y => resource-file-base64-encoded-route.groovy} | 5 --
...te.groovy => resource-file-binary-route.groovy} | 7 +-
...ces-route.groovy => resource-file-route.groovy} | 7 +-
...s-route.groovy => resource-secret-route.groovy} | 7 +-
.../user-config/resource-file-binary-route.groovy | 2 +-
pkg/trait/jvm.go | 2 +
pkg/trait/jvm_test.go | 9 +--
16 files changed, 63 insertions(+), 114 deletions(-)
diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index 2cb79ab..e2d16d4 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -59,35 +59,53 @@ func TestRunConfigExamples(t *testing.T) {
// Configmap
- t.Run("Textplain configmap", func(t *testing.T) {
- // Store a configmap on the cluster
- var cmData = make(map[string]string)
- cmData["my-configmap-key"] = "my-configmap-content"
- NewPlainTextConfigmap(ns, "my-cm", cmData)
-
- Expect(Kamel("run", "-n", ns, "./files/configmap-route.groovy", "--config", "configmap:my-cm").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "configmap-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"]))
+ // Store a configmap on the cluster
+ var cmData = make(map[string]string)
+ cmData["my-configmap-key"] = "my-configmap-content"
+ NewPlainTextConfigmap(ns, "my-cm", cmData)
+
+ t.Run("Config configmap", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/config-configmap-route.groovy", "--config", "configmap:my-cm").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "config-configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "config-configmap-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"]))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
+
+ t.Run("Resource configmap", func(t *testing.T) {
+ // We can reuse the configmap created previously
+
+ Expect(Kamel("run", "-n", ns, "./files/resource-configmap-route.groovy", "--resource", "configmap:my-cm").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-configmap-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"]))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
// Secret
- t.Run("Textplain secret", func(t *testing.T) {
- // Store a secret on the cluster
- var secData = make(map[string]string)
- secData["my-secret-key"] = "very top secret"
- NewPlainTextSecret(ns, "my-sec", secData)
+ // Store a secret on the cluster
+ var secData = make(map[string]string)
+ secData["my-secret-key"] = "very top secret"
+ NewPlainTextSecret(ns, "my-sec", secData)
+
+ t.Run("Config secret", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/config-secret-route.groovy", "--config", "secret:my-sec").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "config-secret-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "config-secret-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "config-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"]))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
- Expect(Kamel("run", "-n", ns, "./files/secret-route.groovy", "--config", "secret:my-sec").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "secret-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "secret-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"]))
+ t.Run("Resource secret", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/resource-secret-route.groovy", "--resource", "secret:my-sec").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-secret-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-secret-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"]))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
- // File Configuration
+ // Config File
t.Run("Plain text configuration file", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/config-file-route.groovy", "--config", "file:./files/resources-data.txt").Execute()).To(Succeed())
@@ -97,21 +115,21 @@ func TestRunConfigExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
- // Resources
+ // Resource File
t.Run("Plain text resource file", func(t *testing.T) {
- Expect(Kamel("run", "-n", ns, "./files/resources-route.groovy", "--resource", "./files/resources-data.txt").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "resources-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "resources-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "resources-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-route.groovy", "--resource", "file:./files/resources-data.txt").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
t.Run("Binary (zip) resource file", func(t *testing.T) {
- Expect(Kamel("run", "-n", ns, "./files/resources-binary-route.groovy", "--resource", "./files/resources-data.zip", "-d", "camel-zipfile").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "resources-binary-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "resources-binary-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "resources-binary-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-binary-route.groovy", "--resource", "file:./files/resources-data.zip", "-d", "camel-zipfile").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-binary-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-binary-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-binary-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
@@ -122,10 +140,10 @@ func TestRunConfigExamples(t *testing.T) {
expectedBytes, err := gzip.CompressBase64([]byte(source))
assert.Nil(t, err)
- Expect(Kamel("run", "-n", ns, "./files/resources-base64-encoded-route.groovy", "--resource", "./files/resources-data.txt", "--compression=true").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "resources-base64-encoded-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "resources-base64-encoded-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "resources-base64-encoded-route"), TestTimeoutShort).Should(ContainSubstring(string(expectedBytes)))
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-base64-encoded-route.groovy", "--resource", "file:./files/resources-data.txt", "--compression=true").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-base64-encoded-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-base64-encoded-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-base64-encoded-route"), TestTimeoutShort).Should(ContainSubstring(string(expectedBytes)))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
diff --git a/e2e/common/config/files/build-property-file-route.groovy b/e2e/common/config/files/build-property-file-route.groovy
index 8427b48..ecb065f 100644
--- a/e2e/common/config/files/build-property-file-route.groovy
+++ b/e2e/common/config/files/build-property-file-route.groovy
@@ -16,14 +16,6 @@
* limitations under the License.
*/
-//
-// Provide a build time configuration property file
-//
-// To run this integrations use:
-//
-// kamel run --build-property=file:quarkus.properties build-property-file-route.groovy --dev
-//
-
from('timer:build-property')
.routeId('build-property')
.log('The application name: {{quarkus.application.name}}')
diff --git a/e2e/common/config/files/build-property-route.groovy b/e2e/common/config/files/build-property-route.groovy
index c32e5e6..ecb065f 100644
--- a/e2e/common/config/files/build-property-route.groovy
+++ b/e2e/common/config/files/build-property-route.groovy
@@ -16,14 +16,6 @@
* limitations under the License.
*/
-//
-// Provide a build time configuration property (the application name)
-//
-// To run this integrations use:
-//
-// kamel run --build-property=quarkus.application.name=my-super-application build-property-route.groovy --dev
-//
-
from('timer:build-property')
.routeId('build-property')
.log('The application name: {{quarkus.application.name}}')
diff --git a/e2e/common/config/files/configmap-route.groovy b/e2e/common/config/files/config-configmap-route.groovy
similarity index 83%
rename from e2e/common/config/files/configmap-route.groovy
rename to e2e/common/config/files/config-configmap-route.groovy
index 948cb15..8c82912 100644
--- a/e2e/common/config/files/configmap-route.groovy
+++ b/e2e/common/config/files/config-configmap-route.groovy
@@ -16,13 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kubectl create configmap my-cm --from-literal=my-configmap-key="configmap content"
-// kamel run --config configmap:my-cm configmap-route.groovy --dev
-//
-
from('timer:configmap')
.routeId('configmap')
.setBody()
diff --git a/e2e/common/config/files/config-file-route.groovy b/e2e/common/config/files/config-file-route.groovy
index 53b347f..37b9473 100644
--- a/e2e/common/config/files/config-file-route.groovy
+++ b/e2e/common/config/files/config-file-route.groovy
@@ -16,11 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --config file:resources-data.txt resources-route.groovy --dev
-//
-
from('timer:resources')
.routeId('resources')
.setBody()
diff --git a/e2e/common/config/files/secret-route.groovy b/e2e/common/config/files/config-secret-route.groovy
similarity index 83%
rename from e2e/common/config/files/secret-route.groovy
rename to e2e/common/config/files/config-secret-route.groovy
index 7027b84..ac369aa 100644
--- a/e2e/common/config/files/secret-route.groovy
+++ b/e2e/common/config/files/config-secret-route.groovy
@@ -16,13 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kubectl create secret generic my-sec --from-literal=my-secret-key="very top secret"
-// kamel run --config secret:my-sec secret-route.groovy --dev
-//
-
from('timer:secret')
.routeId('secret')
.setBody()
diff --git a/e2e/common/config/files/property-file-route.groovy b/e2e/common/config/files/property-file-route.groovy
index 6ce6838..e9718df 100644
--- a/e2e/common/config/files/property-file-route.groovy
+++ b/e2e/common/config/files/property-file-route.groovy
@@ -16,12 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kamel run --property file:my.properties property-file-route.groovy --dev
-//
-
from('timer:property-file')
.routeId('property-file')
.log('property file content is: {{my.key.1}} {{my.key.2}}')
diff --git a/e2e/common/config/files/property-route.groovy b/e2e/common/config/files/property-route.groovy
index 705eca6..a609ea7 100644
--- a/e2e/common/config/files/property-route.groovy
+++ b/e2e/common/config/files/property-route.groovy
@@ -16,12 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kamel run -p my.message=test-property property-route.groovy --dev
-//
-
from('timer:property')
.routeId('property')
.log('property content is: {{my.message}}')
diff --git a/e2e/common/config/files/resources-route.groovy b/e2e/common/config/files/resource-configmap-route.groovy
similarity index 81%
copy from e2e/common/config/files/resources-route.groovy
copy to e2e/common/config/files/resource-configmap-route.groovy
index 1085840..3df9e05 100644
--- a/e2e/common/config/files/resources-route.groovy
+++ b/e2e/common/config/files/resource-configmap-route.groovy
@@ -16,10 +16,5 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resources-base64-encoded-route.groovy b/e2e/common/config/files/resource-file-base64-encoded-route.groovy
similarity index 87%
rename from e2e/common/config/files/resources-base64-encoded-route.groovy
rename to e2e/common/config/files/resource-file-base64-encoded-route.groovy
index 02559f0..8cbff0b 100644
--- a/e2e/common/config/files/resources-base64-encoded-route.groovy
+++ b/e2e/common/config/files/resource-file-base64-encoded-route.groovy
@@ -16,11 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt --compression=true resources-base64-encoded-route.groovy --dev
-//
-
from('timer:resources-bas64')
.routeId('resources-base64')
.setBody()
diff --git a/e2e/common/config/files/resources-binary-route.groovy b/e2e/common/config/files/resource-file-binary-route.groovy
similarity index 80%
rename from e2e/common/config/files/resources-binary-route.groovy
rename to e2e/common/config/files/resource-file-binary-route.groovy
index 8b0878b..c6faa9a 100644
--- a/e2e/common/config/files/resources-binary-route.groovy
+++ b/e2e/common/config/files/resource-file-binary-route.groovy
@@ -16,12 +16,7 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.zip resources-binary-route.groovy -d camel-zipfile --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
diff --git a/e2e/common/config/files/resources-route.groovy b/e2e/common/config/files/resource-file-route.groovy
similarity index 81%
copy from e2e/common/config/files/resources-route.groovy
copy to e2e/common/config/files/resource-file-route.groovy
index 1085840..6ab0338 100644
--- a/e2e/common/config/files/resources-route.groovy
+++ b/e2e/common/config/files/resource-file-route.groovy
@@ -16,10 +16,5 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resources-route.groovy b/e2e/common/config/files/resource-secret-route.groovy
similarity index 81%
rename from e2e/common/config/files/resources-route.groovy
rename to e2e/common/config/files/resource-secret-route.groovy
index 1085840..c2e5685 100644
--- a/e2e/common/config/files/resources-route.groovy
+++ b/e2e/common/config/files/resource-secret-route.groovy
@@ -16,10 +16,5 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/secrets/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-file-binary-route.groovy b/examples/user-config/resource-file-binary-route.groovy
index eef04d1..2121c26 100644
--- a/examples/user-config/resource-file-binary-route.groovy
+++ b/examples/user-config/resource-file-binary-route.groovy
@@ -21,7 +21,7 @@
// kamel run --resource resources-data.zip resource-file-binary-route.groovy -d camel-zipfile --dev
//
-from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 725f84c..c30a3aa 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -96,6 +96,8 @@ func (t *jvmTrait) Apply(e *Environment) error {
classpath := strset.New()
classpath.Add("./resources")
+ classpath.Add(configResourcesMountPath)
+ classpath.Add(dataResourcesMountPath)
for _, artifact := range kit.Status.Artifacts {
classpath.Add(artifact.Target)
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index cfa925c..f5bc7d1 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -19,6 +19,7 @@ package trait
import (
"context"
+ "fmt"
"sort"
"strings"
"testing"
@@ -103,12 +104,12 @@ func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("./resources", "/mount/path").List()
+ cp := strset.New("./resources", configResourcesMountPath, dataResourcesMountPath, "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- "./resources:/mount/path",
+ fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, dataResourcesMountPath),
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, d.Spec.Template.Spec.Containers[0].Args)
}
@@ -135,12 +136,12 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("./resources", "/mount/path").List()
+ cp := strset.New("./resources", configResourcesMountPath, dataResourcesMountPath, "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- "./resources:/mount/path",
+ fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, dataResourcesMountPath),
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, s.Spec.Template.Spec.Containers[0].Args)
}
[camel-k] 05/20: feat(cmd/run): --resource filename compatibility
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b9dbe12e7d8d1e058bbdc796aebea87b29ac5e38
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 16:04:41 2021 +0200
feat(cmd/run): --resource filename compatibility
Adding backward compatibility and a deprecation notice.
Ref #2003
---
pkg/cmd/run.go | 2 +-
pkg/cmd/run_help.go | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 69fcfe8..9d8a0fe 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -544,7 +544,7 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
}
for _, resource := range o.Resources {
- if config, parseErr := ParseConfigOption(resource); parseErr == nil {
+ if config, parseErr := ParseResourceOption(resource); parseErr == nil {
if applyResourceOptionErr := ApplyResourceOption(config, &integration.Spec, c, namespace, o.Compression); applyResourceOptionErr != nil {
return nil, applyResourceOptionErr
}
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index 927d7b8..ca36a91 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -22,6 +22,7 @@ import (
"fmt"
"path"
"regexp"
+ "strings"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/client"
@@ -54,8 +55,27 @@ func newRunConfigOption(configType configOptionType, value string) *RunConfigOpt
}
}
+// ParseResourceOption will parse and return a runConfigOption
+func ParseResourceOption(item string) (*RunConfigOption, error) {
+ // Deprecated: ensure backward compatibility with `--resource filename` format until version 1.5.x
+ // then replace with parseOption() func directly
+ option, err := parseOption(item)
+ if err != nil {
+ if strings.HasPrefix(err.Error(), "could not match configuration") {
+ fmt.Printf("Warn: --resource %s has been deprecated. You should use --resource file:%s instead.\n", item, item)
+ return newRunConfigOption(ConfigOptionTypeFile, item), nil
+ }
+ return nil, err
+ }
+ return option, nil
+}
+
// ParseConfigOption will parse and return a runConfigOption
func ParseConfigOption(item string) (*RunConfigOption, error) {
+ return parseOption(item)
+}
+
+func parseOption(item string) (*RunConfigOption, error) {
if !validConfigRegexp.MatchString(item) {
return nil, fmt.Errorf("could not match configuration %s, must match %v regular expression", item, validConfigRegexp)
}
[camel-k] 02/20: refactor(crd): configuration resource type
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 252eb5227e767b1ada91f07904c13f656d1eff96
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 10:42:28 2021 +0200
refactor(crd): configuration resource type
Ref #2003
---
config/crd/bases/camel.apache.org_integrationkits.yaml | 2 ++
config/crd/bases/camel.apache.org_integrationplatforms.yaml | 4 ++++
config/crd/bases/camel.apache.org_integrations.yaml | 4 ++++
config/crd/bases/camel.apache.org_kameletbindings.yaml | 2 ++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml | 2 ++
.../1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml | 4 ++++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml | 4 ++++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml | 2 ++
helm/camel-k/crds/crd-integration-kit.yaml | 2 ++
helm/camel-k/crds/crd-integration-platform.yaml | 4 ++++
helm/camel-k/crds/crd-integration.yaml | 4 ++++
helm/camel-k/crds/crd-kamelet-binding.yaml | 2 ++
12 files changed, 36 insertions(+)
diff --git a/config/crd/bases/camel.apache.org_integrationkits.yaml b/config/crd/bases/camel.apache.org_integrationkits.yaml
index 335ddb4..fd8f485 100644
--- a/config/crd/bases/camel.apache.org_integrationkits.yaml
+++ b/config/crd/bases/camel.apache.org_integrationkits.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 50b5738..1334a27 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
@@ -515,6 +517,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml
index a6f40f3..e6c6dac 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
@@ -5422,6 +5424,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index be5af62..60378f5 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
index 335ddb4..fd8f485 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
index 50b5738..1334a27 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
@@ -515,6 +517,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
index a6f40f3..e6c6dac 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
@@ -5422,6 +5424,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
index be5af62..60378f5 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/helm/camel-k/crds/crd-integration-kit.yaml b/helm/camel-k/crds/crd-integration-kit.yaml
index 335ddb4..fd8f485 100644
--- a/helm/camel-k/crds/crd-integration-kit.yaml
+++ b/helm/camel-k/crds/crd-integration-kit.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index 50b5738..1334a27 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
@@ -515,6 +517,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml
index a6f40f3..e6c6dac 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
@@ -5422,6 +5424,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml
index be5af62..60378f5 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceType:
+ type: string
type:
type: string
value:
[camel-k] 13/20: feat(cmd/run): validate destination path
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 3cd69e4babf80f355cb7d19ef1219f549a3254f8
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jun 3 16:39:49 2021 +0200
feat(cmd/run): validate destination path
Ref #2003
---
pkg/cmd/run_help.go | 23 +++++++++++++++++++++--
pkg/cmd/run_help_test.go | 15 +++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index a1ab41e..9734dbd 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -29,6 +29,8 @@ import (
"github.com/apache/camel-k/pkg/util/kubernetes"
)
+var invalidPaths = []string{"/etc/camel", "/deployments/dependencies"}
+
// RunConfigOption represents a config option
type RunConfigOption struct {
ConfigType configOptionType
@@ -41,6 +43,19 @@ func (runConfigOption *RunConfigOption) DestinationPath() string {
return runConfigOption.destinationPath
}
+// Validate checks if the DestinationPath exists and in case if it's a valid path
+func (runConfigOption *RunConfigOption) Validate() error {
+ if runConfigOption.destinationPath == "" {
+ return nil
+ }
+ for _, invalidPath := range invalidPaths {
+ if runConfigOption.destinationPath == invalidPath || strings.HasPrefix(runConfigOption.destinationPath, invalidPath+"/") {
+ return fmt.Errorf("you cannot mount a file under %s path", invalidPath)
+ }
+ }
+ return nil
+}
+
type configOptionType string
const (
@@ -79,7 +94,7 @@ func ParseResourceOption(item string) (*RunConfigOption, error) {
if err != nil {
if strings.HasPrefix(err.Error(), "could not match configuration") {
fmt.Printf("Warn: --resource %s has been deprecated. You should use --resource file:%s instead.\n", item, item)
- return newRunConfigOption(ConfigOptionTypeFile, item), nil
+ return parseOption("file:" + item)
}
return nil, err
}
@@ -109,7 +124,11 @@ func parseOption(item string) (*RunConfigOption, error) {
// Should never reach this
return nil, fmt.Errorf("invalid config option type %s", groups[1])
}
- return newRunConfigOption(cot, groups[2]), nil
+ configurationOption := newRunConfigOption(cot, groups[2])
+ if err := configurationOption.Validate(); err != nil {
+ return nil, err
+ }
+ return configurationOption, nil
}
func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
diff --git a/pkg/cmd/run_help_test.go b/pkg/cmd/run_help_test.go
index abae91d..ebbff23 100644
--- a/pkg/cmd/run_help_test.go
+++ b/pkg/cmd/run_help_test.go
@@ -67,3 +67,18 @@ func TestFilterFileLocation(t *testing.T) {
assert.Equal(t, "app.properties", filteredOptions[1])
assert.Equal(t, "/validfile", filteredOptions[2])
}
+
+func TestValidateFileLocation(t *testing.T) {
+ validLocation := "file:my-file.txt@/tmp/another-name.xml"
+ etcCamelLocation := "configmap:my-cm@/etc/camel/configmaps"
+ deploymentsDepsLocation := "secret:my-sec@/deployments/dependencies"
+
+ _, err := ParseConfigOption(validLocation)
+ assert.Nil(t, err)
+ _, err = ParseConfigOption(etcCamelLocation)
+ assert.NotNil(t, err)
+ assert.Equal(t, "you cannot mount a file under /etc/camel path", err.Error())
+ _, err = ParseConfigOption(deploymentsDepsLocation)
+ assert.NotNil(t, err)
+ assert.Equal(t, "you cannot mount a file under /deployments/dependencies path", err.Error())
+}
[camel-k] 07/20: feat(cmd/run): resource @path support
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 1f958527c5b1db1ed27b99e93c857a3d16f8716d
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Jun 2 15:24:59 2021 +0200
feat(cmd/run): resource @path support
Adding the possibility to specify the destination path for any resource
Ref #2003
---
pkg/apis/camel/v1/common_types.go | 8 ++++--
pkg/apis/camel/v1/integration_types_support.go | 11 ++++----
pkg/cmd/run.go | 2 +-
pkg/cmd/run_help.go | 35 ++++++++++++++++++------
pkg/cmd/run_help_test.go | 6 ++++
pkg/cmd/run_test.go | 8 +++---
pkg/trait/trait_types.go | 38 +++++++++++++++++---------
pkg/trait/util.go | 1 +
8 files changed, 74 insertions(+), 35 deletions(-)
diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go
index 6b2cda8..42a23fa 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -26,9 +26,10 @@ const TraitAnnotationPrefix = "trait.camel.apache.org/"
// ConfigurationSpec --
type ConfigurationSpec struct {
- Type string `json:"type"`
- Value string `json:"value"`
- ResourceType string `json:"resourceType,omitempty"`
+ Type string `json:"type"`
+ Value string `json:"value"`
+ ResourceType string `json:"resourceType,omitempty"`
+ ResourceMountPoint string `json:"resourceMountPoint,omitempty"`
}
// Artifact --
@@ -232,6 +233,7 @@ const (
// DataSpec --
type DataSpec struct {
Name string `json:"name,omitempty"`
+ Path string `json:"path,omitempty"`
Content string `json:"content,omitempty"`
RawContent []byte `json:"rawContent,omitempty"`
ContentRef string `json:"contentRef,omitempty"`
diff --git a/pkg/apis/camel/v1/integration_types_support.go b/pkg/apis/camel/v1/integration_types_support.go
index acf3bd6..8c2d3e5 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -109,12 +109,13 @@ func (in *IntegrationSpec) AddConfiguration(confType string, confValue string) {
})
}
-// AddConfigurationAsResourceType will set a configuration specified with a resource type
-func (in *IntegrationSpec) AddConfigurationAsResourceType(confType string, confValue string, resourceType string) {
+// AddConfigurationAsResource will set a configuration specified with a resource type
+func (in *IntegrationSpec) AddConfigurationAsResource(confType string, confValue string, resourceType string, resourceMountPoint string) {
in.Configuration = append(in.Configuration, ConfigurationSpec{
- Type: confType,
- Value: confValue,
- ResourceType: resourceType,
+ Type: confType,
+ Value: confValue,
+ ResourceType: resourceType,
+ ResourceMountPoint: resourceMountPoint,
})
}
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index ad0485d..6e4c373 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -82,7 +82,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
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 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("resource", nil, "Add a runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[@path])")
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")
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index ca36a91..12264c2 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -31,8 +31,14 @@ import (
// RunConfigOption represents a config option
type RunConfigOption struct {
- ConfigType configOptionType
- Value string
+ ConfigType configOptionType
+ Value string
+ destinationPath string
+}
+
+// DestinationPath is the location where the resource will be stored on destination
+func (runConfigOption *RunConfigOption) DestinationPath() string {
+ return runConfigOption.destinationPath
}
type configOptionType string
@@ -46,13 +52,23 @@ const (
ConfigOptionTypeFile configOptionType = "file"
)
-var validConfigRegexp = regexp.MustCompile(`^(configmap|secret|file)\:([\w\.\-\_\:\/]+)$`)
+var validConfigRegexp = regexp.MustCompile(`^(configmap|secret|file)\:([\w\.\-\_\:\/@]+)$`)
func newRunConfigOption(configType configOptionType, value string) *RunConfigOption {
+ optionValue, maybeDestinationPath := parseFileValue(value)
return &RunConfigOption{
- ConfigType: configType,
- Value: value,
+ ConfigType: configType,
+ Value: optionValue,
+ destinationPath: maybeDestinationPath,
+ }
+}
+
+func parseFileValue(value string) (string, string) {
+ split := strings.SplitN(value, "@", 2)
+ if len(split) == 2 {
+ return split[0], split[1]
}
+ return value, ""
}
// ParseResourceOption will parse and return a runConfigOption
@@ -107,14 +123,14 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
} else if resourceType != v1.ResourceTypeData && cm.BinaryData != nil {
return fmt.Errorf("you cannot provide a binary config, use a text file instead")
}
- integrationSpec.AddConfigurationAsResourceType(string(config.ConfigType), config.Value, string(resourceType))
+ integrationSpec.AddConfigurationAsResource(string(config.ConfigType), config.Value, string(resourceType), config.DestinationPath())
case ConfigOptionTypeSecret:
secret := kubernetes.LookupSecret(context.Background(), c, namespace, config.Value)
if secret == nil {
fmt.Printf("Warn: %s Secret not found in %s namespace, make sure to provide it before the Integration can run\n",
config.Value, namespace)
}
- integrationSpec.AddConfigurationAsResourceType(string(config.ConfigType), config.Value, string(resourceType))
+ integrationSpec.AddConfigurationAsResource(string(config.ConfigType), config.Value, string(resourceType), config.DestinationPath())
case ConfigOptionTypeFile:
// Don't allow a binary non compressed resource
rawData, contentType, err := loadRawContent(config.Value)
@@ -124,7 +140,7 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
if resourceType != v1.ResourceTypeData && !enableCompression && isBinary(contentType) {
return fmt.Errorf("you cannot provide a binary config, use a text file or check --resource flag instead")
}
- resourceSpec, err := binaryOrTextResource(path.Base(config.Value), rawData, contentType, enableCompression, resourceType)
+ resourceSpec, err := binaryOrTextResource(path.Base(config.Value), rawData, contentType, enableCompression, resourceType, config.DestinationPath())
if err != nil {
return err
}
@@ -147,10 +163,11 @@ func ApplyResourceOption(config *RunConfigOption, integrationSpec *v1.Integratio
return applyOption(config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeData)
}
-func binaryOrTextResource(fileName string, data []byte, contentType string, base64Compression bool, resourceType v1.ResourceType) (v1.ResourceSpec, error) {
+func binaryOrTextResource(fileName string, data []byte, contentType string, base64Compression bool, resourceType v1.ResourceType, destinationPath string) (v1.ResourceSpec, error) {
resourceSpec := v1.ResourceSpec{
DataSpec: v1.DataSpec{
Name: fileName,
+ Path: destinationPath,
ContentKey: fileName,
ContentType: contentType,
Compression: false,
diff --git a/pkg/cmd/run_help_test.go b/pkg/cmd/run_help_test.go
index 39d67f0..5eab301 100644
--- a/pkg/cmd/run_help_test.go
+++ b/pkg/cmd/run_help_test.go
@@ -28,6 +28,7 @@ func TestParseConfigOption(t *testing.T) {
validSecret := "secret:my-secret"
validFile := "file:/tmp/my-file.txt"
notValid := "someprotocol:wrong"
+ validLocation := "file:my-file.txt@/tmp/another-name.xml"
configmap, err := ParseConfigOption(validConfigMap)
assert.Nil(t, err)
@@ -43,4 +44,9 @@ func TestParseConfigOption(t *testing.T) {
assert.Equal(t, "/tmp/my-file.txt", file.Value)
_, err = ParseConfigOption(notValid)
assert.NotNil(t, err)
+ location, err := ParseConfigOption(validLocation)
+ assert.Nil(t, err)
+ assert.Equal(t, ConfigOptionTypeFile, location.ConfigType)
+ assert.Equal(t, "my-file.txt", location.Value)
+ assert.Equal(t, "/tmp/another-name.xml", location.DestinationPath())
}
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 7d1f8cd..bae4c9d 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -487,7 +487,7 @@ func TestRunWithSavedValues(t *testing.T) {
}*/
func TestRunBinaryResource(t *testing.T) {
- binaryResourceSpec, err := binaryOrTextResource("file.ext", []byte{1, 2, 3, 4}, "application/octet-stream", false, v1.ResourceTypeData)
+ binaryResourceSpec, err := binaryOrTextResource("file.ext", []byte{1, 2, 3, 4}, "application/octet-stream", false, v1.ResourceTypeData, "")
assert.Nil(t, err)
assert.Equal(t, "", binaryResourceSpec.Content)
assert.NotNil(t, binaryResourceSpec.RawContent)
@@ -499,7 +499,7 @@ func TestRunBinaryResource(t *testing.T) {
func TestRunBinaryCompressedResource(t *testing.T) {
data := []byte{1, 2, 3, 4}
base64Compressed, _ := compressToString(data)
- binaryResourceSpec, err := binaryOrTextResource("file.ext", data, "application/octet-stream", true, v1.ResourceTypeData)
+ binaryResourceSpec, err := binaryOrTextResource("file.ext", data, "application/octet-stream", true, v1.ResourceTypeData, "")
assert.Nil(t, err)
assert.Equal(t, base64Compressed, binaryResourceSpec.Content)
assert.Nil(t, binaryResourceSpec.RawContent)
@@ -509,7 +509,7 @@ func TestRunBinaryCompressedResource(t *testing.T) {
}
func TestRunTextResource(t *testing.T) {
- textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello world"), "text/plain", false, v1.ResourceTypeData)
+ textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello world"), "text/plain", false, v1.ResourceTypeData, "")
assert.Nil(t, err)
assert.Equal(t, "hello world", textResourceSpec.Content)
assert.Nil(t, textResourceSpec.RawContent)
@@ -521,7 +521,7 @@ func TestRunTextResource(t *testing.T) {
func TestRunTextCompressedResource(t *testing.T) {
data := []byte("hello horld")
base64Compressed, _ := compressToString(data)
- textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello horld"), "text/plain", true, v1.ResourceTypeData)
+ textResourceSpec, err := binaryOrTextResource("file.ext", []byte("hello horld"), "text/plain", true, v1.ResourceTypeData, "")
assert.Nil(t, err)
assert.Equal(t, base64Compressed, textResourceSpec.Content)
assert.Nil(t, textResourceSpec.RawContent)
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 2786f25..9049fe0 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -613,8 +613,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
refName := fmt.Sprintf("i-resource-%03d", i)
resName := strings.TrimPrefix(r.Name, "/")
cmKey := "content"
- resourceMountPoint := getResourceMountPoint(r.Type)
- resPath := path.Join(resourceMountPoint, resName)
+ resPath := getResourcePath(resName, r.Path, r.Type)
if r.ContentRef != "" {
cmName = r.ContentRef
@@ -711,7 +710,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
*mnts = append(*mnts, corev1.VolumeMount{
Name: refName,
- MountPath: path.Join(getConfigmapMountPoint(configmaps["resourceType"]), strings.ToLower(configmaps["value"])),
+ MountPath: getConfigmapMountPoint(configmaps["value"], configmaps["resourceMountPoint"], configmaps["resourceType"]),
ReadOnly: true,
})
}
@@ -751,7 +750,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
*mnts = append(*mnts, corev1.VolumeMount{
Name: refName,
- MountPath: path.Join(getSecretMountPoint(secret["resourceType"]), strings.ToLower(secret["value"])),
+ MountPath: getSecretMountPoint(secret["value"], secret["resourceMountPoint"], secret["resourceType"]),
ReadOnly: true,
})
}
@@ -786,31 +785,44 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
}
}
-func getResourceMountPoint(resourceType v1.ResourceType) string {
+func getResourcePath(resourceName string, maybePath string, resourceType v1.ResourceType) string {
+ // If the path is specified, we'll return it
+ if maybePath != "" {
+ return maybePath
+ }
+ // otherwise return a default path, according to the resource type
switch resourceType {
case v1.ResourceTypeData:
- return dataResourcesMountPath
+ return path.Join(dataResourcesMountPath, resourceName)
}
// Default, config type
- return configResourcesMountPath
+ return path.Join(configResourcesMountPath, resourceName)
}
-func getConfigmapMountPoint(resourceType string) string {
+func getConfigmapMountPoint(resourceName string, maybeMountPoint string, resourceType string) string {
+ // If the mount point is specified, we'll return it
+ if maybeMountPoint != "" {
+ return maybeMountPoint
+ }
switch resourceType {
case "data":
- return dataConfigmapsMountPath
+ return path.Join(dataConfigmapsMountPath, resourceName)
}
// Default, config type
- return configConfigmapsMountPath
+ return path.Join(configConfigmapsMountPath, resourceName)
}
-func getSecretMountPoint(resourceType string) string {
+func getSecretMountPoint(resourceName string, maybeMountPoint string, resourceType string) string {
+ // If the mount point is specified, we'll return it
+ if maybeMountPoint != "" {
+ return maybeMountPoint
+ }
switch resourceType {
case "data":
- return dataSecretsMountPath
+ return path.Join(dataSecretsMountPath, resourceName)
}
// Default, config type
- return configSecretsMountPath
+ return path.Join(configSecretsMountPath, resourceName)
}
func (e *Environment) collectConfigurationValues(configurationType string) []string {
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 4a2dc5d..0f5d936 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -97,6 +97,7 @@ func collectConfigurations(configurationType string, configurable ...v1.Configur
var item = make(map[string]string)
item["value"] = entry.Value
item["resourceType"] = entry.ResourceType
+ item["resourceMountPoint"] = entry.ResourceMountPoint
result = append(result, item)
}
}
[camel-k] 09/20: doc(example): resource @path
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 1446a6ce64323f85c34918a0662f5041ec6d5ec4
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Jun 2 15:26:07 2021 +0200
doc(example): resource @path
---
.../resource-configmap-location-route.groovy | 27 ++++++++++++++++++++++
.../resource-file-location-route.groovy | 25 ++++++++++++++++++++
.../resource-secret-location-route.groovy | 27 ++++++++++++++++++++++
3 files changed, 79 insertions(+)
diff --git a/examples/user-config/resource-configmap-location-route.groovy b/examples/user-config/resource-configmap-location-route.groovy
new file mode 100644
index 0000000..4714cc4
--- /dev/null
+++ b/examples/user-config/resource-configmap-location-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:
+//
+// kubectl create configmap my-cm --from-literal=my-configmap-key="configmap content"
+// kamel run --resource configmap:my-cm@/tmp/app/data resource-configmap-location-route.groovy --dev
+//
+
+from('file:/tmp/app/data/?fileName=my-configmap-key&noop=true&idempotent=false')
+ .log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-file-location-route.groovy b/examples/user-config/resource-file-location-route.groovy
new file mode 100644
index 0000000..ec59eb4
--- /dev/null
+++ b/examples/user-config/resource-file-location-route.groovy
@@ -0,0 +1,25 @@
+// 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 --resource file:resources-data.txt@/tmp/input.txt resource-file-location-route.groovy --dev
+//
+
+from('file:/tmp/?fileName=input.txt&noop=true&idempotent=false')
+ .log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-secret-location-route.groovy b/examples/user-config/resource-secret-location-route.groovy
new file mode 100644
index 0000000..747e7b2
--- /dev/null
+++ b/examples/user-config/resource-secret-location-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:
+//
+// kubectl create secret generic my-sec --from-literal=my-secret-key="very top secret"
+// kamel run --resource secret:my-sec@/tmp/app/data resource-secret-location-route.groovy --dev
+//
+
+from('file:/tmp/app/data/?fileName=my-secret-key&noop=true&idempotent=false')
+ .log('resource file content is: ${body}')
[camel-k] 20/20: chore(cmd/run): single resource dir and cli syntax
description
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 73339cf8657de13cff07a0dc4723cf74f27f9f95
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Jun 16 12:21:41 2021 +0200
chore(cmd/run): single resource dir and cli syntax description
Ref #2003
---
docs/modules/ROOT/pages/cli/modeline.adoc | 4 ++--
e2e/common/config/files/resource-configmap-route.groovy | 2 +-
e2e/common/config/files/resource-file-binary-route.groovy | 2 +-
e2e/common/config/files/resource-file-route.groovy | 2 +-
e2e/common/config/files/resource-secret-route.groovy | 2 +-
examples/user-config/resource-configmap-route.groovy | 2 +-
examples/user-config/resource-file-binary-route.groovy | 2 +-
examples/user-config/resource-file-route.groovy | 2 +-
examples/user-config/resource-secret-route.groovy | 2 +-
pkg/cmd/run.go | 4 ++--
pkg/trait/jvm.go | 2 +-
pkg/trait/jvm_test.go | 8 ++++----
pkg/trait/trait_test.go | 10 +++++-----
pkg/trait/trait_types.go | 11 ++++-------
14 files changed, 26 insertions(+), 29 deletions(-)
diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc
index ac1b734..e54de1c 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 a runtime configuration from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key]_)
+|Add a runtime configuration from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key]_, where name represents the local file path or the configmap/secret name and key optionally represents the configmap/secret key to be filtered)
|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 runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key][@path]_)
+|Add a runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key][@path]_, where name represents the local file path or the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path)
|trait
|Configure a trait, e.g. `trait=service.enabled=false`
diff --git a/e2e/common/config/files/resource-configmap-route.groovy b/e2e/common/config/files/resource-configmap-route.groovy
index 3df9e05..6cccf02 100644
--- a/e2e/common/config/files/resource-configmap-route.groovy
+++ b/e2e/common/config/files/resource-configmap-route.groovy
@@ -16,5 +16,5 @@
* limitations under the License.
*/
-from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
+from('file:/etc/camel/resources/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resource-file-binary-route.groovy b/e2e/common/config/files/resource-file-binary-route.groovy
index c6faa9a..ff50ad1 100644
--- a/e2e/common/config/files/resource-file-binary-route.groovy
+++ b/e2e/common/config/files/resource-file-binary-route.groovy
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-from('file:/etc/camel/data/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
+from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
diff --git a/e2e/common/config/files/resource-file-route.groovy b/e2e/common/config/files/resource-file-route.groovy
index 6ab0338..d515385 100644
--- a/e2e/common/config/files/resource-file-route.groovy
+++ b/e2e/common/config/files/resource-file-route.groovy
@@ -16,5 +16,5 @@
* limitations under the License.
*/
-from('file:/etc/camel/data/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resource-secret-route.groovy b/e2e/common/config/files/resource-secret-route.groovy
index c2e5685..63f4c76 100644
--- a/e2e/common/config/files/resource-secret-route.groovy
+++ b/e2e/common/config/files/resource-secret-route.groovy
@@ -16,5 +16,5 @@
* limitations under the License.
*/
-from('file:/etc/camel/data/secrets/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
+from('file:/etc/camel/resources/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-configmap-route.groovy b/examples/user-config/resource-configmap-route.groovy
index 1d7ef24..5d0a522 100644
--- a/examples/user-config/resource-configmap-route.groovy
+++ b/examples/user-config/resource-configmap-route.groovy
@@ -23,5 +23,5 @@
// kamel run --resource configmap:my-cm resource-configmap-route.groovy --dev
//
-from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
+from('file:/etc/camel/resources/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-file-binary-route.groovy b/examples/user-config/resource-file-binary-route.groovy
index 2121c26..eef04d1 100644
--- a/examples/user-config/resource-file-binary-route.groovy
+++ b/examples/user-config/resource-file-binary-route.groovy
@@ -21,7 +21,7 @@
// kamel run --resource resources-data.zip resource-file-binary-route.groovy -d camel-zipfile --dev
//
-from('file:/etc/camel/data/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
+from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
diff --git a/examples/user-config/resource-file-route.groovy b/examples/user-config/resource-file-route.groovy
index f39f4e5..63d6298 100644
--- a/examples/user-config/resource-file-route.groovy
+++ b/examples/user-config/resource-file-route.groovy
@@ -21,5 +21,5 @@
// kamel run --resource file:resources-data.txt resource-file-route.groovy --dev
//
-from('file:/etc/camel/data/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-secret-route.groovy b/examples/user-config/resource-secret-route.groovy
index b46bb49..c6dc923 100644
--- a/examples/user-config/resource-secret-route.groovy
+++ b/examples/user-config/resource-secret-route.groovy
@@ -23,5 +23,5 @@
// kamel run --resource secret:my-sec resource-secret-route.groovy --dev
//
-from('file:/etc/camel/data/secrets/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
+from('file:/etc/camel/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index e6d42b4..d85e71a 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -81,8 +81,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 a runtime configuration from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key])")
- cmd.Flags().StringArray("resource", nil, "Add a runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key][@path])")
+ cmd.Flags().StringArray("config", nil, "Add a runtime configuration from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key], where name represents the local file path or the configmap/secret name and key optionally represents the configmap/secret key to be filtered)")
+ cmd.Flags().StringArray("resource", nil, "Add a runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key][@path], where name represents the local file path or the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path)")
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")
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index c30a3aa..44da721 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -97,7 +97,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
classpath.Add("./resources")
classpath.Add(configResourcesMountPath)
- classpath.Add(dataResourcesMountPath)
+ classpath.Add(resourcesDefaultMountPath)
for _, artifact := range kit.Status.Artifacts {
classpath.Add(artifact.Target)
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index f5bc7d1..b568133 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -104,12 +104,12 @@ func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("./resources", configResourcesMountPath, dataResourcesMountPath, "/mount/path").List()
+ cp := strset.New("./resources", configResourcesMountPath, resourcesDefaultMountPath, "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, dataResourcesMountPath),
+ fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, resourcesDefaultMountPath),
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, d.Spec.Template.Spec.Containers[0].Args)
}
@@ -136,12 +136,12 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("./resources", configResourcesMountPath, dataResourcesMountPath, "/mount/path").List()
+ cp := strset.New("./resources", configResourcesMountPath, resourcesDefaultMountPath, "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, dataResourcesMountPath),
+ fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, resourcesDefaultMountPath),
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, s.Spec.Template.Spec.Containers[0].Args)
}
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index f49a5b0..100056d 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -315,7 +315,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "i-resource-001" })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/data/resources/res2.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/resources/res2.txt", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeploymentName+"-resource-002" })
assert.NotNil(t, v)
@@ -326,7 +326,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "i-resource-002" })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/data/resources/res3.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/resources/res3.txt", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeploymentName+"-resource-003" })
assert.NotNil(t, v)
@@ -337,7 +337,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "i-resource-003" })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/data/resources/res4.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/resources/res4.txt", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == "test-configmap" })
assert.NotNil(t, v)
@@ -480,7 +480,7 @@ func TestConfigureVolumesAndMountsBinaryAndTextResources(t *testing.T) {
m := findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == v.Name })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/data/resources/res1.bin", m.MountPath)
+ assert.Equal(t, "/etc/camel/resources/res1.bin", m.MountPath)
v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == "my-cm2" })
assert.NotNil(t, v)
@@ -491,7 +491,7 @@ func TestConfigureVolumesAndMountsBinaryAndTextResources(t *testing.T) {
m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == v.Name })
assert.NotNil(t, m)
- assert.Equal(t, "/etc/camel/data/resources/res2.txt", m.MountPath)
+ assert.Equal(t, "/etc/camel/resources/res2.txt", m.MountPath)
}
func TestOnlySomeTraitsInfluenceBuild(t *testing.T) {
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 6b3a23d..f22e3d5 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -51,10 +51,7 @@ var (
basePath = "/etc/camel"
confDPath = path.Join(basePath, "conf.d")
sourcesMountPath = path.Join(basePath, "sources")
- dataDefaultMountPath = path.Join(basePath, "data")
- dataResourcesMountPath = path.Join(dataDefaultMountPath, "resources")
- dataConfigmapsMountPath = path.Join(dataDefaultMountPath, "configmaps")
- dataSecretsMountPath = path.Join(dataDefaultMountPath, "secrets")
+ resourcesDefaultMountPath = path.Join(basePath, "resources")
configResourcesMountPath = path.Join(confDPath, "_resources")
configConfigmapsMountPath = path.Join(confDPath, "_configmaps")
configSecretsMountPath = path.Join(confDPath, "_secrets")
@@ -818,7 +815,7 @@ func getResourcePath(resourceName string, maybePath string, resourceType v1.Reso
// otherwise return a default path, according to the resource type
switch resourceType {
case v1.ResourceTypeData:
- return path.Join(dataResourcesMountPath, resourceName)
+ return path.Join(resourcesDefaultMountPath, resourceName)
}
// Default, config type
return path.Join(configResourcesMountPath, resourceName)
@@ -831,7 +828,7 @@ func getConfigmapMountPoint(resourceName string, maybeMountPoint string, resourc
}
switch resourceType {
case "data":
- return path.Join(dataConfigmapsMountPath, resourceName)
+ return path.Join(resourcesDefaultMountPath, resourceName)
}
// Default, config type
return path.Join(configConfigmapsMountPath, resourceName)
@@ -844,7 +841,7 @@ func getSecretMountPoint(resourceName string, maybeMountPoint string, resourceTy
}
switch resourceType {
case "data":
- return path.Join(dataSecretsMountPath, resourceName)
+ return path.Join(resourcesDefaultMountPath, resourceName)
}
// Default, config type
return path.Join(configSecretsMountPath, resourceName)
[camel-k] 16/20: chore(crd): configmap/secret eky filtering regen
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 7a31b305ed3c8465214b6b0777d9671172a3f373
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jun 7 12:38:13 2021 +0200
chore(crd): configmap/secret eky filtering regen
Ref #2003
---
config/crd/bases/camel.apache.org_integrationkits.yaml | 2 ++
config/crd/bases/camel.apache.org_integrationplatforms.yaml | 4 ++++
config/crd/bases/camel.apache.org_integrations.yaml | 4 ++++
config/crd/bases/camel.apache.org_kameletbindings.yaml | 2 ++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml | 2 ++
.../1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml | 4 ++++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml | 4 ++++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml | 2 ++
helm/camel-k/crds/crd-integration-kit.yaml | 2 ++
helm/camel-k/crds/crd-integration-platform.yaml | 4 ++++
helm/camel-k/crds/crd-integration.yaml | 4 ++++
helm/camel-k/crds/crd-kamelet-binding.yaml | 2 ++
12 files changed, 36 insertions(+)
diff --git a/config/crd/bases/camel.apache.org_integrationkits.yaml b/config/crd/bases/camel.apache.org_integrationkits.yaml
index 058d5bc..89bae12 100644
--- a/config/crd/bases/camel.apache.org_integrationkits.yaml
+++ b/config/crd/bases/camel.apache.org_integrationkits.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 6be160e..e7c66a0 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
@@ -519,6 +521,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml
index c93c8d0..27987cb 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
@@ -5430,6 +5432,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index a71f560..c577cc6 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
index 058d5bc..89bae12 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
index 6be160e..e7c66a0 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
@@ -519,6 +521,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
index c93c8d0..27987cb 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
@@ -5430,6 +5432,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
index a71f560..c577cc6 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/helm/camel-k/crds/crd-integration-kit.yaml b/helm/camel-k/crds/crd-integration-kit.yaml
index 058d5bc..89bae12 100644
--- a/helm/camel-k/crds/crd-integration-kit.yaml
+++ b/helm/camel-k/crds/crd-integration-kit.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index 6be160e..e7c66a0 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
@@ -519,6 +521,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml
index c93c8d0..27987cb 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
@@ -5430,6 +5432,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml
index a71f560..c577cc6 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceKey:
+ type: string
resourceMountPoint:
type: string
resourceType:
[camel-k] 08/20: chore(crd): autogen update
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 573ea1bb56455d69c8e970c45dbe9c90fb99a107
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Jun 2 15:25:34 2021 +0200
chore(crd): autogen update
Ref #2003
---
config/crd/bases/camel.apache.org_builds.yaml | 4 ++++
config/crd/bases/camel.apache.org_integrationkits.yaml | 2 ++
config/crd/bases/camel.apache.org_integrationplatforms.yaml | 4 ++++
config/crd/bases/camel.apache.org_integrations.yaml | 12 ++++++++++++
config/crd/bases/camel.apache.org_kameletbindings.yaml | 6 ++++++
config/crd/bases/camel.apache.org_kamelets.yaml | 2 ++
.../camel-k-dev/1.5.0-snapshot/camel.apache.org_builds.yaml | 4 ++++
.../1.5.0-snapshot/camel.apache.org_integrationkits.yaml | 2 ++
.../camel.apache.org_integrationplatforms.yaml | 4 ++++
.../1.5.0-snapshot/camel.apache.org_integrations.yaml | 12 ++++++++++++
.../1.5.0-snapshot/camel.apache.org_kameletbindings.yaml | 6 ++++++
.../1.5.0-snapshot/camel.apache.org_kamelets.yaml | 2 ++
helm/camel-k/crds/crd-build.yaml | 4 ++++
helm/camel-k/crds/crd-integration-kit.yaml | 2 ++
helm/camel-k/crds/crd-integration-platform.yaml | 4 ++++
helm/camel-k/crds/crd-integration.yaml | 12 ++++++++++++
helm/camel-k/crds/crd-kamelet-binding.yaml | 6 ++++++
helm/camel-k/crds/crd-kamelet.yaml | 2 ++
18 files changed, 90 insertions(+)
diff --git a/config/crd/bases/camel.apache.org_builds.yaml b/config/crd/bases/camel.apache.org_builds.yaml
index b7f82ec..7a142c9 100644
--- a/config/crd/bases/camel.apache.org_builds.yaml
+++ b/config/crd/bases/camel.apache.org_builds.yaml
@@ -286,6 +286,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -386,6 +388,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the
source (e.g. if type is "template")
diff --git a/config/crd/bases/camel.apache.org_integrationkits.yaml b/config/crd/bases/camel.apache.org_integrationkits.yaml
index fd8f485..058d5bc 100644
--- a/config/crd/bases/camel.apache.org_integrationkits.yaml
+++ b/config/crd/bases/camel.apache.org_integrationkits.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 1334a27..6be160e 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -517,6 +519,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml
index e6c6dac..c93c8d0 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -188,6 +190,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -227,6 +231,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
@@ -5424,6 +5430,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -5486,6 +5494,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -5523,6 +5533,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index 60378f5..a71f560 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -190,6 +192,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -229,6 +233,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source
(e.g. if type is "template")
diff --git a/config/crd/bases/camel.apache.org_kamelets.yaml b/config/crd/bases/camel.apache.org_kamelets.yaml
index e8371f9..fbd3da8 100644
--- a/config/crd/bases/camel.apache.org_kamelets.yaml
+++ b/config/crd/bases/camel.apache.org_kamelets.yaml
@@ -247,6 +247,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_builds.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_builds.yaml
index b7f82ec..7a142c9 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_builds.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_builds.yaml
@@ -286,6 +286,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -386,6 +388,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the
source (e.g. if type is "template")
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
index fd8f485..058d5bc 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationkits.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
index 1334a27..6be160e 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrationplatforms.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -517,6 +519,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
index e6c6dac..c93c8d0 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_integrations.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -188,6 +190,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -227,6 +231,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
@@ -5424,6 +5430,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -5486,6 +5494,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -5523,6 +5533,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
index 60378f5..a71f560 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kameletbindings.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -190,6 +192,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -229,6 +233,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source
(e.g. if type is "template")
diff --git a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kamelets.yaml b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kamelets.yaml
index e8371f9..fbd3da8 100644
--- a/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kamelets.yaml
+++ b/deploy/olm-catalog/camel-k-dev/1.5.0-snapshot/camel.apache.org_kamelets.yaml
@@ -247,6 +247,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
diff --git a/helm/camel-k/crds/crd-build.yaml b/helm/camel-k/crds/crd-build.yaml
index b7f82ec..7a142c9 100644
--- a/helm/camel-k/crds/crd-build.yaml
+++ b/helm/camel-k/crds/crd-build.yaml
@@ -286,6 +286,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -386,6 +388,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the
source (e.g. if type is "template")
diff --git a/helm/camel-k/crds/crd-integration-kit.yaml b/helm/camel-k/crds/crd-integration-kit.yaml
index fd8f485..058d5bc 100644
--- a/helm/camel-k/crds/crd-integration-kit.yaml
+++ b/helm/camel-k/crds/crd-integration-kit.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index 1334a27..6be160e 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -251,6 +251,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -517,6 +519,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml
index e6c6dac..c93c8d0 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -75,6 +75,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -188,6 +190,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -227,6 +231,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
@@ -5424,6 +5430,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -5486,6 +5494,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -5523,6 +5533,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml
index 60378f5..a71f560 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -76,6 +76,8 @@ spec:
items:
description: ConfigurationSpec --
properties:
+ resourceMountPoint:
+ type: string
resourceType:
type: string
type:
@@ -190,6 +192,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
rawContent:
format: byte
type: string
@@ -229,6 +233,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source
(e.g. if type is "template")
diff --git a/helm/camel-k/crds/crd-kamelet.yaml b/helm/camel-k/crds/crd-kamelet.yaml
index e8371f9..fbd3da8 100644
--- a/helm/camel-k/crds/crd-kamelet.yaml
+++ b/helm/camel-k/crds/crd-kamelet.yaml
@@ -247,6 +247,8 @@ spec:
type: string
name:
type: string
+ path:
+ type: string
property-names:
description: List of property names defined in the source (e.g.
if type is "template")
[camel-k] 17/20: chore(e2e): configmap/secret key test
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 90cbbda23ee38feb294fcaf4add219b7be1a7960
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jun 7 12:38:43 2021 +0200
chore(e2e): configmap/secret key test
Ref #2003
---
e2e/common/config/config_test.go | 17 +++++++++++++++++
.../resource-configmap-key-location-route.groovy | 20 ++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index 9282fad..07ba32f 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -64,6 +64,12 @@ func TestRunConfigExamples(t *testing.T) {
cmData["my-configmap-key"] = "my-configmap-content"
NewPlainTextConfigmap(ns, "my-cm", cmData)
+ // Store a configmap with multiple values
+ var cmDataMulti = make(map[string]string)
+ cmDataMulti["my-configmap-key"] = "should-not-see-it"
+ cmDataMulti["my-configmap-key-2"] = "my-configmap-content-2"
+ NewPlainTextConfigmap(ns, "my-cm-multi", cmDataMulti)
+
t.Run("Config configmap", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/config-configmap-route.groovy", "--config", "configmap:my-cm").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "config-configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
@@ -92,6 +98,17 @@ func TestRunConfigExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
+ t.Run("Resource configmap with filtered key and destination", func(t *testing.T) {
+ // We'll use the configmap contaning 2 values filtering only 1 key
+
+ Expect(Kamel("run", "-n", ns, "./files/resource-configmap-key-location-route.groovy", "--resource", "configmap:my-cm-multi/my-configmap-key-2@/tmp/app").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-configmap-key-location-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-configmap-key-location-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-configmap-key-location-route"), TestTimeoutShort).ShouldNot(ContainSubstring(cmDataMulti["my-configmap-key"]))
+ Eventually(IntegrationLogs(ns, "resource-configmap-key-location-route"), TestTimeoutShort).Should(ContainSubstring(cmDataMulti["my-configmap-key-2"]))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
+
// Secret
// Store a secret on the cluster
diff --git a/e2e/common/config/files/resource-configmap-key-location-route.groovy b/e2e/common/config/files/resource-configmap-key-location-route.groovy
new file mode 100644
index 0000000..c065401
--- /dev/null
+++ b/e2e/common/config/files/resource-configmap-key-location-route.groovy
@@ -0,0 +1,20 @@
+// 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.
+ */
+
+from('file:/tmp/app/?noop=true&idempotent=false')
+ .log('resource file content is: ${body}')
[camel-k] 03/20: refactor(example): resource run option
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 95a51ef752af8f4d830b6ea27503f553112b882a
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 10:43:05 2021 +0200
refactor(example): resource run option
---
.../{configmap-route.groovy => config-configmap-route.groovy} | 2 +-
examples/user-config/config-file-route.groovy | 6 +++---
.../{secret-route.groovy => config-secret-route.groovy} | 2 +-
...configmap-route.groovy => resource-configmap-route.groovy} | 11 ++++-------
...route.groovy => resource-file-base64-encoded-route.groovy} | 2 +-
...-binary-route.groovy => resource-file-binary-route.groovy} | 2 +-
.../{resources-route.groovy => resource-file-route.groovy} | 4 ++--
.../{secret-route.groovy => resource-secret-route.groovy} | 11 ++++-------
8 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/examples/user-config/configmap-route.groovy b/examples/user-config/config-configmap-route.groovy
similarity index 93%
copy from examples/user-config/configmap-route.groovy
copy to examples/user-config/config-configmap-route.groovy
index 948cb15..97653b8 100644
--- a/examples/user-config/configmap-route.groovy
+++ b/examples/user-config/config-configmap-route.groovy
@@ -20,7 +20,7 @@
// To run this integrations use:
//
// kubectl create configmap my-cm --from-literal=my-configmap-key="configmap content"
-// kamel run --config configmap:my-cm configmap-route.groovy --dev
+// kamel run --config configmap:my-cm config-configmap-route.groovy --dev
//
from('timer:configmap')
diff --git a/examples/user-config/config-file-route.groovy b/examples/user-config/config-file-route.groovy
index 53b347f..e899acd 100644
--- a/examples/user-config/config-file-route.groovy
+++ b/examples/user-config/config-file-route.groovy
@@ -18,11 +18,11 @@
//
// To run this integrations use:
-// kamel run --config file:resources-data.txt resources-route.groovy --dev
+// kamel run --config file:resources-data.txt config-file-route.groovy --dev
//
-from('timer:resources')
- .routeId('resources')
+from('timer:config-file')
+ .routeId('config-file')
.setBody()
.simple("resource:classpath:resources-data.txt")
.log('resource file content is: ${body}')
diff --git a/examples/user-config/secret-route.groovy b/examples/user-config/config-secret-route.groovy
similarity index 94%
copy from examples/user-config/secret-route.groovy
copy to examples/user-config/config-secret-route.groovy
index 7027b84..178bb8e 100644
--- a/examples/user-config/secret-route.groovy
+++ b/examples/user-config/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 --config secret:my-sec secret-route.groovy --dev
+// kamel run --config secret:my-sec config-secret-route.groovy --dev
//
from('timer:secret')
diff --git a/examples/user-config/configmap-route.groovy b/examples/user-config/resource-configmap-route.groovy
similarity index 80%
rename from examples/user-config/configmap-route.groovy
rename to examples/user-config/resource-configmap-route.groovy
index 948cb15..1d7ef24 100644
--- a/examples/user-config/configmap-route.groovy
+++ b/examples/user-config/resource-configmap-route.groovy
@@ -18,13 +18,10 @@
//
// To run this integrations use:
-//
+//
// kubectl create configmap my-cm --from-literal=my-configmap-key="configmap content"
-// kamel run --config configmap:my-cm configmap-route.groovy --dev
+// kamel run --resource configmap:my-cm resource-configmap-route.groovy --dev
//
-from('timer:configmap')
- .routeId('configmap')
- .setBody()
- .simple("resource:classpath:my-configmap-key")
- .log('configmap content is: ${body}')
+from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
+ .log('resource file content is: ${body}')
diff --git a/examples/user-config/resources-base64-encoded-route.groovy b/examples/user-config/resource-file-base64-encoded-route.groovy
similarity index 96%
rename from examples/user-config/resources-base64-encoded-route.groovy
rename to examples/user-config/resource-file-base64-encoded-route.groovy
index 02559f0..281d6ad 100644
--- a/examples/user-config/resources-base64-encoded-route.groovy
+++ b/examples/user-config/resource-file-base64-encoded-route.groovy
@@ -18,7 +18,7 @@
//
// To run this integrations use:
-// kamel run --resource resources-data.txt --compression=true resources-base64-encoded-route.groovy --dev
+// kamel run --resource resources-data.txt --compression=true resource-file-base64-encoded-route.groovy --dev
//
from('timer:resources-bas64')
diff --git a/examples/user-config/resources-binary-route.groovy b/examples/user-config/resource-file-binary-route.groovy
similarity index 91%
rename from examples/user-config/resources-binary-route.groovy
rename to examples/user-config/resource-file-binary-route.groovy
index 8b0878b..eef04d1 100644
--- a/examples/user-config/resources-binary-route.groovy
+++ b/examples/user-config/resource-file-binary-route.groovy
@@ -18,7 +18,7 @@
//
// To run this integrations use:
-// kamel run --resource resources-data.zip resources-binary-route.groovy -d camel-zipfile --dev
+// kamel run --resource resources-data.zip resource-file-binary-route.groovy -d camel-zipfile --dev
//
from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
diff --git a/examples/user-config/resources-route.groovy b/examples/user-config/resource-file-route.groovy
similarity index 83%
rename from examples/user-config/resources-route.groovy
rename to examples/user-config/resource-file-route.groovy
index 1085840..f39f4e5 100644
--- a/examples/user-config/resources-route.groovy
+++ b/examples/user-config/resource-file-route.groovy
@@ -18,8 +18,8 @@
//
// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
+// kamel run --resource file:resources-data.txt resource-file-route.groovy --dev
//
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/examples/user-config/secret-route.groovy b/examples/user-config/resource-secret-route.groovy
similarity index 81%
rename from examples/user-config/secret-route.groovy
rename to examples/user-config/resource-secret-route.groovy
index 7027b84..b46bb49 100644
--- a/examples/user-config/secret-route.groovy
+++ b/examples/user-config/resource-secret-route.groovy
@@ -18,13 +18,10 @@
//
// To run this integrations use:
-//
+//
// kubectl create secret generic my-sec --from-literal=my-secret-key="very top secret"
-// kamel run --config secret:my-sec secret-route.groovy --dev
+// kamel run --resource secret:my-sec resource-secret-route.groovy --dev
//
-from('timer:secret')
- .routeId('secret')
- .setBody()
- .simple("resource:classpath:my-secret-key")
- .log('secret content is: ${body}')
+from('file:/etc/camel/data/secrets/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
+ .log('resource file content is: ${body}')
[camel-k] 19/20: feat(cmd/run): warn when using path on --config
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 4465e1a8bd6fb6e036bf79b19c8d84a2db890208
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jun 7 14:44:59 2021 +0200
feat(cmd/run): warn when using path on --config
Ref #2003
---
docs/modules/ROOT/pages/cli/modeline.adoc | 4 ++--
pkg/cmd/run_help.go | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc
index e4daff5..ac1b734 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 a runtime configuration from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key])_
+|Add a runtime configuration from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key]_)
|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 runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key][@path])_
+|Add a runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key][@path]_)
|trait
|Configure a trait, e.g. `trait=service.enabled=false`
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index d117bf8..0fe8ee1 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -220,6 +220,10 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
// ApplyConfigOption will set the proper --config option behavior to the IntegrationSpec
func ApplyConfigOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
+ // A config option cannot specify destination path
+ if config.DestinationPath() != "" {
+ return fmt.Errorf("cannot specify a destination path for this option type")
+ }
return applyOption(config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeConfig)
}
[camel-k] 18/20: doc(example): configmap/secret key selection
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 18f34ac4573c1870d10df6dacf63e668de74cb4d
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jun 7 12:41:39 2021 +0200
doc(example): configmap/secret key selection
---
docs/modules/ROOT/pages/cli/modeline.adoc | 4 +--
.../user-config/config-secret-key-route.groovy | 30 ++++++++++++++++++++++
.../resource-configmap-key-location-route.groovy | 27 +++++++++++++++++++
3 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc
index 424a00b..e4daff5 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 a 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[/key])_
|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 runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[@path])_
+|Add a runtime resource from a Configmap, a Secret or a file (syntax: _[configmap\|secret\|file]:name[/key][@path])_
|trait
|Configure a trait, e.g. `trait=service.enabled=false`
diff --git a/examples/user-config/config-secret-key-route.groovy b/examples/user-config/config-secret-key-route.groovy
new file mode 100644
index 0000000..724a885
--- /dev/null
+++ b/examples/user-config/config-secret-key-route.groovy
@@ -0,0 +1,30 @@
+// 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:
+//
+// kubectl create secret generic my-sec-multi --from-literal=my-secret-key="very top secret" --from-literal=my-secret-key-2="even more secret"
+// kamel run --config secret:my-sec-multi/my-secret-key-2 config-secret-key-route.groovy --dev
+//
+
+from('timer:secret')
+ .routeId('secret')
+ .setBody()
+ .simple("resource:classpath:my-secret-key-2")
+ .log('secret content is: ${body}')
diff --git a/examples/user-config/resource-configmap-key-location-route.groovy b/examples/user-config/resource-configmap-key-location-route.groovy
new file mode 100644
index 0000000..70f39e6
--- /dev/null
+++ b/examples/user-config/resource-configmap-key-location-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:
+//
+// kubectl create configmap my-cm-multi --from-literal=my-configmap-key="configmap content" --from-literal=my-configmap-key-2="another content"
+// kamel run --resource configmap:my-cm-multi/my-configmap-key-2@/tmp/app/data resource-configmap-key-location-route.groovy --dev
+//
+
+from('file:/tmp/app/data/?fileName=my-configmap-key-2&noop=true&idempotent=false')
+ .log('resource file content is: ${body} consumed from ${header.CamelFileName}')