Skip to content

[placement] Allow zone to be overridden #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 7 additions & 0 deletions pkg/apis/m3dboperator/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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