Skip to content

Commit

Permalink
Merge pull request #247 from vshn/add/wait_for_db
Browse files Browse the repository at this point in the history
Add initcontainer to wait for PostgreSQL
  • Loading branch information
Kidswiss authored Oct 25, 2024
2 parents c433fcf + 05289ad commit 358271f
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 358271f

Please sign in to comment.