From 29eee26121e35b3cdc4c5b60fb139d05cbaa1b34 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Tue, 8 Dec 2020 14:52:03 +0100 Subject: [PATCH] fix: do not consider resource status when disabled (#7) * chore: preserve unknown fields Signed-off-by: Hector Fernandez * Do not consider resource status when disabled managedDispatcherImpl.RecordStatus only writes status if collection is enabled. Because of that if collection is disabled, resource map will always differ from the expected map of all clusters. Signed-off-by: Alena Varkockova Co-authored-by: Hector Fernandez --- pkg/controller/sync/status/status.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/controller/sync/status/status.go b/pkg/controller/sync/status/status.go index f0fb2e1d54..1b1018a69d 100644 --- a/pkg/controller/sync/status/status.go +++ b/pkg/controller/sync/status/status.go @@ -177,7 +177,7 @@ func (s *GenericFederatedStatus) update(generation int64, reason AggregateReason } } - clustersChanged := s.setClusters(collectedStatus.StatusMap, collectedResourceStatus.StatusMap) + clustersChanged := s.setClusters(collectedStatus.StatusMap, collectedResourceStatus.StatusMap, resourceStatusCollection) // Indicate that changes were propagated if either status.clusters // was changed or if existing resources were updated (which could @@ -196,8 +196,8 @@ func (s *GenericFederatedStatus) update(generation int64, reason AggregateReason // setClusters sets the status.clusters slice from propagation and resource status // maps. Returns a boolean indication of whether the status.clusters was // modified. -func (s *GenericFederatedStatus) setClusters(statusMap PropagationStatusMap, resourceStatusMap map[string]interface{}) bool { - if !s.clustersDiffer(statusMap, resourceStatusMap) { +func (s *GenericFederatedStatus) setClusters(statusMap PropagationStatusMap, resourceStatusMap map[string]interface{}, resourceStatusCollection bool) bool { + if !s.clustersDiffer(statusMap, resourceStatusMap, resourceStatusCollection) { return false } s.Clusters = []GenericClusterStatus{} @@ -214,9 +214,9 @@ func (s *GenericFederatedStatus) setClusters(statusMap PropagationStatusMap, res // clustersDiffer checks whether `status.clusters` differs from the // given status map. -func (s *GenericFederatedStatus) clustersDiffer(statusMap PropagationStatusMap, resourceStatusMap map[string]interface{}) bool { - if len(s.Clusters) != len(statusMap) || len(s.Clusters) != len(resourceStatusMap) { - klog.Info("Clusters differs from the size") +func (s *GenericFederatedStatus) clustersDiffer(statusMap PropagationStatusMap, resourceStatusMap map[string]interface{}, resourceStatusCollection bool) bool { + if len(s.Clusters) != len(statusMap) || (resourceStatusCollection && len(s.Clusters) != len(resourceStatusMap)) { + klog.Infof("Clusters differs from the size: %v, status: %v, resourceStatus: %v", s.Clusters, statusMap, resourceStatusMap) return true } for _, status := range s.Clusters {