mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-03-31 13:58:51 +02:00
* feat: delete in reverse order of sync waves Signed-off-by: darshanime <deathbullet@gmail.com> * feat: add tests for deletion in order Signed-off-by: darshanime <deathbullet@gmail.com> * feat: fix lint for appcontroller.go Signed-off-by: darshanime <deathbullet@gmail.com> * feat: add comment to explain early return Signed-off-by: darshanime <deathbullet@gmail.com>
41 lines
862 B
Go
41 lines
862 B
Go
package controller
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/argoproj/gitops-engine/pkg/sync/syncwaves"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
)
|
|
|
|
type syncWaveSorter []*unstructured.Unstructured
|
|
|
|
func (s syncWaveSorter) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s syncWaveSorter) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s syncWaveSorter) Less(i, j int) bool {
|
|
return syncwaves.Wave(s[i]) < syncwaves.Wave(s[j])
|
|
}
|
|
|
|
func FilterObjectsForDeletion(objs []*unstructured.Unstructured) []*unstructured.Unstructured {
|
|
if len(objs) <= 1 {
|
|
return objs
|
|
}
|
|
|
|
sort.Sort(sort.Reverse(syncWaveSorter(objs)))
|
|
|
|
currentSyncWave := syncwaves.Wave(objs[0])
|
|
filteredObjs := make([]*unstructured.Unstructured, 0)
|
|
for _, obj := range objs {
|
|
if syncwaves.Wave(obj) != currentSyncWave {
|
|
break
|
|
}
|
|
filteredObjs = append(filteredObjs, obj)
|
|
}
|
|
return filteredObjs
|
|
}
|