@@ -130,8 +130,7 @@ func collectResourceSummariesFromCluster(ctx context.Context, c client.Client, c
130130 if getAgentInMgmtCluster () {
131131 listOptions = []client.ListOption {
132132 client.MatchingLabels {
133- sveltos_upgrade .ClusterNameLabel : cluster .Name ,
134- libsveltosv1beta1 .ClusterSummaryNamespaceLabel : cluster .Namespace ,
133+ sveltos_upgrade .ClusterNameLabel : cluster .Name ,
135134 },
136135 }
137136 }
@@ -147,6 +146,15 @@ func collectResourceSummariesFromCluster(ctx context.Context, c client.Client, c
147146
148147 for i := range rsList .Items {
149148 rs := & rsList .Items [i ]
149+
150+ ns , ok := getClusterSummaryNamespaceFromResourceSummary (rs , logger )
151+ if ! ok {
152+ continue
153+ }
154+ if ns != cluster .Namespace {
155+ continue
156+ }
157+
150158 if ! rs .DeletionTimestamp .IsZero () {
151159 // ignore deleted resourceSummary
152160 continue
@@ -178,26 +186,78 @@ func isResourceSummaryInstalled(ctx context.Context, c client.Client) (bool, err
178186 return true , nil
179187}
180188
189+ func getClusterSummaryNameFromResourceSummary (rs * libsveltosv1beta1.ResourceSummary , logger logr.Logger ,
190+ ) (string , bool ) {
191+
192+ // ResourceSummary previously used labels for ClusterSummary Namespace and Name.
193+ // This information is now stored as annotations. For backward compatibility, we'll
194+ // check annotations first, then labels.
195+
196+ var clusterSummaryName string
197+ ok := false
198+
199+ if rs .Annotations != nil {
200+ clusterSummaryName , ok = rs .Annotations [libsveltosv1beta1 .ClusterSummaryNameAnnotation ]
201+ }
202+
203+ if ! ok { // If not found in annotations, try labels
204+ if rs .Labels != nil {
205+ clusterSummaryName , ok = rs .Labels [libsveltosv1beta1 .ClusterSummaryNameLabel ]
206+ }
207+ }
208+
209+ if ! ok { // If still not found after checking both
210+ logger .V (logs .LogInfo ).Info ("neither ClusterSummary name annotation nor label are set. Cannot process it." )
211+ return "" , false
212+ }
213+
214+ return clusterSummaryName , true
215+ }
216+
217+ func getClusterSummaryNamespaceFromResourceSummary (rs * libsveltosv1beta1.ResourceSummary , logger logr.Logger ,
218+ ) (string , bool ) {
219+
220+ // ResourceSummary previously used labels for ClusterSummary Namespace and Name.
221+ // This information is now stored as annotations. For backward compatibility, we'll
222+ // check annotations first, then labels.
223+
224+ // Get ClusterSummary Namespace
225+ var clusterSummaryNamespace string
226+ ok := false
227+
228+ if rs .Annotations != nil {
229+ clusterSummaryNamespace , ok = rs .Annotations [libsveltosv1beta1 .ClusterSummaryNamespaceAnnotation ]
230+ }
231+
232+ if ! ok { // If not found in annotations, try labels
233+ if rs .Labels != nil {
234+ clusterSummaryNamespace , ok = rs .Labels [libsveltosv1beta1 .ClusterSummaryNamespaceLabel ]
235+ }
236+ }
237+
238+ if ! ok { // If still not found after checking both
239+ logger .V (logs .LogInfo ).Info ("neither ClusterSummary namespace annotation nor label are set. Cannot process it." )
240+ return "" , false
241+ }
242+
243+ return clusterSummaryNamespace , true
244+ }
245+
181246// clusterClient points to the cluster where ResourceSummary is. That can be
182247// the management cluster if running in agentless mode or the managed cluster
183248// otherwise
184249func processResourceSummary (ctx context.Context , clusterClient client.Client ,
185250 rs * libsveltosv1beta1.ResourceSummary , logger logr.Logger ) error {
186251
187- if rs .Labels == nil {
188- logger .V (logs .LogInfo ).Info ("labels not set. Cannot process it" )
189- return nil
190- }
191-
192252 // Get ClusterSummary
193- clusterSummaryName , ok := rs . Labels [ libsveltosv1beta1 . ClusterSummaryNameLabel ]
253+ clusterSummaryName , ok := getClusterSummaryNameFromResourceSummary ( rs , logger )
194254 if ! ok {
195255 logger .V (logs .LogInfo ).Info ("clusterSummary name label not set. Cannot process it" )
196256 return nil
197257 }
198258
199259 var clusterSummaryNamespace string
200- clusterSummaryNamespace , ok = rs . Labels [ libsveltosv1beta1 . ClusterSummaryNamespaceLabel ]
260+ clusterSummaryNamespace , ok = getClusterSummaryNamespaceFromResourceSummary ( rs , logger )
201261 if ! ok {
202262 logger .V (logs .LogInfo ).Info ("clusterSummary namespace label not set. Cannot process it" )
203263 return nil
0 commit comments