diff --git a/pkg/reconciler/eventlistener/eventlistener.go b/pkg/reconciler/eventlistener/eventlistener.go index 766dc9130..aade03652 100644 --- a/pkg/reconciler/eventlistener/eventlistener.go +++ b/pkg/reconciler/eventlistener/eventlistener.go @@ -354,15 +354,19 @@ func (r *Reconciler) reconcileCustomObject(ctx context.Context, el *v1beta1.Even } } + // Preserve any externally added annotations + data.SetAnnotations(kmeta.UnionMaps(data.GetAnnotations(), existingCustomObject.GetAnnotations())) + if !equality.Semantic.DeepEqual(data.GetLabels(), existingCustomObject.GetLabels()) || !equality.Semantic.DeepEqual(data.GetAnnotations(), existingCustomObject.GetAnnotations()) || !equality.Semantic.DeepEqual(data.Object["spec"], existingCustomObject.Object["spec"]) { - data = data.DeepCopy() - data.SetLabels(existingCustomObject.GetLabels()) - data.SetAnnotations(existingCustomObject.GetAnnotations()) - data.Object["spec"] = existingCustomObject.Object["spec"] + // Don't modify informer copy + existingCustomObject = existingCustomObject.DeepCopy() + existingCustomObject.SetLabels(data.GetLabels()) + existingCustomObject.SetAnnotations(data.GetAnnotations()) + existingCustomObject.Object["spec"] = data.Object["spec"] - if updated, err := r.DynamicClientSet.Resource(gvr).Namespace(data.GetNamespace()).Update(ctx, data, metav1.UpdateOptions{}); err != nil { + if updated, err := r.DynamicClientSet.Resource(gvr).Namespace(data.GetNamespace()).Update(ctx, existingCustomObject, metav1.UpdateOptions{}); err != nil { logging.FromContext(ctx).Errorf("error updating to eventListener custom object: %v", err) return err } else if data.GetResourceVersion() != updated.GetResourceVersion() { diff --git a/pkg/reconciler/eventlistener/eventlistener_test.go b/pkg/reconciler/eventlistener/eventlistener_test.go index 258c7b39e..1ef54101b 100644 --- a/pkg/reconciler/eventlistener/eventlistener_test.go +++ b/pkg/reconciler/eventlistener/eventlistener_test.go @@ -400,7 +400,8 @@ func makeWithPod(ops ...func(d *duckv1.WithPod)) *duckv1.WithPod { OwnerReferences: []metav1.OwnerReference{ *ownerRefs, }, - Labels: generatedLabels, + Annotations: map[string]string{}, + Labels: generatedLabels, }, Spec: duckv1.WithPodSpec{ Template: duckv1.PodSpecable{ @@ -1379,6 +1380,7 @@ func TestReconcile(t *testing.T) { Namespaces: []*corev1.Namespace{namespaceResource}, EventListeners: []*v1beta1.EventListener{elWithCustomResourceForEnv}, ConfigMaps: []*corev1.ConfigMap{loggingConfigMap, observabilityConfigMap}, + WithPod: []*duckv1.WithPod{envForCustomResource}, }, endResources: test.Resources{ Namespaces: []*corev1.Namespace{namespaceResource}, @@ -1408,6 +1410,7 @@ func TestReconcile(t *testing.T) { Namespaces: []*corev1.Namespace{namespaceResource}, EventListeners: []*v1beta1.EventListener{elWithCustomResourceForArgs}, ConfigMaps: []*corev1.ConfigMap{loggingConfigMap, observabilityConfigMap}, + WithPod: []*duckv1.WithPod{argsForCustomResource}, }, endResources: test.Resources{ Namespaces: []*corev1.Namespace{namespaceResource}, @@ -1422,6 +1425,7 @@ func TestReconcile(t *testing.T) { Namespaces: []*corev1.Namespace{namespaceResource}, EventListeners: []*v1beta1.EventListener{elWithCustomResourceForImage}, ConfigMaps: []*corev1.ConfigMap{loggingConfigMap, observabilityConfigMap}, + WithPod: []*duckv1.WithPod{imageForCustomResource}, }, endResources: test.Resources{ Namespaces: []*corev1.Namespace{namespaceResource},