github.com/argoproj/argo-cd@v1.8.7/controller/sort_delete.go (about) 1 package controller 2 3 import ( 4 "sort" 5 6 "github.com/argoproj/gitops-engine/pkg/sync/syncwaves" 7 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 8 ) 9 10 type syncWaveSorter []*unstructured.Unstructured 11 12 func (s syncWaveSorter) Len() int { 13 return len(s) 14 } 15 16 func (s syncWaveSorter) Swap(i, j int) { 17 s[i], s[j] = s[j], s[i] 18 } 19 20 func (s syncWaveSorter) Less(i, j int) bool { 21 return syncwaves.Wave(s[i]) < syncwaves.Wave(s[j]) 22 } 23 24 func FilterObjectsForDeletion(objs []*unstructured.Unstructured) []*unstructured.Unstructured { 25 if len(objs) <= 1 { 26 return objs 27 } 28 29 sort.Sort(sort.Reverse(syncWaveSorter(objs))) 30 31 currentSyncWave := syncwaves.Wave(objs[0]) 32 filteredObjs := make([]*unstructured.Unstructured, 0) 33 for _, obj := range objs { 34 if syncwaves.Wave(obj) != currentSyncWave { 35 break 36 } 37 filteredObjs = append(filteredObjs, obj) 38 } 39 return filteredObjs 40 }