func PlacementInstanceFromPod(cluster *myspec.M3DBCluster, pod *corev1.Pod, idProvider podidentity.Provider) (*placementpb.Instance, error) {
	isoGroup, ok := pod.ObjectMeta.Labels[labels.IsolationGroup]
	if !ok {
		return nil, fmt.Errorf("could not find label %s in %v", labels.IsolationGroup, pod.ObjectMeta.Labels)
	}
	id, err := idProvider.Identity(pod, cluster)
	if err != nil {
		return nil, err
	}
	idStr, err := podidentity.IdentityJSON(id)
	if err != nil {
		return nil, err
	}
	epFmt := cluster.Spec.NodeEndpointFormat
	if epFmt == "" {
		epFmt = defaultNodeEndpointFormat
	}
	str := &strings.Builder{}
	epCtx := endpointContext{
		PodName:      pod.Name,
		PodNamespace: pod.Namespace,
		M3DBService:  HeadlessServiceName(cluster.Name),
		Port:         defaultM3DBPort,
	}
	tmpl, err := template.New("nodeEndpoint").Parse(epFmt)
	if err != nil {
		return nil, pkgerrors.WithMessage(err, "cannot construct node endpoint template")
	}
	if err := tmpl.Execute(str, epCtx); err != nil {
		return nil, pkgerrors.WithMessage(err, "cannot execute node endpoint template")
	}
	zone := cluster.Spec.Zone
	if zone == "" {
		zone = _zoneEmbedded
	}
	instance := &placementpb.Instance{
		Id:             idStr,
		IsolationGroup: isoGroup,
		Zone:           zone,
		Weight:         100,
		Hostname:       pod.Name + "." + epCtx.M3DBService,
		Endpoint:       str.String(),
		Port:           defaultM3DBPort,
	}
	return instance, nil
}
PlacementInstanceFromPod creates a new m3cluster placement instance given a
pod spec.
package m3db
import (
	"fmt"
	"strings"
	"text/template"
	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/podidentity"
	"github.com/m3db/m3/src/cluster/generated/proto/placementpb"
	corev1 "k8s.io/api/core/v1"
	pkgerrors "github.com/pkg/errors"
)
const (
	_zoneEmbedded             = "embedded"
	defaultM3DBPort           = 9000
	defaultNodeEndpointFormat = "{{ .PodName }}.{{ .M3DBService }}:{{ .Port }}"
)
type endpointContext struct {
	PodName      string
	M3DBService  string
	PodNamespace string
	Port         uint32
}