Skip to content

Commit

Permalink
Add support for adding sidecar containers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromefroe committed Dec 4, 2020
1 parent 32f88b4 commit d2f26e6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ ClusterSpec defines the desired state for a M3 cluster to be converge to.
| parallelPodManagement | ParallelPodManagement sets StatefulSets created by the operator to have Parallel pod management instead of OrderedReady. If nil, this will default to true. | *bool | true |
| serviceAccountName | To use a non-default service account, specify the name here otherwise the service account \"default\" will be used. This is useful for advanced use-cases such as pod security policies. The service account must exist. This operator will not create it. | string | false |
| frozen | Frozen is used to stop the operator from taking any further actions on a cluster. This is useful when troubleshooting as it guarantees the operator won't make any changes to the cluster. | bool | false |
| sidecarContainers | SidecarContainers is used to add sidecar containers to the pods that run the cluster's nodes. If any storage volumes are needed by the sidecar containers, see SidecarVolumes below. | []corev1.Container | false |
| sidecarVolumes | SidecarVolumes is used to add any volumes that are required by sidecar containers. | []corev1.Volume | false |

[Back to TOC](#table-of-contents)

Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/m3dboperator/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ type ClusterSpec struct {
// won't make any changes to the cluster.
// +optional
Frozen bool `json:"frozen,omitempty"`

// SidecarContainers is used to add sidecar containers to the pods that run
// the cluster's nodes. If any storage volumes are needed by the sidecar
// containers, see SidecarVolumes below.
SidecarContainers []corev1.Container `json:"sidecarContainers,omitempty"`

// SidecarVolumes is used to add any volumes that are required by sidecar
// containers.
SidecarVolumes []corev1.Volume `json:"sidecarVolumes,omitempty"`
}

// ExternalCoordinatorConfig defines parameters for using an external
Expand Down
26 changes: 26 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.

14 changes: 14 additions & 0 deletions pkg/apis/m3dboperator/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions pkg/k8sops/m3db/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ func GenerateStatefulSet(
statefulSet.Spec.Template.Spec.Volumes = append(statefulSet.Spec.Template.Spec.Volumes, cluster.Spec.InitVolumes...)
}

if cluster.Spec.SidecarContainers != nil && len(cluster.Spec.SidecarContainers) > 0 {
cluster := cluster.DeepCopy()
statefulSet.Spec.Template.Spec.Containers = append(statefulSet.Spec.Template.Spec.Containers, cluster.Spec.SidecarContainers...)
}

if cluster.Spec.SidecarVolumes != nil && len(cluster.Spec.SidecarVolumes) > 0 {
cluster := cluster.DeepCopy()
statefulSet.Spec.Template.Spec.Volumes = append(statefulSet.Spec.Template.Spec.Volumes, cluster.Spec.SidecarVolumes...)
}

return statefulSet, nil
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/k8sops/m3db/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,25 @@ func TestGenerateStatefulSet(t *testing.T) {
t.Log(diff)
t.Log(fixture.Spec.ParallelPodManagement)
}

// Test sidecar containers.
fixture = getFixture("testM3DBCluster.yaml", t)
fixture.Spec.SidecarContainers = []v1.Container{
{
Name: "sidecar0",
},
}

ss = baseSS.DeepCopy()
sidecar := v1.Container{Name: "sidecar0"}
ss.Spec.Template.Spec.Containers = append(ss.Spec.Template.Spec.Containers, sidecar)
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) {
Expand Down

0 comments on commit d2f26e6

Please sign in to comment.