Skip to content
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 gitops-engine/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"

"github.com/argoproj/gitops-engine/pkg/sync/common"
"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 resource.HasAnnotationOption(un, common.AnnotationSyncOptions, common.SyncOptionControllerReferencesOnly) {
controllerOwnerRefs := []metav1.OwnerReference{}
for _, ownerRef := range un.GetOwnerReferences() {
if ownerRef.Controller != nil && *ownerRef.Controller {
controllerOwnerRefs = append(controllerOwnerRefs, ownerRef)
}
}
ownerRefs = controllerOwnerRefs
}

Comment on lines +28 to +37
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any UT we can add / modify to cover this extra if block?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was someone else's PR that I ported over now 2x. Can you reference an existing test I can look at?

switch {
// Special case for endpoint. Remove after https://github.com/kubernetes/kubernetes/issues/28483 is fixed
case gvk.Group == "" && gvk.Kind == kube.EndpointsKind && len(ownerRefs) == 0:
Expand Down
2 changes: 2 additions & 0 deletions gitops-engine/pkg/sync/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
SyncOptionClientSideApplyMigration = "ClientSideApplyMigration=true"
// Sync option that disables client-side apply migration
SyncOptionDisableClientSideApplyMigration = "ClientSideApplyMigration=false"
// Sync option that means only controller owner references are respected
SyncOptionControllerReferencesOnly = "ControllerReferencesOnly=true"

// Default field manager for client-side apply migration
DefaultClientSideApplyMigrationManager = "kubectl-client-side-apply"
Expand Down
Loading