Repository: m3db/m3db-operator
Pull request #208 (2020-03-21 21:58:11)

tentative support for an external controlling coordinator
This allows the operator to startup in db-only mode (no colocated coordinator).  Uses an externally managed coordinator. Start the db with no "coordinator" section in the configmap.

Pass in the labels of the externally controlled coordinator's service endpoint.

`spec:
.
.
.
  externalCoordinatorSelector:
    app: coordinator
.
.
.`

The db-only cluster will boot up using the external coordinator.

codecov[bot]: # [Codecov](https://codecov.io/gh/m3db/m3db-operator/pull/208?src=pr&el=h1) Report
> Merging [#208](https://codecov.io/gh/m3db/m3db-operator/pull/208?src=pr&el=desc) into [master](https://codecov.io/gh/m3db/m3db-operator/commit/73a10cd57deb4ea2807a916e6381d4efeba56065&el=desc) will **decrease** coverage by `0.07%`.
> The diff coverage is `0.00%`.


[![Impacted file tree graph](https://codecov.io/gh/m3db/m3db-operator/pull/208/graphs/tree.svg?width=650&height=150&src=pr&token=jtHDyWhsto)](https://codecov.io/gh/m3db/m3db-operator/pull/208?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
- Coverage   75.28%   75.21%   -0.08%     
==========================================
  Files          30       30              
  Lines        2096     2098       +2     
==========================================
  Hits         1578     1578              
- Misses        391      392       +1     
- Partials      127      128       +1     
```


------

[Continue to review full report at Codecov](https://codecov.io/gh/m3db/m3db-operator/pull/208?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/m3db/m3db-operator/pull/208?src=pr&el=footer). Last update [73a10cd...43fc721](https://codecov.io/gh/m3db/m3db-operator/pull/208?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/docs/api.md b/docs/api.md
index de116f9..831950e 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -62,6 +62,7 @@ ClusterSpec defines the desired state for a M3 cluster to be converge to.
 | nodeEndpointFormat | NodeEndpointFormat allows overriding of the endpoint used for a node in the M3DB placement. Defaults to \"{{ .PodName }}.{{ .M3DBService }}:{{ .Port }}\". Useful if access to the cluster from other namespaces is desired. See \"Node Endpoint\" docs for full variables available. | string | false |
 | hostNetwork | HostNetwork indicates whether M3DB pods should run in the same network namespace as the node its on. This option should be used sparingly due to security concerns outlined in the linked documentation. https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces | bool | false |
 | dnsPolicy | DNSPolicy allows the user to set the pod's DNSPolicy. This is often used in conjunction with HostNetwork.+optional | *corev1.DNSPolicy | false |
+| externalCoordinatorSelector | Specify a \"controlling\" coordinator for the cluster It is expected that there is a separate standalone coordinator cluster It is externally managed - not managed by this operator It is expected to have a service endpoint Setup this db cluster, but do not assume a co-located coordinator Instead provide a selector here so we can point to a separate coordinator service Specify here the labels required for the selector | map[string]string | false |
 
 [Back to TOC](#table-of-contents)
 
diff --git a/pkg/apis/m3dboperator/v1alpha1/cluster.go b/pkg/apis/m3dboperator/v1alpha1/cluster.go
index 303339b..91eefab 100644
--- a/pkg/apis/m3dboperator/v1alpha1/cluster.go
+++ b/pkg/apis/m3dboperator/v1alpha1/cluster.go
@@ -277,6 +277,15 @@ type ClusterSpec struct {
 	// conjunction with HostNetwork.+optional
 	// +optional
 	DNSPolicy *corev1.DNSPolicy `json:"dnsPolicy,omitEmpty"`
+
+	// Specify a "controlling" coordinator for the cluster
+	// It is expected that there is a separate standalone coordinator cluster
+	// It is externally managed - not managed by this operator
+	// It is expected to have a service endpoint
+	// Setup this db cluster, but do not assume a co-located coordinator
+	// Instead provide a selector here so we can point to a separate coordinator service
+	// Specify here the labels required for the selector
+	ExternalCoordinatorSelector map[string]string `json:"externalCoordinatorSelector,omitempty"`
 }
 
 // NodeAffinityTerm represents a node label and a set of label values, any of
diff --git a/pkg/k8sops/m3db/generators.go b/pkg/k8sops/m3db/generators.go
index c578ab1..6afff29 100644
--- a/pkg/k8sops/m3db/generators.go
+++ b/pkg/k8sops/m3db/generators.go
@@ -236,6 +236,9 @@ func GenerateCoordinatorService(cluster *myspec.M3DBCluster) (*v1.Service, error
 
 	selectorLabels := labels.BaseLabels(cluster)
 	selectorLabels[labels.Component] = labels.ComponentM3DBNode
+	if len(cluster.Spec.ExternalCoordinatorSelector) > 0 {
+		selectorLabels = cluster.Spec.ExternalCoordinatorSelector
+	}
 
 	serviceLabels := labels.BaseLabels(cluster)
 	serviceLabels[labels.Component] = labels.ComponentCoordinator


Test patch:
diff --git a/pkg/k8sops/m3db/generators_test.go b/pkg/k8sops/m3db/generators_test.go
index 4203fd4..d0ee669 100644
--- a/pkg/k8sops/m3db/generators_test.go
+++ b/pkg/k8sops/m3db/generators_test.go
@@ -542,4 +542,10 @@ func TestGenerateCoordinatorService(t *testing.T) {
 	}
 
 	assert.Equal(t, expSvc, svc)
+
+	cluster.Spec.ExternalCoordinatorSelector = map[string]string{"foo": "bar"}
+	expSvc.Spec.Selector = map[string]string{"foo": "bar"}
+	svc, err = GenerateCoordinatorService(cluster)
+	assert.NoError(t, err)
+	assert.Equal(t, expSvc, svc)
 }