Skip to content

Commit

Permalink
Inject the owner only to the namespace-scoped resources
Browse files Browse the repository at this point in the history
  • Loading branch information
houshengbo authored and knative-prow-robot committed Jul 29, 2023
1 parent 9013513 commit 3703606
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/reconciler/common/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package common

import (
"context"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

mf "github.com/manifestival/manifestival"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"knative.dev/pkg/logging"

"knative.dev/operator/pkg/apis/operator/base"
Expand All @@ -43,7 +43,9 @@ func transformers(ctx context.Context, obj base.KComponent) []mf.Transformer {

func injectOwner(owner mf.Owner) mf.Transformer {
return func(u *unstructured.Unstructured) error {
u.SetOwnerReferences([]v1.OwnerReference{*v1.NewControllerRef(owner, owner.GroupVersionKind())})
if u.GetNamespace() != "" {
u.SetOwnerReferences([]v1.OwnerReference{*v1.NewControllerRef(owner, owner.GroupVersionKind())})
}
return nil
}
}
Expand Down

0 comments on commit 3703606

Please sign in to comment.