Skip to content

Commit

Permalink
Add initcontainer to wait for PostgreSQL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kidswiss committed Oct 22, 2024
1 parent c433fcf commit 05289ad
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/comp-functions/functions/vshnnextcloud/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 05289ad

Please sign in to comment.