func (c *M3DBController) readyNamespaces(cluster *myspec.M3DBCluster, registry *dbns.Registry) error {
	if cluster.Spec.ExternalCoordinator != nil {
		c.logger.Debug("using an external coordinator. will not attempt to ready namespaces")
		return nil
	}
	toReady := namespacesToReady(registry, cluster.Spec.Namespaces)
	for _, ns := range toReady {
		req := &admin.NamespaceReadyRequest{
			Name: ns.Name,
		}
		err := c.adminClient.namespaceClientForCluster(cluster).Ready(req)
		cause := pkgerrors.Cause(err)
		if cause == m3admin.ErrNotFound || cause == m3admin.ErrMethodNotAllowed {
			c.logger.Info("coordinator does not yet support the ready endpoint. " +
				"skipping readying namespaces until upgraded")
			return nil
		}
		if err != nil {
			c.logger.Error("error readying namespace",
				zap.String("namespace", ns.Name),
				zap.Error(err))
			return fmt.Errorf("error readying namespace '%s': %v", ns.Name, err)
		}
	}
	return nil
}
readyNamespaces will attempt to mark all namespaces in the initializing state as ready.
package controller
import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"reflect"
	"sort"
	"strconv"
	"strings"
	"time"
	myspec "github.com/m3db/m3db-operator/pkg/apis/m3dboperator/v1alpha1"
	"github.com/m3db/m3db-operator/pkg/k8sops/labels"
	"github.com/m3db/m3db-operator/pkg/k8sops/m3db"
	"github.com/m3db/m3db-operator/pkg/k8sops/podidentity"
	"github.com/m3db/m3db-operator/pkg/m3admin"
	"github.com/m3db/m3db-operator/pkg/m3admin/namespace"
	"github.com/m3db/m3db-operator/pkg/util/eventer"
	"github.com/m3db/m3/src/cluster/generated/proto/placementpb"
	"github.com/m3db/m3/src/cluster/placement"
	dbns "github.com/m3db/m3/src/dbnode/generated/proto/namespace"
	"github.com/m3db/m3/src/query/generated/proto/admin"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	klabels "k8s.io/apimachinery/pkg/labels"
	"k8s.io/apimachinery/pkg/util/runtime"
	pkgerrors "github.com/pkg/errors"
	"go.uber.org/zap"
)
var (
	errEmptyPodList         = errors.New("cannot find removal candidate in empty list")
	errNoPodsInPlacement    = errors.New("no pods were found in the placement")
	errNilNamespaceRegistry = errors.New("nil registry for namespaces")
	errPodNotInPlacement    = errors.New("instance not found in placement")
)
func (c *M3DBController) reconcileNamespaces(cluster *myspec.M3DBCluster) error {
	resp, err := c.adminClient.namespaceClientForCluster(cluster).List()
	if err != nil {
		c.logger.Error("failed to get namespace", zap.Error(err))
		c.recorder.WarningEvent(cluster, eventer.ReasonFailSync, err.Error())
		return err
	}
	if err := c.pruneNamespaces(cluster, resp.Registry); err != nil {
		return err
	}
	if err := c.createNamespaces(cluster, resp.Registry); err != nil {
		return err
	}
	return c.readyNamespaces(cluster, resp.Registry)
}
func (c *M3DBController) createNamespaces(cluster *myspec.M3DBCluster, registry *dbns.Registry) error {
	toCreate := namespacesToCreate(registry, cluster.Spec.Namespaces)
	for _, ns := range toCreate {
		req, err := namespace.RequestFromSpec(ns)
		if err != nil {
			c.logger.Error("error forming namespace request",
				zap.String("namespace", ns.Name),
				zap.Error(err))
			return fmt.Errorf("error forming request for namespace '%s': %v", ns.Name, err)
		}
		err = c.adminClient.namespaceClientForCluster(cluster).Create(req)
		if err != nil {
			c.logger.Error("error creating namespace",
				zap.String("namespace", ns.Name),
				zap.Error(err))
			return fmt.Errorf("error creating namespace '%s': %w", ns.Name, err)
		}
		c.recorder.NormalEvent(cluster, eventer.ReasonCreating, "created namespace "+ns.Name)
	}
	return nil
}