@@ -137,6 +137,33 @@ func removeClusterClassifierReports(ctx context.Context, c client.Client, cluste
137137 return nil
138138}
139139
140+ // ClassifierReports are collected from managed cluster to the management cluster.
141+ // When an ClassifierReport is collected from a managed cluster and created in the
142+ // management cluster, the label classifier.projectsveltos.io/cluster-name
143+ // is added. All ClassifierReport found in the management cluster with this
144+ // labels should be ignored as collected from other managed clusters.
145+ func shouldIgnore (cr * libsveltosv1beta1.ClassifierReport , isPullMode bool ) bool {
146+ if isPullMode {
147+ // Sveltos-applier copies the EventReports to the management cluster
148+ // and add this label to the EventReport
149+ return false
150+ }
151+
152+ if getAgentInMgmtCluster () {
153+ // If sveltos-agent is in the management cluster, EventReports
154+ // are directly generated by sveltos-agent here. So there is no
155+ // copy to ignore.
156+ return false
157+ }
158+
159+ if cr .Labels == nil {
160+ return false
161+ }
162+
163+ _ , ok := cr .Labels [libsveltosv1beta1 .ClassifierReportClusterNameLabel ]
164+ return ok
165+ }
166+
140167// Periodically collects ClassifierReports from each cluster.
141168// If sharding is used, it will collect only from clusters matching shard.
142169func collectClassifierReports (c client.Client , shardKey , capiOnboardAnnotation , version string , logger logr.Logger ) {
@@ -237,10 +264,7 @@ func collectClassifierReportsFromCluster(ctx context.Context, c client.Client,
237264 // ignore deleted ClassifierReport
238265 continue
239266 }
240- if cr .Spec .ClusterName != "" {
241- // if ClusterName is set, this is coming from a
242- // managed cluster. If management cluster is in turn
243- // managed by another cluster, do not pull those.
267+ if shouldIgnore (cr , isPullMode ) {
244268 continue
245269 }
246270 l := logger .WithValues ("classifierReport" , cr .Name )
0 commit comments