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/04/12 09:30:58 UTC

[camel-k] branch master updated (7d2df32 -> dad0c47)

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git.


    from 7d2df32  Updated CHANGELOG.md
     new 96d8b60  fix: Prevent Integration environment variables ordering randomization
     new dad0c47  chore: pass configuration variable with empty value

The 2 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:
 pkg/trait/container.go       |  4 ++--
 pkg/trait/cron.go            |  2 +-
 pkg/trait/deployment.go      |  4 +---
 pkg/trait/knative_service.go |  2 +-
 pkg/trait/trait.go           |  8 ++++----
 pkg/trait/trait_types.go     | 12 ++++++++----
 pkg/trait/util.go            | 42 ++++++++++++++++++++++++++----------------
 pkg/trait/util_test.go       | 10 ++++++----
 8 files changed, 49 insertions(+), 35 deletions(-)

[camel-k] 01/02: fix: Prevent Integration environment variables ordering randomization

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 96d8b60e948d093e741f55ad9e1473d0e194881b
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Apr 8 16:26:51 2021 +0200

    fix: Prevent Integration environment variables ordering randomization
---
 pkg/trait/container.go       |  4 ++--
 pkg/trait/cron.go            |  2 +-
 pkg/trait/deployment.go      |  4 +---
 pkg/trait/knative_service.go |  2 +-
 pkg/trait/trait.go           |  8 ++++----
 pkg/trait/trait_types.go     | 12 ++++++++----
 pkg/trait/util.go            | 32 +++++++++++++++++++-------------
 pkg/trait/util_test.go       | 10 ++++++----
 8 files changed, 42 insertions(+), 32 deletions(-)

diff --git a/pkg/trait/container.go b/pkg/trait/container.go
index 8f3a7d1..238a827 100644
--- a/pkg/trait/container.go
+++ b/pkg/trait/container.go
@@ -186,8 +186,8 @@ func (t *containerTrait) configureContainer(e *Environment) error {
 	}
 
 	// combine Environment of integration with platform, kit, integration
-	for key, value := range e.collectConfigurationPairs("env") {
-		envvar.SetVal(&container.Env, key, value)
+	for _, env := range e.collectConfigurationPairs("env") {
+		envvar.SetVal(&container.Env, env.Name, env.Value)
 	}
 
 	envvar.SetVal(&container.Env, "CAMEL_K_DIGEST", e.Integration.Status.Digest)
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 478fe12..e876128 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -266,7 +266,7 @@ func (t *cronTrait) getCronJobFor(e *Environment) *v1beta1.CronJob {
 
 	// Copy annotations from the integration resource
 	if e.Integration.Annotations != nil {
-		for k, v := range FilterTransferableAnnotations(e.Integration.Annotations) {
+		for k, v := range filterTransferableAnnotations(e.Integration.Annotations) {
 			annotations[k] = v
 		}
 	}
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 8fd05ad..11d24c6 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -60,9 +60,7 @@ func (t *deploymentTrait) Configure(e *Environment) (bool, error) {
 		return condition != nil && condition.Status == corev1.ConditionTrue, nil
 	}
 
-	//
 	// Don't deploy when a different strategy is needed (e.g. Knative, Cron)
-	//
 	strategy, err := e.DetermineControllerStrategy()
 	if err != nil {
 		e.Integration.Status.SetErrorCondition(
@@ -141,7 +139,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 	// create a copy to avoid sharing the underlying annotation map
 	annotations := make(map[string]string)
 	if e.Integration.Annotations != nil {
-		for k, v := range FilterTransferableAnnotations(e.Integration.Annotations) {
+		for k, v := range filterTransferableAnnotations(e.Integration.Annotations) {
 			annotations[k] = v
 		}
 	}
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index a6f5eda..a1e8ac1 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -269,7 +269,7 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
 
 	// Copy annotations from the integration resource
 	if e.Integration.Annotations != nil {
-		for k, v := range FilterTransferableAnnotations(e.Integration.Annotations) {
+		for k, v := range filterTransferableAnnotations(e.Integration.Annotations) {
 			annotations[k] = v
 		}
 	}
diff --git a/pkg/trait/trait.go b/pkg/trait/trait.go
index 28c388e..35ea851 100644
--- a/pkg/trait/trait.go
+++ b/pkg/trait/trait.go
@@ -20,17 +20,17 @@ package trait
 import (
 	"context"
 
+	"github.com/pkg/errors"
+
 	corev1 "k8s.io/api/core/v1"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/client"
 	"github.com/apache/camel-k/pkg/platform"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
-	"github.com/pkg/errors"
-	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 )
 
-// Apply --
 func Apply(ctx context.Context, c client.Client, integration *v1.Integration, kit *v1.IntegrationKit) (*Environment, error) {
 	environment, err := newEnvironment(ctx, c, integration, kit)
 	if err != nil {
@@ -77,7 +77,7 @@ func newEnvironment(ctx context.Context, c client.Client, integration *v1.Integr
 	}
 
 	if kit == nil {
-		kit, err = GetIntegrationKit(ctx, c, integration)
+		kit, err = getIntegrationKit(ctx, c, integration)
 		if err != nil {
 			return nil, err
 		}
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index a34c718..b3cd991 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -402,8 +402,8 @@ func (e *Environment) computeConfigMaps() []ctrl.Object {
 	// properties have the priority
 	userProperties := ""
 
-	for key, val := range e.collectConfigurationPairs("property") {
-		userProperties += fmt.Sprintf("%s=%s\n", key, val)
+	for _, prop := range e.collectConfigurationPairs("property") {
+		userProperties += fmt.Sprintf("%s=%s\n", prop.Name, prop.Value)
 	}
 
 	if userProperties != "" {
@@ -783,8 +783,12 @@ func (e *Environment) collectConfigurationValues(configurationType string) []str
 	return collectConfigurationValues(configurationType, e.Platform, e.IntegrationKit, e.Integration)
 }
 
-func (e *Environment) collectConfigurationPairs(configurationType string) map[string]string {
-	return CollectConfigurationPairs(configurationType, e.Platform, e.IntegrationKit, e.Integration)
+type variable struct {
+	Name, Value string
+}
+
+func (e *Environment) collectConfigurationPairs(configurationType string) []variable {
+	return collectConfigurationPairs(configurationType, e.Platform, e.IntegrationKit, e.Integration)
 }
 
 func (e *Environment) getIntegrationContainer() *corev1.Container {
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index debba1f..591f90b 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -28,7 +28,7 @@ import (
 	user "github.com/mitchellh/go-homedir"
 	"github.com/scylladb/go-set/strset"
 
-	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/client"
@@ -39,17 +39,13 @@ import (
 
 var exactVersionRegexp = regexp.MustCompile(`^(\d+)\.(\d+)\.([\w-.]+)$`)
 
-// GetIntegrationKit retrieves the kit set on the integration
-func GetIntegrationKit(ctx context.Context, c client.Client, integration *v1.Integration) (*v1.IntegrationKit, error) {
+// getIntegrationKit retrieves the kit set on the integration
+func getIntegrationKit(ctx context.Context, c client.Client, integration *v1.Integration) (*v1.IntegrationKit, error) {
 	if integration.Status.IntegrationKit == nil {
 		return nil, nil
 	}
 	kit := v1.NewIntegrationKit(integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name)
-	key := k8sclient.ObjectKey{
-		Namespace: integration.Status.IntegrationKit.Namespace,
-		Name:      integration.Status.IntegrationKit.Name,
-	}
-	err := c.Get(ctx, key, &kit)
+	err := c.Get(ctx, ctrl.ObjectKeyFromObject(&kit), &kit)
 	return &kit, err
 }
 
@@ -80,8 +76,8 @@ func collectConfigurationValues(configurationType string, configurable ...v1.Con
 	return s
 }
 
-func CollectConfigurationPairs(configurationType string, configurable ...v1.Configurable) map[string]string {
-	result := make(map[string]string)
+func collectConfigurationPairs(configurationType string, configurable ...v1.Configurable) []variable {
+	result := make([]variable, 0)
 
 	for _, c := range configurable {
 		c := c
@@ -103,7 +99,17 @@ func CollectConfigurationPairs(configurationType string, configurable ...v1.Conf
 					v := strings.TrimSpace(pair[1])
 
 					if len(k) > 0 && len(v) > 0 {
-						result[k] = v
+						ok := false
+						for i, variable := range result {
+							if variable.Name == k {
+								result[i].Value = v
+								ok = true
+								break
+							}
+						}
+						if !ok {
+							result = append(result, variable{Name: k, Value: v})
+						}
 					}
 				}
 			}
@@ -129,8 +135,8 @@ func keyValuePairArrayAsStringMap(pairs []string) (map[string]string, error) {
 	return m, nil
 }
 
-// FilterTransferableAnnotations returns a map containing annotations that are meaningful for being transferred to child resources.
-func FilterTransferableAnnotations(annotations map[string]string) map[string]string {
+// filterTransferableAnnotations returns a map containing annotations that are meaningful for being transferred to child resources.
+func filterTransferableAnnotations(annotations map[string]string) map[string]string {
 	res := make(map[string]string)
 	for k, v := range annotations {
 		if strings.HasPrefix(k, "kubectl.kubernetes.io") {
diff --git a/pkg/trait/util_test.go b/pkg/trait/util_test.go
index 9e9e350..87d70cf 100644
--- a/pkg/trait/util_test.go
+++ b/pkg/trait/util_test.go
@@ -94,8 +94,10 @@ func TestCollectConfigurationPairs(t *testing.T) {
 	e.Platform.ResyncStatusFullConfig()
 
 	pairs := e.collectConfigurationPairs("property")
-	assert.Equal(t, "integration", pairs["p1"])
-	assert.Equal(t, "kit", pairs["p2"])
-	assert.Equal(t, "platform", pairs["p3"])
-	assert.Equal(t, "integration", pairs["p4"])
+	assert.Equal(t, pairs, []variable{
+		{Name: "p1", Value: "integration"},
+		{Name: "p2", Value: "kit"},
+		{Name: "p3", Value: "platform"},
+		{Name: "p4", Value: "integration"},
+	})
 }

[camel-k] 02/02: chore: pass configuration variable with empty value

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit dad0c472164eb27074661154f600ed5c496d1f9f
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Apr 8 16:38:53 2021 +0200

    chore: pass configuration variable with empty value
---
 pkg/trait/util.go | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 591f90b..695b7ee 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -94,24 +94,28 @@ func collectConfigurationPairs(configurationType string, configurable ...v1.Conf
 		for _, entry := range entries {
 			if entry.Type == configurationType {
 				pair := strings.SplitN(entry.Value, "=", 2)
+				var k, v string
+				if len(pair) >= 1 {
+					k = strings.TrimSpace(pair[0])
+				}
 				if len(pair) == 2 {
-					k := strings.TrimSpace(pair[0])
-					v := strings.TrimSpace(pair[1])
-
-					if len(k) > 0 && len(v) > 0 {
-						ok := false
-						for i, variable := range result {
-							if variable.Name == k {
-								result[i].Value = v
-								ok = true
-								break
-							}
-						}
-						if !ok {
-							result = append(result, variable{Name: k, Value: v})
-						}
+					v = strings.TrimSpace(pair[1])
+				}
+				if k == "" {
+					continue
+				}
+
+				ok := false
+				for i, variable := range result {
+					if variable.Name == k {
+						result[i].Value = v
+						ok = true
+						break
 					}
 				}
+				if !ok {
+					result = append(result, variable{Name: k, Value: v})
+				}
 			}
 		}
 	}