From 05289ad48fa5e2647e56e3e49eb634e4512d8425 Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Tue, 22 Oct 2024 11:02:24 +0200 Subject: [PATCH] Add initcontainer to wait for PostgreSQL It was possible that Nextcloud started without PostgreSQL being ready. This new initcontainer will make sure that PostgreSQL is reachable before attempting to start the main Nextcloud container. --- .../functions/vshnnextcloud/deploy.go | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/comp-functions/functions/vshnnextcloud/deploy.go b/pkg/comp-functions/functions/vshnnextcloud/deploy.go index 92c7b1724..b0fd73a64 100644 --- a/pkg/comp-functions/functions/vshnnextcloud/deploy.go +++ b/pkg/comp-functions/functions/vshnnextcloud/deploy.go @@ -242,6 +242,7 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS } externalDb := map[string]any{} + extraInitContainers := []map[string]any{} if comp.Spec.Parameters.Service.UseExternalPostgreSQL { cd, err := svc.GetObservedComposedResourceConnectionDetails(comp.GetName() + pgInstanceNameSuffix) @@ -264,6 +265,24 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS "user": string(cd[vshnpostgres.PostgresqlUser]), "password": string(cd[vshnpostgres.PostgresqlPassword]), } + + extraInitContainers = []map[string]any{ + { + "name": "dbchecker", + "image": "docker.io/busybox", + "command": []string{ + "sh", + "-c", + `echo 'Waiting for Database to become ready...' + + until printf "." && nc -z -w 2 ` + string(cd[vshnpostgres.PostgresqlHost]) + " " + string(cd[vshnpostgres.PostgresqlPort]) + `; do + sleep 2; + done; + + echo 'Database OK ✓'`, + }, + }, + } } configString := svc.Config.Data["isOpenshift"] @@ -297,8 +316,9 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS "configs": map[string]string{ "vshn-nextcloud.config.php": updatedNextcloudConfig, }, - "containerPort": 8080, - "podSecurityContext": securityContext, + "extraInitContainers": extraInitContainers, + "containerPort": 8080, + "podSecurityContext": securityContext, "extraVolumes": []map[string]any{ { "name": "apache-config",