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
The following commit(s) were added to refs/heads/master by this push:
new a656a8b fix: Consider ObjectMeta field for deep derivative comparison
before patching
a656a8b is described below
commit a656a8b3eb369cabe4f2151fd3edd597fd15f8a8
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Wed Feb 17 11:54:52 2021 +0100
fix: Consider ObjectMeta field for deep derivative comparison before
patching
---
pkg/trait/deployer.go | 7 ++++---
pkg/util/patch/patch.go | 19 +++++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index cc78537..062b91d 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -95,9 +95,10 @@ func (t *deployerTrait) Apply(e *Environment) error {
return err
}
- if !patch.SpecEqualDeepDerivative(object,
resource) {
- // If both objects have a "Spec" field
and it contains all expected fields
- // (plus optional others), then avoid
patching
+ // 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 {
diff --git a/pkg/util/patch/patch.go b/pkg/util/patch/patch.go
index 67c2813..e2c54b1 100644
--- a/pkg/util/patch/patch.go
+++ b/pkg/util/patch/patch.go
@@ -91,6 +91,25 @@ 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 {