Skip to content

Commit

Permalink
Fix validation failure issue for Knative service
Browse files Browse the repository at this point in the history
  • Loading branch information
savitaashture authored and tekton-robot committed Oct 18, 2021
1 parent ef99bbd commit b629238
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 9 additions & 5 deletions pkg/reconciler/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion pkg/reconciler/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down

0 comments on commit b629238

Please sign in to comment.