func (r *ReconcileCluster) Reconcile(request reconcile.Request) (reconcile.Result, error) {
	reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
	reqLogger.Info("Reconciling Cluster")
	instance := &picchuv1alpha1.Cluster{}
	err := r.client.Get(context.TODO(), request.NamespacedName, instance)
	if err != nil {
		if errors.IsNotFound(err) {
			return reconcile.Result{}, nil
		}
		return reconcile.Result{}, err
	}
	r.scheme.Default(instance)
	if !instance.IsDeleted() {
		if instance.IsFinalized() {
			instance.AddFinalizer()
			return reconcile.Result{Requeue: true}, r.client.Update(context.TODO(), instance)
		}
		if !instance.Spec.Enabled {
			reqLogger.Info("Disabled, no status")
			instance.Status = picchuv1alpha1.ClusterStatus{}
		} else {
			secret := &corev1.Secret{}
			selector := types.NamespacedName{
				Name:      instance.Name,
				Namespace: instance.Namespace,
			}
			err = r.client.Get(context.TODO(), selector, secret)
			if err != nil {
				secret = nil
			}
			if secret != nil {
				config, err := instance.Config(secret)
				if err != nil {
					reqLogger.Error(err, "Failed to create kube config")
					return reconcile.Result{}, err
				}
				ready := true
				version, err := ServerVersion(config)
				if err != nil {
					ready = false
				}
				reqLogger.Info("Setting status")
				instance.Status = picchuv1alpha1.ClusterStatus{
					Kubernetes: picchuv1alpha1.ClusterKubernetesStatus{
						Version: FormatVersion(version),
						Ready:   ready,
					},
				}
			}
		}
		err = utils.UpdateStatus(context.TODO(), r.client, instance)
		if err != nil {
			reqLogger.Error(err, "Failed to update Cluster status")
			return reconcile.Result{}, err
		}
		return reconcile.Result{RequeueAfter: r.config.RequeueAfter}, nil
	}
	if !instance.IsFinalized() {
		instance.Finalize()
		return reconcile.Result{}, r.client.Update(context.TODO(), instance)
	}
	return reconcile.Result{}, nil
}
Reconcile reads that state of the cluster for a Cluster object and makes changes based on the state read
and what is in the Cluster.Spec
Note:
The Controller will requeue the Request to be processed again if the returned error is non-nil or
Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
package cluster
import (
	"context"
	"fmt"
	"regexp"
	picchuv1alpha1 "go.medium.engineering/picchu/pkg/apis/picchu/v1alpha1"
	"go.medium.engineering/picchu/pkg/controller/utils"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/version"
	"sigs.k8s.io/controller-runtime/pkg/builder"
	"sigs.k8s.io/controller-runtime/pkg/client"
	logf "sigs.k8s.io/controller-runtime/pkg/log"
	"sigs.k8s.io/controller-runtime/pkg/manager"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
	"k8s.io/client-go/discovery"
	"k8s.io/client-go/rest"
)
var log = logf.Log.WithName("controller_cluster")
var hostPattern = regexp.MustCompile(`https: 
func Add(mgr manager.Manager, c utils.Config) error {
	return add(mgr, newReconciler(mgr, c))
}
func newReconciler(mgr manager.Manager, c utils.Config) reconcile.Reconciler {
	return &ReconcileCluster{client: mgr.GetClient(), scheme: mgr.GetScheme(), config: c}
}
func add(mgr manager.Manager, r reconcile.Reconciler) error {
	_, err := builder.ControllerManagedBy(mgr).
		For(&picchuv1alpha1.Cluster{}).
		Build(r)
	if err != nil {
		return err
	}
	return nil
}
var _ reconcile.Reconciler = &ReconcileCluster{}
type ReconcileCluster struct {
	client client.Client
	scheme *runtime.Scheme
	config utils.Config
}