Skip to content

Commit 529b9b7

Browse files
committed
fetchVMClusters: sort clusters by ObservedGeneration (descending order)
1 parent adbada8 commit 529b9b7

File tree

1 file changed

+7
-0
lines changed
  • internal/controller/operator/factory/vmdistributedcluster

1 file changed

+7
-0
lines changed

internal/controller/operator/factory/vmdistributedcluster/vmcluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"reflect"
8+
"sort"
89
"time"
910

1011
corev1 "k8s.io/api/core/v1"
@@ -88,6 +89,12 @@ func fetchVMClusters(ctx context.Context, rclient client.Client, namespace strin
8889
return nil, fmt.Errorf("invalid VMClusterRefOrSpec at index %d: neither Ref nor Spec is set", i)
8990
}
9091
}
92+
93+
// Sort VMClusters by observedGeneration in descending order (biggest first)
94+
sort.Slice(vmClusters, func(i, j int) bool {
95+
return vmClusters[i].Status.ObservedGeneration > vmClusters[j].Status.ObservedGeneration
96+
})
97+
9198
return vmClusters, nil
9299
}
93100

0 commit comments

Comments
 (0)