@@ -10,6 +10,8 @@ import (
1010 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1111 "k8s.io/apimachinery/pkg/types"
1212
13+ synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
14+ syncresource "github.com/argoproj/gitops-engine/pkg/sync/resource"
1315 "github.com/argoproj/gitops-engine/pkg/utils/kube"
1416)
1517
@@ -20,15 +22,17 @@ func mightHaveInferredOwner(r *Resource) bool {
2022
2123func (c * clusterCache ) resolveResourceReferences (un * unstructured.Unstructured ) ([]metav1.OwnerReference , func (kube.ResourceKey ) bool ) {
2224 var isInferredParentOf func (_ kube.ResourceKey ) bool
23- allOwnerRefs := un .GetOwnerReferences ()
25+ ownerRefs := un .GetOwnerReferences ()
2426 gvk := un .GroupVersionKind ()
2527
26- // TODO: Put this behind a gate
27- ownerRefs := []metav1.OwnerReference {}
28- for _ , ownerRef := range allOwnerRefs {
29- if ownerRef .Controller != nil && * ownerRef .Controller {
30- ownerRefs = append (ownerRefs , ownerRef )
28+ if syncresource .HasAnnotationOption (un , synccommon .AnnotationSyncOptions , synccommon .SyncOptionControllerReferencesOnly ) {
29+ controllerOwnerRefs := []metav1.OwnerReference {}
30+ for _ , ownerRef := range un .GetOwnerReferences () {
31+ if ownerRef .Controller != nil && * ownerRef .Controller {
32+ controllerOwnerRefs = append (controllerOwnerRefs , ownerRef )
33+ }
3134 }
35+ return controllerOwnerRefs , isInferredParentOf
3236 }
3337
3438 switch {
0 commit comments