Skip to content

Commit

Permalink
Add init containers to wait for DNS and volumes (#255)
Browse files Browse the repository at this point in the history
Signed-off-by: Ritesh H Shukla <ritesh@minio.io>
  • Loading branch information
kerneltime committed Aug 20, 2020
1 parent 495c178 commit 3c1908d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/apis/minio.min.io/v1/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ import (
// MinIOServerName specifies the default container name for Tenant
const MinIOServerName = "minio"

// MinIODNSInitContainer Init Container for DNS
const MinIODNSInitContainer = "minio-dns-wait"

// MinIOVolumeInitContainer Init Container for DNS
const MinIOVolumeInitContainer = "minio-vol-wait"

// KESContainerName specifies the default container name for KES
const KESContainerName = "kes"

// ConsoleContainerName specifies the default container name for Console
const ConsoleContainerName = "console"

// InitContainerImage name for init container.
const InitContainerImage = "busybox:1.32"

// MinIO Related Names

// MinIOStatefulSetNameForZone returns the name for MinIO StatefulSet
Expand Down
48 changes: 47 additions & 1 deletion pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,48 @@ func zoneMinioServerContainer(t *miniov1.Tenant, wsSecret *v1.Secret, zone *mini
}
}

// Builds the MinIO init container to check for mounts.
func zoneMinIOInitContainerValidateMounts(t *miniov1.Tenant, zone *miniov1.Zone, templates []v1.PersistentVolumeClaim, volumes []v1.Volume) v1.Container {
command := []string{"/bin/sh", "-c"}
mounts := volumeMounts(t, zone)
var s string
for _, m := range mounts {
s = s + fmt.Sprintf("until /bin/stat %s; do sleep 2; done;", m.MountPath)
}
//Explicitly check the certs/
if t.AutoCert() || t.ExternalCert() {
s = s + "echo Wait till certs can be read;"
s = s + "until /bin/cat /tmp/certs/private.key > /dev/null; do sleep 2; done;"
s = s + "until /bin/cat /tmp/certs/public.crt > /dev/null; do sleep 2; done;"
s = s + "until /bin/cat /tmp/certs/CAs/public.crt > /dev/null; do sleep 2; done;"
}

args := []string{s}

return corev1.Container{
Name: miniov1.MinIOVolumeInitContainer,
Image: miniov1.InitContainerImage,
Command: command,
Args: args,
VolumeMounts: volumeMounts(t, zone),
}
}

// Builds the MinIO init container to wait for DNS to be ready.
func zoneMinIOInitContainerWaitForDNS(t *miniov1.Tenant, zone *appsv1.StatefulSet) v1.Container {
command := []string{"/bin/sh", "-c"}
args := []string{
fmt.Sprintf("echo Wait for service; until nslookup %[1]s ; do echo waiting for %[1]s; sleep 2; done; ",
t.MinIOServerHost()),
}
return corev1.Container{
Name: miniov1.MinIODNSInitContainer,
Image: miniov1.InitContainerImage,
Command: command,
Args: args,
}
}

// GetContainerArgs returns the arguments that the MinIO container receives
func GetContainerArgs(t *miniov1.Tenant, hostsTemplate string) []string {
var args []string
Expand Down Expand Up @@ -361,7 +403,6 @@ func NewForMinIOZone(t *miniov1.Tenant, wsSecret *v1.Secret, zone *miniov1.Zone,
}

containers := []corev1.Container{zoneMinioServerContainer(t, wsSecret, zone, hostsTemplate)}

ss := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: t.Namespace,
Expand Down Expand Up @@ -412,5 +453,10 @@ func NewForMinIOZone(t *miniov1.Tenant, wsSecret *v1.Secret, zone *miniov1.Zone,
ss.Spec.VolumeClaimTemplates = append(ss.Spec.VolumeClaimTemplates, pvClaim)
}
}
initContainers := []corev1.Container{
zoneMinIOInitContainerValidateMounts(t, zone, ss.Spec.VolumeClaimTemplates, ss.Spec.Template.Spec.Volumes),
zoneMinIOInitContainerWaitForDNS(t, ss),
}
ss.Spec.Template.Spec.InitContainers = initContainers
return ss
}

0 comments on commit 3c1908d

Please sign in to comment.