@@ -354,7 +354,7 @@ func isClassifierAlreadyRegistered(classifiers []string, classifierKey string) b
354354
355355// rebuildRegistrations rebuilds internal structures to identify Classifiers managing
356356// labels and Classifiers currently just registered but not managing.
357- // Reads from ClassifierReport.Status (the authoritative post-migration location) .
357+ // Reads from ClassifierReport.Status and ManagementClusterClassifierReport.Status .
358358func (m * instance ) rebuildRegistrations (ctx context.Context , c client.Client ) error {
359359 // Lock here
360360 m .chartMux .Lock ()
@@ -389,6 +389,47 @@ func (m *instance) rebuildRegistrations(ctx context.Context, c client.Client) er
389389 m .addManagedLabelsInCluster (classifierKey , clusterKey , unManagedKeys )
390390 }
391391
392+ // Also rebuild registrations from ManagementClusterClassifierReports.
393+ // ManagementClusterClassifier names are stored with the "mgmt:" prefix to avoid
394+ // collision with regular Classifier names.
395+ if err := m .rebuildMgmtClassifierRegistrations (ctx , c ); err != nil {
396+ return err
397+ }
398+
399+ return nil
400+ }
401+
402+ // rebuildMgmtClassifierRegistrations reads ManagementClusterClassifierReports and registers
403+ // each ManagementClusterClassifier's label ownership using the "mgmt:" prefix.
404+ func (m * instance ) rebuildMgmtClassifierRegistrations (ctx context.Context , c client.Client ) error {
405+ mgmtReportList := & libsveltosv1beta1.ManagementClusterClassifierReportList {}
406+ if err := c .List (ctx , mgmtReportList ); err != nil {
407+ return err
408+ }
409+
410+ // First pass: managed labels (primary managers).
411+ for i := range mgmtReportList .Items {
412+ report := & mgmtReportList .Items [i ]
413+ if report .Spec .ClusterNamespace == "" || len (report .Status .ManagedLabels ) == 0 {
414+ continue
415+ }
416+ clusterKey := m .getClusterKey (report .Spec .ClusterNamespace , report .Spec .ClusterName , report .Spec .ClusterType )
417+ classifierKey := m .getClassifierKey ("mgmt:" + report .Spec .ClassifierName )
418+ m .addManagedLabelsInCluster (classifierKey , clusterKey , report .Status .ManagedLabels )
419+ }
420+
421+ // Second pass: unmanaged labels (waiting to take over).
422+ for i := range mgmtReportList .Items {
423+ report := & mgmtReportList .Items [i ]
424+ if report .Spec .ClusterNamespace == "" || len (report .Status .UnManagedLabels ) == 0 {
425+ continue
426+ }
427+ clusterKey := m .getClusterKey (report .Spec .ClusterNamespace , report .Spec .ClusterName , report .Spec .ClusterType )
428+ classifierKey := m .getClassifierKey ("mgmt:" + report .Spec .ClassifierName )
429+ unManagedKeys := m .buildSliceOfUnManagedLabels (report .Status .UnManagedLabels )
430+ m .addManagedLabelsInCluster (classifierKey , clusterKey , unManagedKeys )
431+ }
432+
392433 return nil
393434}
394435
0 commit comments