func Role(n NFD) (ResourceStatus, error) {
	state := n.idx
	obj := n.resources[state].Role
	obj.SetNamespace(n.ins.GetNamespace())
	found := &rbacv1.Role{}
	klog.Info("Looking for Role %q in Namespace %q", obj.Name, obj.Namespace)
	if err := controllerutil.SetControllerReference(n.ins, &obj, n.rec.Scheme); err != nil {
		return NotReady, err
	}
	err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: obj.Namespace, Name: obj.Name}, found)
	if err != nil && errors.IsNotFound(err) {
		klog.Info("Role %q not found in Namespace %q, creating", obj.Name, obj.Namespace)
		err = n.rec.Client.Create(context.TODO(), &obj)
		if err != nil {
			klog.Info("Couldn't create Role %q in Namespace %q", obj.Name, obj.Namespace)
			return NotReady, err
		}
		return Ready, nil
	} else if err != nil {
		return NotReady, err
	}
	klog.Info("Found Role %q in Namespace %q, updating", obj.Name, obj.Namespace)
	err = n.rec.Client.Update(context.TODO(), &obj)
	if err != nil {
		return NotReady, err
	}
	return Ready, nil
}
Role checks if a Role exists and creates a Role if it doesn't
package controllers
import (
	"context"
	"fmt"
	"strings"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	rbacv1 "k8s.io/api/rbac/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/intstr"
	"k8s.io/klog/v2"
	"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
type controlFunc []func(n NFD) (ResourceStatus, error)
type ResourceStatus int
const (
	Ready ResourceStatus = iota
	NotReady
	defaultServicePort int = 12000
)
func (s ResourceStatus) String() string {
	names := [...]string{
		"Ready",
		"NotReady"}
	if s < Ready || s > NotReady {
		return "Unkown Resources Status"
	}
	return names[s]
}
func Namespace(n NFD) (ResourceStatus, error) {
	state := n.idx
	obj := n.resources[state].Namespace
	found := &corev1.Namespace{}
	klog.Info("Looking for Namespace %q", obj.Name)
	err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: obj.Namespace, Name: obj.Name}, found)
	if err != nil && errors.IsNotFound(err) {
		klog.Info("Namespace %q Not found, creating", obj.Name)
		err = n.rec.Client.Create(context.TODO(), &obj)
		if err != nil {
			klog.Info("Couldn't create Namespace %q", obj.Name)
			return NotReady, err
		}
		return Ready, nil
	} else if err != nil {
		return NotReady, err
	}
	klog.Info("Found Namespace %q, skipping update", obj.Name)
	return Ready, nil
}
func ServiceAccount(n NFD) (ResourceStatus, error) {
	state := n.idx
	obj := n.resources[state].ServiceAccount
	obj.SetNamespace(n.ins.GetNamespace())
	found := &corev1.ServiceAccount{}
	klog.Info("Looking for ServiceAccount %q in Namespace %q", obj.Name, obj.Namespace)
	if err := controllerutil.SetControllerReference(n.ins, &obj, n.rec.Scheme); err != nil {
		return NotReady, err
	}
	err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: obj.Namespace, Name: obj.Name}, found)
	if err != nil && errors.IsNotFound(err) {
		klog.Info("ServiceAccount %q not found, creating", obj.Name)
		err = n.rec.Client.Create(context.TODO(), &obj)
		if err != nil {
			klog.Info("Couldn't create ServiceAccount %q", obj.Name)
			return NotReady, err
		}
		return Ready, nil
	} else if err != nil {
		return NotReady, err
	}
	klog.Info("Found ServiceAccount %q in Namespace %q, skipping update", obj.Name, obj.Namespace)
	return Ready, nil
}
func ClusterRole(n NFD) (ResourceStatus, error) {
	state := n.idx
	obj := n.resources[state].ClusterRole
	found := &rbacv1.ClusterRole{}
	klog.Info("Looking for ClusterRole %q in Namespace %", obj.Name, obj.Namespace)
	err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: "", Name: obj.Name}, found)
	if err != nil && errors.IsNotFound(err) {
		klog.Info("ClusterRole %q not found, creating", obj.Name)
		err = n.rec.Client.Create(context.TODO(), &obj)
		if err != nil {
			klog.Info("Couldn't create ClusterRole %q", obj.Name)
			return NotReady, err
		}
		return Ready, nil
	} else if err != nil {
		return NotReady, err
	}
	klog.Info("ClusterRole found, updating", obj.Name)
	err = n.rec.Client.Update(context.TODO(), &obj)
	if err != nil {
		return NotReady, err
	}
	return Ready, nil
}
func ClusterRoleBinding(n NFD) (ResourceStatus, error) {
	state := n.idx
	obj := n.resources[state].ClusterRoleBinding
	found := &rbacv1.ClusterRoleBinding{}
	obj.Subjects[0].Namespace = n.ins.GetNamespace()
	klog.Info("Looking for ClusterRoleBinding %q in Namespace %q", obj.Name, obj.Namespace)
	err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: "", Name: obj.Name}, found)
	if err != nil && errors.IsNotFound(err) {
		klog.Info("ClusterRoleBinding %q not found in Namespace %q, creating", obj.Name, obj.Namespace)
		err = n.rec.Client.Create(context.TODO(), &obj)
		if err != nil {
			klog.Info("Couldn't create ClusterRoleBinding %q in Namespace %q", obj.Name, obj.Namespace)
			return NotReady, err
		}
		return Ready, nil
	} else if err != nil {
		return NotReady, err
	}
	klog.Info("ClusterRoleBinding %q found in Namespace %q, updating", obj.Name, obj.Namespace)
	err = n.rec.Client.Update(context.TODO(), &obj)
	if err != nil {
		return NotReady, err
	}
	return Ready, nil
}