func initializeClusterOperator(co *configv1.ClusterOperator) {
	co.Name = operatorcontroller.DNSClusterOperatorName().Name
	co.Status.Versions = []configv1.OperandVersion{
		{
			Name:    OperatorVersionName,
			Version: UnknownVersionValue,
		},
		{
			Name:    CoreDNSVersionName,
			Version: UnknownVersionValue,
		},
		{
			Name:    OpenshiftCLIVersionName,
			Version: UnknownVersionValue,
		},
		{
			Name:    KubeRBACProxyName,
			Version: UnknownVersionValue,
		},
	}
	co.Status.Conditions = []configv1.ClusterOperatorStatusCondition{
		{
			Type:   configv1.OperatorDegraded,
			Status: configv1.ConditionUnknown,
		},
		{
			Type:   configv1.OperatorProgressing,
			Status: configv1.ConditionUnknown,
		},
		{
			Type:   configv1.OperatorAvailable,
			Status: configv1.ConditionUnknown,
		},
	}
}
Populate versions and conditions in cluster operator status as CVO expects these fields.
package status
import (
	"context"
	"fmt"
	"strings"
	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
	configv1 "github.com/openshift/api/config/v1"
	operatorv1 "github.com/openshift/api/operator/v1"
	operatorconfig "github.com/openshift/cluster-dns-operator/pkg/operator/config"
	operatorcontroller "github.com/openshift/cluster-dns-operator/pkg/operator/controller"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/types"
	utilclock "k8s.io/apimachinery/pkg/util/clock"
	podutil "k8s.io/kubectl/pkg/util/podutils"
	"sigs.k8s.io/controller-runtime/pkg/cache"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"sigs.k8s.io/controller-runtime/pkg/controller"
	"sigs.k8s.io/controller-runtime/pkg/handler"
	"sigs.k8s.io/controller-runtime/pkg/manager"
	"sigs.k8s.io/controller-runtime/pkg/predicate"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
	"sigs.k8s.io/controller-runtime/pkg/source"
)
const (
	OperatorVersionName     = "operator"
	CoreDNSVersionName      = "coredns"
	OpenshiftCLIVersionName = "openshift-cli"
	KubeRBACProxyName       = "kube-rbac-proxy"
	UnknownVersionValue = "unknown"
	controllerName      = "status_controller"
	dnsEqualConditionMessage = "desired and current number of DNSes are equal"
)
var clock utilclock.Clock = utilclock.RealClock{}
type reconciler struct {
	operatorconfig.Config
	client client.Client
	cache  cache.Cache
}
func New(mgr manager.Manager, config operatorconfig.Config) (controller.Controller, error) {
	reconciler := &reconciler{
		Config: config,
		client: mgr.GetClient(),
		cache:  mgr.GetCache(),
	}
	c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: reconciler})
	if err != nil {
		return nil, err
	}
	if err := c.Watch(&source.Kind{Type: &operatorv1.DNS{}}, &handler.EnqueueRequestForObject{}); err != nil {
		return nil, err
	}
	if err := c.Watch(&source.Kind{Type: &appsv1.DaemonSet{}}, &handler.EnqueueRequestForOwner{OwnerType: &operatorv1.DNS{}}); err != nil {
		return nil, err
	}
	isDNSClusterOperator := func(o client.Object) bool {
		return o.GetName() == operatorcontroller.DefaultOperatorName
	}
	clusteroperatorToDNS := func(_ client.Object) []reconcile.Request {
		return []reconcile.Request{{
			NamespacedName: types.NamespacedName{
				Name: operatorcontroller.DefaultDNSName,
			},
		}}
	}
	if err := c.Watch(
		&source.Kind{Type: &configv1.ClusterOperator{}},
		handler.EnqueueRequestsFromMapFunc(clusteroperatorToDNS),
		predicate.NewPredicateFuncs(isDNSClusterOperator),
	); err != nil {
		return nil, err
	}
	return c, nil
}
func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
	co := &configv1.ClusterOperator{}
	name := operatorcontroller.DNSClusterOperatorName()
	if err := r.client.Get(ctx, name, co); err != nil {
		if errors.IsNotFound(err) {
			initializeClusterOperator(co)
			if err := r.client.Create(ctx, co); err != nil {
				return reconcile.Result{}, fmt.Errorf("failed to create clusteroperator %q: %w", name.Name, err)
			}
		} else {
			return reconcile.Result{}, fmt.Errorf("failed to get clusteroperator %q: %w", name.Name, err)
		}
	}
	oldStatus := co.Status.DeepCopy()
	state, err := r.getOperatorState()
	if err != nil {
		return reconcile.Result{}, fmt.Errorf("failed to get operator state: %w", err)
	}
	related := []configv1.ObjectReference{
		{
			Resource: "namespaces",
			Name:     r.Config.OperatorNamespace,
		},
		{
			Group:    operatorv1.GroupName,
			Resource: "dnses",
			Name:     "default",
		},
	}
	if state.haveNamespace {
		related = append(related, configv1.ObjectReference{
			Resource: "namespaces",
			Name:     state.namespace.Name,
		})
	}
	co.Status.RelatedObjects = related
	oldVersions := computeOldVersions(co.Status.Versions)
	newVersions := computeNewVersions(
		r.OperatorReleaseVersion,
		r.CoreDNSImage,
		r.OpenshiftCLIImage,
		r.KubeRBACProxyImage,
	)
	curVersions := computeCurrentVersions(
		oldVersions,
		newVersions,
		&state.dnsDaemonSet,
		&state.nodeResolverDaemonSet,
		state.dnsPodList.Items,
		state.nodeResolverPodList.Items,
	)
	operatorProgressingCondition := computeOperatorProgressingCondition(
		state.haveDNS,
		&state.dns,
		oldVersions,
		newVersions,
		curVersions,
	)
	co.Status.Conditions = mergeConditions(co.Status.Conditions,
		computeOperatorAvailableCondition(state.haveDNS, &state.dns),
		operatorProgressingCondition,
		computeOperatorDegradedCondition(state.haveDNS, &state.dns),
	)
	co.Status.Versions = computeOperatorStatusVersions(curVersions)
	co.Status.Conditions = mergeConditions(co.Status.Conditions, computeOperatorUpgradeableCondition(&state.dns))
	if !operatorStatusesEqual(*oldStatus, co.Status) {
		if err := r.client.Status().Update(ctx, co); err != nil {
			return reconcile.Result{}, fmt.Errorf("failed to update clusteroperator %q: %w", name.Name, err)
		}
	}
	return reconcile.Result{}, nil
}