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 <[email protected]>
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)
 

Reply via email to