@@ -564,6 +564,22 @@ func updateClusterSummaries(ctx context.Context, c client.Client, profileScope *
564
564
continue
565
565
}
566
566
567
+ if maxUpdate != 0 {
568
+ // maxUpdate is set. Skip paused clusters (which would not be updated anyhow as set to paused)
569
+ // and try to pcik any non paused cluster
570
+ isClusterPaused , err := clusterproxy .IsClusterPaused (ctx , c , cluster .Namespace ,
571
+ cluster .Name , clusterproxy .GetClusterType (& cluster ))
572
+ if err != nil {
573
+ logger .V (logs .LogDebug ).Info (fmt .Sprintf ("failed to verify if cluster is paused: %v" , err ))
574
+ return err
575
+ }
576
+ if isClusterPaused {
577
+ // No need to set skippedUpdated. Profile will react to a cluster switching from paused to unpaused
578
+ logger .V (logs .LogDebug ).Info ("Cluster is paused and maxUpdate is set. Ignore this cluster." )
579
+ continue
580
+ }
581
+ }
582
+
567
583
// if maxUpdate is set no more than maxUpdate clusters can be updated in parallel by ClusterProfile
568
584
if maxUpdate != 0 && ! updatingClusters .Has (& cluster ) && int32 (updatingClusters .Len ()) >= maxUpdate {
569
585
logger .V (logs .LogDebug ).Info (fmt .Sprintf ("Already %d being updating" , updatingClusters .Len ()))
@@ -575,27 +591,9 @@ func updateClusterSummaries(ctx context.Context, c client.Client, profileScope *
575
591
// If a Cluster exists and it is a match, ClusterSummary is created (and ClusterSummary.Spec kept in sync if mode is
576
592
// continuous).
577
593
// ClusterSummary won't program cluster in paused state.
578
- _ , err = getClusterSummary (ctx , c , profileScope .GetKind (), profileScope .Name (), cluster .Namespace ,
579
- cluster .Name , clusterproxy .GetClusterType (& cluster ))
594
+ err = patchClusterSummary (ctx , c , profileScope , & cluster , logger )
580
595
if err != nil {
581
- if apierrors .IsNotFound (err ) {
582
- err = createClusterSummary (ctx , c , profileScope , & cluster )
583
- if err != nil {
584
- profileScope .Logger .Error (err , fmt .Sprintf ("failed to create ClusterSummary for cluster %s/%s" ,
585
- cluster .Namespace , cluster .Name ))
586
- }
587
- } else {
588
- profileScope .Logger .Error (err , "failed to get ClusterSummary for cluster %s/%s" ,
589
- cluster .Namespace , cluster .Name )
590
- return err
591
- }
592
- } else {
593
- err = updateClusterSummary (ctx , c , profileScope , & cluster )
594
- if err != nil {
595
- profileScope .Logger .Error (err , "failed to update ClusterSummary for cluster %s/%s" ,
596
- cluster .Namespace , cluster .Name )
597
- return err
598
- }
596
+ return err
599
597
}
600
598
601
599
if ! updatingClusters .Has (& cluster ) {
@@ -609,7 +607,7 @@ func updateClusterSummaries(ctx context.Context, c client.Client, profileScope *
609
607
}
610
608
611
609
if skippedUpdate {
612
- return fmt .Errorf ("Not all clusters updated yet. %d still being updated" ,
610
+ return fmt .Errorf ("not all clusters updated yet. %d still being updated" ,
613
611
len (profileScope .GetStatus ().UpdatingClusters .Clusters ))
614
612
}
615
613
@@ -620,6 +618,36 @@ func updateClusterSummaries(ctx context.Context, c client.Client, profileScope *
620
618
return nil
621
619
}
622
620
621
+ func patchClusterSummary (ctx context.Context , c client.Client , profileScope * scope.ProfileScope ,
622
+ cluster * corev1.ObjectReference , logger logr.Logger ) error {
623
+
624
+ // ClusterProfile does not look at whether Cluster is paused or not.
625
+ // If a Cluster exists and it is a match, ClusterSummary is created (and ClusterSummary.Spec kept in sync if mode is
626
+ // continuous).
627
+ // ClusterSummary won't program cluster in paused state.
628
+ _ , err := getClusterSummary (ctx , c , profileScope .GetKind (), profileScope .Name (), cluster .Namespace ,
629
+ cluster .Name , clusterproxy .GetClusterType (cluster ))
630
+ if err != nil {
631
+ if apierrors .IsNotFound (err ) {
632
+ err = createClusterSummary (ctx , c , profileScope , cluster )
633
+ if err != nil {
634
+ logger .Error (err , "failed to create ClusterSummary" )
635
+ }
636
+ } else {
637
+ logger .Error (err , "failed to get ClusterSummary" )
638
+ return err
639
+ }
640
+ } else {
641
+ err = updateClusterSummary (ctx , c , profileScope , cluster )
642
+ if err != nil {
643
+ logger .Error (err , "failed to update ClusterSummary" )
644
+ return err
645
+ }
646
+ }
647
+
648
+ return nil
649
+ }
650
+
623
651
// cleanClusterSummaries finds all ClusterSummary currently owned by ClusterProfile/Profile.
624
652
// For each such ClusterSummary, if corresponding Sveltos/Cluster is not a match anymore, deletes ClusterSummary
625
653
func cleanClusterSummaries (ctx context.Context , c client.Client , profileScope * scope.ProfileScope ) error {
0 commit comments