Skip to content
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

[api] Support custom InitContainers in cluster spec #209

Merged
merged 8 commits into from
Apr 8, 2020
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
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ ClusterSpec defines the desired state for a M3 cluster to be converge to.
| 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 |
| 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 |

[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 @@ -286,6 +286,15 @@ type ClusterSpec struct {
// 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"`

// 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
InitContainers []corev1.Container `json:"initContainers,omitempty"`

// If the InitContainers require any storage volumes
// Provide the complete specification for the required Volumes here
InitVolumes []corev1.Volume `json:"initVolumes,omitempty"`
}

// NodeAffinityTerm represents a node label and a set of label values, any of
Expand Down
10 changes: 10 additions & 0 deletions pkg/k8sops/m3db/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ func GenerateStatefulSet(
m3dbContainer.Env = append(m3dbContainer.Env, cluster.Spec.EnvVars...)
}

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

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

return statefulSet, nil
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/k8sops/m3db/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,28 @@ func TestGenerateStatefulSet(t *testing.T) {
diff, _ := messagediff.PrettyDiff(ss, newSS)
t.Log(diff)
}

// Test init containers
fixture = getFixture("testM3DBCluster.yaml", t)
fixture.Spec.InitContainers = []v1.Container{
{
Name: "init0",
},
}

ss = baseSS.DeepCopy()
ss.Spec.Template.Spec.InitContainers = []v1.Container{
{
Name: "init0",
},
}
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