You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: legacy_ownerrefs_cleaner.go
    path of file: ./repos/rancher/pkg/controllers/management/rbac
    
    the code of the file until where you have to start completion: /* Following objects had Roles and RoleBindings with incorrect OwnerRefs prior to 2.4.6:
Cloud Credential (Secret representing a cloud credential)
Node Template
Cluster Template
Cluster Template Revision
Global DNS Entry
Global DNS Provider
Multi Cluster App
Multi Cluster App Revision

this controller updates the ownerReferences on these roles and rolebindings to use the correct Kind/APIVersion fields
*/

package rbac

import (
	"context"

	typesv1 "github.com/rancher/rancher/pkg/generated/norman/core/v1"
	v3 "github.com/rancher/rancher/pkg/generated/norman/management.cattle.io/v3"
	v1 "github.com/rancher/rancher/pkg/generated/norman/rbac.authorization.k8s.io/v1"
	namespaces "github.com/rancher/rancher/pkg/namespace"
	"github.com/rancher/rancher/pkg/types/config"
	"github.com/sirupsen/logrus"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/client-go/util/retry"
)

const (
	ownerRefUpdated = "auth.management.cattle.io/owner-ref-updated"
)

type ownerRefCleaner struct {
	roles        v1.RoleInterface
	roleBindings v1.RoleBindingInterface
    
func (o *ownerRefCleaner) roleSync(key string, role *v1.Role) (runtime.Object, error) {
	if role == nil || role.DeletionTimestamp != nil {
		return nil, nil
	}
	if val, ok := role.Labels[ownerRefUpdated]; ok && val == "true" {
		return nil, nil
	}
	// All these resources are either created in cattle-global-data ns, or in case of node templates in cattle-global-nt ns
	if role.Namespace != namespaces.GlobalNamespace && role.Namespace != namespaces.NodeTemplateGlobalNamespace {
		return nil, nil
	}
	if len(role.OwnerReferences) == 0 {
		return nil, nil
	}

	needsUpdate := correctOwnerRefs(&role.OwnerReferences)
	if !needsUpdate {
		return nil, nil
	}
	logrus.Infof("Updating ownerReferences of Role %v/%v", role.Namespace, role.Name)

	retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
		roleToUpdate, updateErr := o.roles.GetNamespaced(role.Namespace, role.Name, metav1.GetOptions{})
		if updateErr != nil {
			return updateErr
		}
		roleToUpdate.OwnerReferences = role.OwnerReferences
		if roleToUpdate.Labels == nil {
			roleToUpdate.Labels = make(map[string]string)
		}
		roleToUpdate.Labels[ownerRefUpdated] = "true"
		_, err := o.roles.Update(roleToUpdate)
		return err
	})

	return nil, retryErr
}