You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2021/04/08 08:43:11 UTC

[camel-k] branch release-1.3.x updated (4c84252 -> 25fe071)

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

nferraro pushed a change to branch release-1.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git.


    from 4c84252  Add helm chart for 1.3.2
     new b070146  fix: Add bindings.knative.dev/include label to SinkBinding sources
     new afe8f19  fix: SinkBinding should be managed when the Integration is running
     new 25fe071  fix: Remove deep derivative comparison from deployer

The 3 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/deployer.go             | 28 +++++++++++-----------------
 pkg/trait/knative.go              | 20 +++++++++++++++++++-
 pkg/util/kubernetes/collection.go |  2 --
 pkg/util/patch/patch.go           | 39 ---------------------------------------
 4 files changed, 30 insertions(+), 59 deletions(-)

[camel-k] 02/03: fix: SinkBinding should be managed when the Integration is running

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

nferraro pushed a commit to branch release-1.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit afe8f191dd97e8f3fabbc31e6f580099cd634fbe
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Apr 2 16:40:46 2021 +0200

    fix: SinkBinding should be managed when the Integration is running
---
 pkg/trait/knative.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index 0dcfa2a..923c9f3 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -505,7 +505,7 @@ func (t *knativeTrait) configureSinkBinding(e *Environment, env *knativeapi.Came
 		e.ApplicationProperties["camel.k.customizer.sinkbinding.kind"] = ref.Kind
 		e.ApplicationProperties["camel.k.customizer.sinkbinding.api-version"] = ref.APIVersion
 
-		if e.IntegrationInPhase(v1.IntegrationPhaseDeploying) {
+		if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) {
 			e.PostStepProcessors = append(e.PostStepProcessors, func(e *Environment) error {
 				sinkBindingInjected := false
 				e.Resources.Visit(func(object runtime.Object) {

[camel-k] 01/03: fix: Add bindings.knative.dev/include label to SinkBinding sources

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

nferraro pushed a commit to branch release-1.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit b070146701dda17590388372acfcf038fb8c0c16
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Apr 2 16:20:12 2021 +0200

    fix: Add bindings.knative.dev/include label to SinkBinding sources
---
 pkg/trait/knative.go              | 18 ++++++++++++++++++
 pkg/util/kubernetes/collection.go |  2 --
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index dbef97d..0dcfa2a 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -34,6 +34,7 @@ import (
 	"github.com/pkg/errors"
 	corev1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	eventing "knative.dev/eventing/pkg/apis/eventing/v1beta1"
 	serving "knative.dev/serving/pkg/apis/serving/v1"
@@ -535,7 +536,24 @@ func (t *knativeTrait) configureSinkBinding(e *Environment, env *knativeapi.Came
 						Name:       ref.Name,
 						APIVersion: ref.APIVersion,
 					}
+
+					// Add the SinkBinding in first position, to make sure it is created
+					// before the reference source, so that the SinkBinding webhook has
+					// all the information to perform injection.
 					e.Resources.AddFirst(knativeutil.CreateSinkBinding(source, target))
+
+					// Make sure the Eventing webhook will select the source resource,
+					// in order to inject the sink information.
+					// This is necessary for Knative environments, that are configured
+					// with SINK_BINDING_SELECTION_MODE=inclusion.
+					// See:
+					// - https://knative.dev/v0.20-docs/eventing/sources/sinkbinding/
+					// - https://github.com/knative/operator/blob/c60e62bb86ff318c44d1520927d2182659cfdeb5/docs/configuration.md#specsinkbindingselectionmode
+					c, ok := controller.(metav1.Object)
+					if !ok {
+						return fmt.Errorf("cannot set sink binding selection mode annotation on %v", controller)
+					}
+					c.GetLabels()["bindings.knative.dev/include"] = "true"
 				}
 				return nil
 			})
diff --git a/pkg/util/kubernetes/collection.go b/pkg/util/kubernetes/collection.go
index 4643e2f..1292803 100644
--- a/pkg/util/kubernetes/collection.go
+++ b/pkg/util/kubernetes/collection.go
@@ -474,7 +474,6 @@ func (c *Collection) Remove(selector func(runtime.Object) bool) runtime.Object {
 	return nil
 }
 
-// VisitServiceMonitor ---
 func (c *Collection) VisitServiceMonitor(visitor func(*monitoringv1.ServiceMonitor)) {
 	c.Visit(func(res runtime.Object) {
 		if conv, ok := res.(*monitoringv1.ServiceMonitor); ok {
@@ -483,7 +482,6 @@ func (c *Collection) VisitServiceMonitor(visitor func(*monitoringv1.ServiceMonit
 	})
 }
 
-// GetServiceMonitor ---
 func (c *Collection) GetServiceMonitor(filter func(*monitoringv1.ServiceMonitor) bool) *monitoringv1.ServiceMonitor {
 	var retValue *monitoringv1.ServiceMonitor
 	c.VisitServiceMonitor(func(serviceMonitor *monitoringv1.ServiceMonitor) {

[camel-k] 03/03: fix: Remove deep derivative comparison from deployer

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

nferraro pushed a commit to branch release-1.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 25fe071211a1d552f7bd95c5fa2fcc753077a6fc
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Apr 6 15:12:08 2021 +0200

    fix: Remove deep derivative comparison from deployer
---
 pkg/trait/deployer.go   | 28 +++++++++++-----------------
 pkg/util/patch/patch.go | 39 ---------------------------------------
 2 files changed, 11 insertions(+), 56 deletions(-)

diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index e21b0bd..6c705f3 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -94,23 +94,17 @@ func (t *deployerTrait) Apply(e *Environment) error {
 					return err
 				}
 
-				// If both objects have "ObjectMeta" and "Spec" fields and they contain all the expected fields
-				// (plus optional others), then avoid patching.
-				if !patch.ObjectMetaEqualDeepDerivative(object, resource) ||
-					!patch.SpecEqualDeepDerivative(object, resource) {
-
-					p, err := patch.PositiveMergePatch(object, resource)
-					if err != nil {
-						return err
-					} else if len(p) == 0 {
-						// Avoid triggering a patch request for nothing
-						continue
-					}
-
-					err = env.Client.Patch(env.C, resource, client.RawPatch(types.MergePatchType, p))
-					if err != nil {
-						return errors.Wrap(err, "error during patch resource")
-					}
+				p, err := patch.PositiveMergePatch(object, resource)
+				if err != nil {
+					return err
+				} else if len(p) == 0 {
+					// Avoid triggering a patch request for nothing
+					continue
+				}
+
+				err = env.Client.Patch(env.C, resource, client.RawPatch(types.MergePatchType, p))
+				if err != nil {
+					return errors.Wrap(err, "error during patch resource")
 				}
 			}
 			return nil
diff --git a/pkg/util/patch/patch.go b/pkg/util/patch/patch.go
index e2c54b1..e0ae632 100644
--- a/pkg/util/patch/patch.go
+++ b/pkg/util/patch/patch.go
@@ -21,7 +21,6 @@ import (
 	"reflect"
 
 	jsonpatch "github.com/evanphx/json-patch"
-	"k8s.io/apimachinery/pkg/api/equality"
 
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/util/json"
@@ -90,41 +89,3 @@ func removeNilValues(v reflect.Value, parent reflect.Value) {
 		}
 	}
 }
-
-func ObjectMetaEqualDeepDerivative(object runtime.Object, expected runtime.Object) (res bool) {
-	defer func() {
-		if r := recover(); r != nil {
-			res = false
-		}
-	}()
-
-	if expected == nil {
-		return true
-	} else if object == nil {
-		return false
-	}
-
-	objectMeta := reflect.ValueOf(object).Elem().FieldByName("ObjectMeta").Interface()
-	expectedMeta := reflect.ValueOf(expected).Elem().FieldByName("ObjectMeta").Interface()
-
-	return equality.Semantic.DeepDerivative(expectedMeta, objectMeta)
-}
-
-func SpecEqualDeepDerivative(object runtime.Object, expected runtime.Object) (res bool) {
-	defer func() {
-		if r := recover(); r != nil {
-			res = false
-		}
-	}()
-
-	if expected == nil {
-		return true
-	} else if object == nil {
-		return false
-	}
-
-	objectSpec := reflect.ValueOf(object).Elem().FieldByName("Spec").Interface()
-	expectedSpec := reflect.ValueOf(expected).Elem().FieldByName("Spec").Interface()
-
-	return equality.Semantic.DeepDerivative(expectedSpec, objectSpec)
-}