Skip to content

Commit

Permalink
chore(cmd/run): single resource dir and cli syntax description
Browse files Browse the repository at this point in the history
Ref #2003
  • Loading branch information
squakez authored and astefanutti committed Jun 16, 2021
1 parent 4465e1a commit 73339cf
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/cli/modeline.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion e2e/common/config/files/resource-configmap-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion e2e/common/config/files/resource-file-binary-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion e2e/common/config/files/resource-file-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion e2e/common/config/files/resource-secret-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion examples/user-config/resource-configmap-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion examples/user-config/resource-file-binary-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion examples/user-config/resource-file-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion examples/user-config/resource-secret-route.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
4 changes: 2 additions & 2 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/trait/jvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/trait/trait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
11 changes: 4 additions & 7 deletions pkg/trait/trait_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 73339cf

Please sign in to comment.