Skip to content

Commit 8dd5d6d

Browse files
author
Matt Pryor
committed
Move code behind a resource-specific annotation
1 parent 92eb90f commit 8dd5d6d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pkg/cache/references.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2123
func (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 {

pkg/sync/common/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const (
2929
SyncOptionReplace = "Replace=true"
3030
// Sync option that enables use of --server-side flag instead of client-side
3131
SyncOptionServerSideApply = "ServerSideApply=true"
32+
// Sync option that means only controller owner references are respected
33+
SyncOptionControllerReferencesOnly = "ControllerReferencesOnly=true"
3234
)
3335

3436
type PermissionValidator func(un *unstructured.Unstructured, res *metav1.APIResource) error

0 commit comments

Comments
 (0)