Skip to content

Commit

Permalink
Move code behind a resource-specific annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjpryor committed Feb 1, 2023
1 parent 92eb90f commit 8dd5d6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/cache/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"

synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
syncresource "github.com/argoproj/gitops-engine/pkg/sync/resource"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
)

Expand All @@ -20,15 +22,17 @@ func mightHaveInferredOwner(r *Resource) bool {

func (c *clusterCache) resolveResourceReferences(un *unstructured.Unstructured) ([]metav1.OwnerReference, func(kube.ResourceKey) bool) {
var isInferredParentOf func(_ kube.ResourceKey) bool
allOwnerRefs := un.GetOwnerReferences()
ownerRefs := un.GetOwnerReferences()
gvk := un.GroupVersionKind()

// TODO: Put this behind a gate
ownerRefs := []metav1.OwnerReference{}
for _, ownerRef := range allOwnerRefs {
if ownerRef.Controller != nil && *ownerRef.Controller {
ownerRefs = append(ownerRefs, ownerRef)
if syncresource.HasAnnotationOption(un, synccommon.AnnotationSyncOptions, synccommon.SyncOptionControllerReferencesOnly) {
controllerOwnerRefs := []metav1.OwnerReference{}
for _, ownerRef := range un.GetOwnerReferences() {
if ownerRef.Controller != nil && *ownerRef.Controller {
controllerOwnerRefs = append(controllerOwnerRefs, ownerRef)
}
}
return controllerOwnerRefs, isInferredParentOf
}

switch {
Expand Down
2 changes: 2 additions & 0 deletions pkg/sync/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
SyncOptionReplace = "Replace=true"
// Sync option that enables use of --server-side flag instead of client-side
SyncOptionServerSideApply = "ServerSideApply=true"
// Sync option that means only controller owner references are respected
SyncOptionControllerReferencesOnly = "ControllerReferencesOnly=true"
)

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

0 comments on commit 8dd5d6d

Please sign in to comment.