Skip to content

Commit

Permalink
Fix cluster scope resources (#1510)
Browse files Browse the repository at this point in the history
* Add the owner references to the namespaced-scoped resources

* Inject the owner only to the namespace-scoped resources
  • Loading branch information
houshengbo authored Jul 28, 2023
1 parent 0a438bc commit ce2ef23
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/reconciler/common/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"context"

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 @@ -26,7 +28,7 @@ import (
func transformers(ctx context.Context, obj base.KComponent) []mf.Transformer {
logger := logging.FromContext(ctx)
return []mf.Transformer{
mf.InjectOwner(obj),
injectOwner(obj),
mf.InjectNamespace(obj.GetNamespace()),
JobTransform(obj),
HighAvailabilityTransform(obj, logger),
Expand All @@ -39,6 +41,15 @@ func transformers(ctx context.Context, obj base.KComponent) []mf.Transformer {
}
}

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

// Transform will mutate the passed-by-reference manifest with one
// transformed by platform, common, and any extra passed in
func Transform(ctx context.Context, manifest *mf.Manifest, instance base.KComponent, extra ...mf.Transformer) error {
Expand Down

0 comments on commit ce2ef23

Please sign in to comment.