Skip to content

Commit

Permalink
modify setOwnerReference to accept unstructred.Unstructured
Browse files Browse the repository at this point in the history
  • Loading branch information
varshaprasad96 committed Oct 21, 2021
1 parent 2f04ded commit fe0bde3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func watchDependentResources(mgr manager.Manager, r *HelmOperatorReconciler, c c
}

restMapper := mgr.GetRESTMapper()
useOwnerRef, err := controllerutil.SupportsOwnerReference(restMapper, owner, dependent)
useOwnerRef, err := controllerutil.SupportsOwnerReference(restMapper, owner, unstructuredObj)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/actionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (pr *ownerPostRenderer) Run(in *bytes.Buffer) (*bytes.Buffer, error) {
return err
}
u := &unstructured.Unstructured{Object: objMap}
useOwnerRef, err := controllerutil.SupportsOwnerReference(pr.rm, pr.owner, u)
useOwnerRef, err := controllerutil.SupportsOwnerReference(pr.rm, pr.owner.(*unstructured.Unstructured), u)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/controllerutil/controllerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -57,7 +57,7 @@ func WaitForDeletion(ctx context.Context, cl client.Reader, o client.Object) err
}, ctx.Done())
}

func SupportsOwnerReference(restMapper meta.RESTMapper, owner, dependent runtime.Object) (bool, error) {
func SupportsOwnerReference(restMapper meta.RESTMapper, owner, dependent *unstructured.Unstructured) (bool, error) {
ownerGVK := owner.GetObjectKind().GroupVersionKind()
ownerMapping, err := restMapper.RESTMapping(ownerGVK.GroupKind(), ownerGVK.Version)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/controllerutil/controllerutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ var _ = Describe("Controllerutil", func() {
Describe("SupportsOwnerReference", func() {
var (
rm *meta.DefaultRESTMapper
owner client.Object
dependent client.Object
owner *unstructured.Unstructured
dependent *unstructured.Unstructured
clusterScoped = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "ClusterScoped"}
namespaceScoped = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "NamespaceScoped"}
)
Expand Down

0 comments on commit fe0bde3

Please sign in to comment.