Repository: m3db/m3db-operator
Pull request #211 (2020-04-23 04:31:19)

[api] Support Parallel pod management policies.
Experimental feature. More details in comment.

codecov[bot]: # [Codecov](https://codecov.io/gh/m3db/m3db-operator/pull/211?src=pr&el=h1) Report
> Merging [#211](https://codecov.io/gh/m3db/m3db-operator/pull/211?src=pr&el=desc) into [master](https://codecov.io/gh/m3db/m3db-operator/commit/d63d5f3c3194b540b15e4f830de74ea23dd56110&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.


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

```diff
@@            Coverage Diff             @@
##           master     #211      +/-   ##
==========================================
+ Coverage   75.30%   75.33%   +0.02%     
==========================================
  Files          30       30              
  Lines        2110     2112       +2     
==========================================
+ Hits         1589     1591       +2     
  Misses        393      393              
  Partials      128      128              
```


------

[Continue to review full report at Codecov](https://codecov.io/gh/m3db/m3db-operator/pull/211?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/211?src=pr&el=footer). Last update [d63d5f3...d062882](https://codecov.io/gh/m3db/m3db-operator/pull/211?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 6478fb2..a9f5403 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -66,6 +66,7 @@ ClusterSpec defines the desired state for a M3 cluster to be converge to.
 | initContainers | Custom setup for db nodes can be done via initContainers Provide the complete spec for the initContainer here If any storage volumes are needed in the initContainer see InitVolumes below | []corev1.Container | false |
 | initVolumes | If the InitContainers require any storage volumes Provide the complete specification for the required Volumes here | []corev1.Volume | false |
 | podMetadata | PodMetadata is for any Metadata that is unique to the pods, and does not belong on any other objects, such as Prometheus scrape tags | [metav1.ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#objectmeta-v1-meta) | false |
+| parallelPodManagement | ParallelPodManagement sets StatefulSets created by the operator to have Parallel pod management instead of OrderedReady. This is an EXPERIMENTAL flag and subject to deprecation in a future release. This has not been tested in production and users should not depend on it without validating it for their own use case. | bool | true |
 
 [Back to TOC](#table-of-contents)
 
diff --git a/pkg/apis/m3dboperator/v1alpha1/cluster.go b/pkg/apis/m3dboperator/v1alpha1/cluster.go
index ea16bc0..800d6a5 100644
--- a/pkg/apis/m3dboperator/v1alpha1/cluster.go
+++ b/pkg/apis/m3dboperator/v1alpha1/cluster.go
@@ -299,6 +299,13 @@ type ClusterSpec struct {
 	// PodMetadata is for any Metadata that is unique to the pods, and does
 	// not belong on any other objects, such as Prometheus scrape tags
 	PodMetadata metav1.ObjectMeta `json:"podMetadata,omitempty"`
+
+	// ParallelPodManagement sets StatefulSets created by the operator to have
+	// Parallel pod management instead of OrderedReady. This is an EXPERIMENTAL
+	// flag and subject to deprecation in a future release. This has not been
+	// tested in production and users should not depend on it without validating
+	// it for their own use case.
+	ParallelPodManagement bool `json:"parallelPodManagement,omitEmpty"`
 }
 
 // NodeAffinityTerm represents a node label and a set of label values, any of
diff --git a/pkg/k8sops/m3db/statefulset.go b/pkg/k8sops/m3db/statefulset.go
index 63c6725..efdb106 100644
--- a/pkg/k8sops/m3db/statefulset.go
+++ b/pkg/k8sops/m3db/statefulset.go
@@ -178,6 +178,10 @@ func NewBaseStatefulSet(ssName, isolationGroup string, cluster *myspec.M3DBClust
 		},
 	}
 
+	if cluster.Spec.ParallelPodManagement {
+		stsSpec.PodManagementPolicy = appsv1.ParallelPodManagement
+	}
+
 	return &appsv1.StatefulSet{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:        ssName,


Test patch:
diff --git a/pkg/k8sops/m3db/generators_test.go b/pkg/k8sops/m3db/generators_test.go
index 771652d..fe46a2d 100644
--- a/pkg/k8sops/m3db/generators_test.go
+++ b/pkg/k8sops/m3db/generators_test.go
@@ -488,6 +488,20 @@ func TestGenerateStatefulSet(t *testing.T) {
 		diff, _ := messagediff.PrettyDiff(ss, newSS)
 		t.Log(diff)
 	}
+
+	// Test PodManagement
+	fixture = getFixture("testM3DBCluster.yaml", t)
+	fixture.Spec.ParallelPodManagement = true
+
+	ss = baseSS.DeepCopy()
+	ss.Spec.PodManagementPolicy = "Parallel"
+	newSS, err = GenerateStatefulSet(fixture, isolationGroup, *instanceAmount)
+	assert.NoError(t, err)
+	assert.NotNil(t, newSS)
+	if !assert.Equal(t, ss, newSS) {
+		diff, _ := messagediff.PrettyDiff(ss, newSS)
+		t.Log(diff)
+	}
 }
 
 func TestGenerateM3DBService(t *testing.T) {