Skip to content

Commit

Permalink
chore(traits): remove mounting from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Aug 14, 2024
1 parent b451e60 commit e4e29ff
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 232 deletions.
21 changes: 0 additions & 21 deletions e2e/common/config/kamelet_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,6 @@ func TestKameletImplicitConfigDefaultUserProperty(t *testing.T) {
g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My Named Config message"))
})

t.Run("run test named config using labeled secret", func(t *testing.T) {
g.Expect(CreateTimerKamelet(t, ctx, ns, "iconfig06-timer-source")()).To(Succeed())

name := RandomizedSuffixName("iconfig-test-timer-source-int6")
secretName := "my-iconfig-int6-secret"

var secData = make(map[string]string)
secData["camel.kamelet.iconfig06-timer-source.mynamedconfig.message"] = "very top named secret message"
var labels = make(map[string]string)
labels["camel.apache.org/kamelet"] = "iconfig06-timer-source"
labels["camel.apache.org/kamelet.configuration"] = "mynamedconfig"
g.Expect(CreatePlainTextSecretWithLabels(t, ctx, ns, secretName, secData, labels)).To(Succeed())
g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(Not(BeNil()))

g.Expect(KamelRun(t, ctx, ns, "files/TimerKameletIntegrationNamedConfiguration06.java",
"-p", "camel.kamelet.iconfig06-timer-source.message='Default message 06'",
"--name", name).Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top named secret message"))
})

t.Run("run test named config using mounted secret", func(t *testing.T) {
g.Expect(CreateTimerKamelet(t, ctx, ns, "iconfig07-timer-source")()).To(Succeed())

Expand Down
23 changes: 0 additions & 23 deletions e2e/common/config/pipe_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,6 @@ func TestPipeConfig(t *testing.T) {
g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeLogger"))
})

t.Run("run test implicit default config using labeled secret", func(t *testing.T) {
name := RandomizedSuffixName("my-pipe-with-default-implicit-secret")
secretName := "my-pipe-default-implicit-secret"

var secData = make(map[string]string)
secData["camel.kamelet.my-pipe-timer-source.message"] = "My pipe secret message"
var labels = make(map[string]string)
labels["camel.apache.org/kamelet"] = "my-pipe-timer-source"
g.Expect(CreatePlainTextSecretWithLabels(t, ctx, ns, secretName, secData, labels)).To(Succeed())

g.Expect(KamelBind(t, ctx, ns,
"my-pipe-timer-source",
"my-pipe-log-sink",
"-p", "sink.loggerName=myDefaultLogger",
"--name", name,
).Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe secret message"))
g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myDefaultLogger"))

g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed())
})

t.Run("run test implicit default config using mounted secret", func(t *testing.T) {
name := RandomizedSuffixName("my-pipe-with-default-implicit-secret")
secretName := "my-pipe-default-implicit-secret"
Expand Down
15 changes: 10 additions & 5 deletions pkg/trait/knative_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,22 @@ func TestKnativeService(t *testing.T) {
Language: v1.LanguageJavaScript,
},
},
Configuration: []v1.ConfigurationSpec{
{Type: "configmap", Value: "my-cm"},
{Type: "secret", Value: "my-secret"},
{Type: "property", Value: "my-property=my-property-value"},
},
Traits: v1.Traits{
KnativeService: &traitv1.KnativeServiceTrait{
Trait: traitv1.Trait{
Enabled: ptr.To(true),
},
},
Camel: &traitv1.CamelTrait{
Properties: []string{
"my-property=my-property-value",
},
},
Mount: &traitv1.MountTrait{
Configs: []string{
"configmap:my-cm", "secret:my-secret",
},
},
},
},
},
Expand Down
74 changes: 0 additions & 74 deletions pkg/trait/trait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package trait

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -185,79 +184,6 @@ func TestTraitHierarchyDecode(t *testing.T) {
assert.Equal(t, 15, *kns.Target)
}

func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
env := Environment{
Resources: kubernetes.NewCollection(),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: TestDeploymentName,
Namespace: "ns",
},
Spec: v1.IntegrationSpec{
Configuration: []v1.ConfigurationSpec{
{
Type: "property",
Value: "a=b",
},
{
Type: "configmap",
Value: "test-configmap",
},
{
Type: "secret",
Value: "test-secret",
},
{
Type: "volume",
Value: "testvolume:/foo/bar",
},
{
Type: "volume",
Value: "an-invalid-volume-spec",
},
},
},
},
}

vols := make([]corev1.Volume, 0)
mnts := make([]corev1.VolumeMount, 0)

env.configureVolumesAndMounts(&vols, &mnts)

assert.Len(t, vols, 3)
assert.Len(t, mnts, 3)

v := findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == "test-configmap" })
assert.NotNil(t, v)
assert.NotNil(t, v.VolumeSource.ConfigMap)
assert.NotNil(t, v.VolumeSource.ConfigMap.LocalObjectReference)
assert.Equal(t, "test-configmap", v.VolumeSource.ConfigMap.LocalObjectReference.Name)

m := findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "test-configmap" })
assert.NotNil(t, m)
assert.Equal(t, filepath.Join(camel.ConfigConfigmapsMountPath, "test-configmap"), m.MountPath)

v = findVolume(vols, func(v corev1.Volume) bool { return v.Name == "test-secret" })
assert.NotNil(t, v)
assert.NotNil(t, v.Secret)
assert.Equal(t, "test-secret", v.Secret.SecretName)

m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "test-secret" })
assert.NotNil(t, m)
assert.Equal(t, filepath.Join(camel.ConfigSecretsMountPath, "test-secret"), m.MountPath)

v = findVolume(vols, func(v corev1.Volume) bool { return v.Name == "testvolume-data" })
assert.NotNil(t, v)
assert.NotNil(t, v.VolumeSource)
assert.NotNil(t, v.VolumeSource.PersistentVolumeClaim)
assert.Equal(t, "testvolume", v.VolumeSource.PersistentVolumeClaim.ClaimName)

m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == "testvolume-data" })
assert.NotNil(t, m)
assert.Equal(t, "/foo/bar", m.MountPath)
}

func TestConfigureVolumesAndMountsSources(t *testing.T) {
env := Environment{
Resources: kubernetes.NewCollection(),
Expand Down
50 changes: 0 additions & 50 deletions pkg/trait/trait_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,48 +569,6 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
}
})
}

// Deprecated - should use mount trait
// User provided configmaps
for _, configmaps := range e.collectConfigurations("configmap") {
refName := kubernetes.SanitizeLabel(configmaps["value"])
mountPath := getMountPoint(configmaps["value"], configmaps["resourceMountPoint"], configmapStorageType, configmaps["resourceType"])
vol := getVolume(refName, configmapStorageType, configmaps["value"], configmaps["resourceKey"], configmaps["resourceKey"])
mnt := getMount(refName, mountPath, "", true)

*vols = append(*vols, *vol)
*mnts = append(*mnts, *mnt)
}

// Deprecated - should use mount trait
// User provided secrets
for _, secret := range e.collectConfigurations("secret") {
refName := kubernetes.SanitizeLabel(secret["value"])
mountPath := getMountPoint(secret["value"], secret["resourceMountPoint"], secretStorageType, secret["resourceType"])
vol := getVolume(refName, secretStorageType, secret["value"], secret["resourceKey"], secret["resourceKey"])
mnt := getMount(refName, mountPath, "", true)

*vols = append(*vols, *vol)
*mnts = append(*mnts, *mnt)
}
// Deprecated - should use mount trait
// User provided volumes
for _, volumeConfig := range e.collectConfigurationValues("volume") {
configParts := strings.Split(volumeConfig, ":")

if len(configParts) != 2 {
continue
}

pvcName := configParts[0]
mountPath := configParts[1]
volumeName := pvcName + "-data"

vol := getVolume(volumeName, pvcStorageType, pvcName, "", "")
mnt := getMount(volumeName, mountPath, "", false)
*vols = append(*vols, *vol)
*mnts = append(*mnts, *mnt)
}
}

func getVolume(volName, storageType, storageName, filterKey, filterValue string) *corev1.Volume {
Expand Down Expand Up @@ -692,10 +650,6 @@ func getMountPoint(resourceName string, mountPoint string, storagetype, resource
return filepath.Join(defaultMountPoint, resourceName)
}

func (e *Environment) collectConfigurationValues(configurationType string) []string {
return collectConfigurationValues(configurationType, e.Platform, e.IntegrationKit, e.Integration)
}

type variable struct {
Name, Value string
}
Expand All @@ -704,10 +658,6 @@ 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) GetIntegrationContainerName() string {
containerName := defaultContainerName

Expand Down
5 changes: 0 additions & 5 deletions pkg/trait/trait_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ func TestCollectConfigurationValues(t *testing.T) {
},
}
e.Platform.ResyncStatusFullConfig()

assert.Contains(t, e.collectConfigurationValues("configmap"), "my-cm-integration")
assert.Contains(t, e.collectConfigurationValues("secret"), "my-secret-platform")
assert.Contains(t, e.collectConfigurationValues("property"), "my-p-kit")
assert.Contains(t, e.collectConfigurationValues("env"), "my-env-integration")
}

func TestCollectConfigurationPairs(t *testing.T) {
Expand Down
57 changes: 3 additions & 54 deletions pkg/trait/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"fmt"
"reflect"
"regexp"
"sort"
"strings"

ctrl "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -75,56 +74,6 @@ func getIntegrationKit(ctx context.Context, c client.Client, integration *v1.Int
return kit, err
}

func collectConfigurationValues(configurationType string, configurable ...v1.Configurable) []string {
result := sets.NewSet()

for _, c := range configurable {
if c == nil || reflect.ValueOf(c).IsNil() {
continue
}

entries := c.Configurations()
if entries == nil {
continue
}

for _, entry := range entries {
if entry.Type == configurationType {
result.Add(entry.Value)
}
}
}

s := result.List()
sort.Strings(s)
return s
}

func collectConfigurations(configurationType string, configurable ...v1.Configurable) []map[string]string {
var result []map[string]string

for _, c := range configurable {
if c == nil || reflect.ValueOf(c).IsNil() {
continue
}

entries := c.Configurations()
if entries == nil {
continue
}

for _, entry := range entries {
if entry.Type == configurationType {
item := make(map[string]string)
item["value"] = entry.Value
result = append(result, item)
}
}
}

return result
}

func collectConfigurationPairs(configurationType string, configurable ...v1.Configurable) []variable {
result := make([]variable, 0)

Expand Down Expand Up @@ -524,7 +473,7 @@ func NewSpecTraitsOptionsForIntegrationAndPlatform(c client.Client, i *v1.Integr
}

// Deprecated: to remove when we remove support for traits annotations.
// IMPORTANT: when we remove this we'll need to remove the cli from the func,
// IMPORTANT: when we remove this we'll need to remove the client.Client from the func,
// which will bring to more cascade removal. It had to be introduced to support the deprecated feature
// in a properly manner (ie, comparing the spec.traits with annotations in a proper way).
return newTraitsOptions(c, options, i.ObjectMeta.Annotations)
Expand All @@ -537,7 +486,7 @@ func NewSpecTraitsOptionsForIntegration(c client.Client, i *v1.Integration) (Opt
}

// Deprecated: to remove when we remove support for traits annotations.
// IMPORTANT: when we remove this we'll need to remove the cli from the func,
// IMPORTANT: when we remove this we'll need to remove the client.Client from the func,
// which will bring to more cascade removal. It had to be introduced to support the deprecated feature
// in a properly manner (ie, comparing the spec.traits with annotations in a proper way).
return newTraitsOptions(c, m1, i.ObjectMeta.Annotations)
Expand All @@ -550,7 +499,7 @@ func newTraitsOptionsForIntegrationKit(c client.Client, i *v1.IntegrationKit, tr
}

// Deprecated: to remove when we remove support for traits annotations.
// IMPORTANT: when we remove this we'll need to remove the cli from the func,
// IMPORTANT: when we remove this we'll need to remove the client.Client from the func,
// which will bring to more cascade removal. It had to be introduced to support the deprecated feature
// in a properly manner (ie, comparing the spec.traits with annotations in a proper way).
return newTraitsOptions(c, m1, i.ObjectMeta.Annotations)
Expand Down

0 comments on commit e4e29ff

Please sign in to comment.