Skip to content

Commit

Permalink
[placement] Allow zone to be overridden
Browse files Browse the repository at this point in the history
This allows us to direct placement writes
to an etcd cluster other than the hardcoded "embedded"
zone.
  • Loading branch information
wesleyk committed Apr 27, 2021
1 parent 3259a9c commit 059a477
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/apis/m3dboperator/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ type ClusterSpec struct {
// OnDeleteUpdateStrategy sets StatefulSets created by the operator to
// have OnDelete as the update strategy instead of RollingUpdate.
OnDeleteUpdateStrategy bool `json:"onDeleteUpdateStrategy,omitempty"`

// Zone defines the zone that placement instances will be written to if set.
// If not set, the default zone of "embedded" will be used.
// +optional
Zone string `json:"zone,omitempty"`
}

// ExternalCoordinatorConfig defines parameters for using an external
Expand Down
7 changes: 6 additions & 1 deletion pkg/k8sops/m3db/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ func PlacementInstanceFromPod(cluster *myspec.M3DBCluster, pod *corev1.Pod, idPr
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: _zoneEmbedded,
Zone: zone,
Weight: 100,
Hostname: pod.Name + "." + epCtx.M3DBService,
Endpoint: str.String(),
Expand Down
16 changes: 16 additions & 0 deletions pkg/k8sops/m3db/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ func TestPlacementInstanceFromPod(t *testing.T) {
Port: 9000,
}

inst, err := PlacementInstanceFromPod(cluster, pod, idProvider)
assert.NoError(t, err)
assert.Equal(t, expInst, inst)
})
t.Run("zone override", func(t *testing.T) {
cluster.Spec.Zone = "embedded-override"
expInst := &placementpb.Instance{
Id: `{"name":"pod-a"}`,
IsolationGroup: "zone-a",
Zone: "embedded-override",
Weight: 100,
Hostname: "pod-a.m3dbnode-cluster-a",
Endpoint: "pod-a.m3dbnode-cluster-a.my_ns:9000",
Port: 9000,
}

inst, err := PlacementInstanceFromPod(cluster, pod, idProvider)
assert.NoError(t, err)
assert.Equal(t, expInst, inst)
Expand Down

0 comments on commit 059a477

Please sign in to comment.