Skip to content

Commit

Permalink
initcontainer checks schedulable configmap first
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d committed Feb 28, 2019
1 parent 67262c4 commit b8617a3
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions pkg/controller/util/stateful_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const (
esJavaOpts = "-Xms256m -Xmx256m"
)

var (
SchedulableFilePath = filepath.Join(schedulingVolumeMountPath, "schedulable.yml")
)

func ReconcileStatefulSet(
client client.Client,
scheme *runtime.Scheme,
Expand Down Expand Up @@ -68,6 +72,12 @@ func ReconcileStatefulSet(

podEnv := mkEnv(clusterName, namespace, pool)

schedulableMount := corev1.VolumeMount{
Name: PoolSchedulableConfigMapName(clusterName, pool.Name),
MountPath: schedulingVolumeMountPath,
ReadOnly: true,
}

statefulSet := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -85,7 +95,7 @@ func ReconcileStatefulSet(
Labels: podLabels,
},
Spec: corev1.PodSpec{
InitContainers: mkInitContainers(CatImage(esImage, esTag), maxMapCount),
InitContainers: mkInitContainers(CatImage(esImage, esTag), maxMapCount, schedulableMount),
Containers: []corev1.Container{
{
Name: "elasticsearch",
Expand Down Expand Up @@ -120,11 +130,7 @@ func ReconcileStatefulSet(
SubPath: elasticConfigFile,
ReadOnly: true,
},
{
Name: PoolSchedulableConfigMapName(clusterName, pool.Name),
MountPath: schedulingVolumeMountPath,
ReadOnly: true,
},
schedulableMount,
},
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Expand Down Expand Up @@ -314,7 +320,7 @@ func mkEnv(clusterName string, namespace string, pool elasticsearchv1beta1.PoolS
return podEnv
}

func mkInitContainers(image string, maxMapCount int) []corev1.Container {
func mkInitContainers(image string, maxMapCount int, schedulingVolumeMount corev1.VolumeMount) []corev1.Container {
var user int64 = 0
privileged := true

Expand All @@ -337,6 +343,30 @@ func mkInitContainers(image string, maxMapCount int) []corev1.Container {
Limits: reqs,
},
},
{
Name: "check-schedulable",
Image: image,
Command: []string{"/bin/sh", "-c", `grep "${POD_NAME}" "${SCHEDULABLE_FILE}"`},
Resources: corev1.ResourceRequirements{
Requests: reqs,
Limits: reqs,
},
VolumeMounts: []corev1.VolumeMount{schedulingVolumeMount},
Env: []corev1.EnvVar{
corev1.EnvVar{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
corev1.EnvVar{
Name: "SCHEDULABLE_FILE",
Value: SchedulableFilePath,
},
},
},
}
}

Expand Down

0 comments on commit b8617a3

Please sign in to comment.