Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only respect controller refs for resources #503

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 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 @@ -23,6 +25,16 @@ func (c *clusterCache) resolveResourceReferences(un *unstructured.Unstructured)
ownerRefs := un.GetOwnerReferences()
gvk := un.GroupVersionKind()

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 {

// Special case for endpoint. Remove after https://github.com/kubernetes/kubernetes/issues/28483 is fixed
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 @@ -31,6 +31,8 @@ const (
SyncOptionServerSideApply = "ServerSideApply=true"
// Sync option that disables resource deletion
SyncOptionDisableDeletion = "Delete=false"
// 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