Skip to content

[installer]: configure and validate the external database #6716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions installer/pkg/components/database/cloudsql/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
package cloudsql

const (
Component = "cloudsqlproxy"
dbSessionsImage = "mysql"
dbSessionsTag = "5.7.34"
ImageRepo = "b.gcr.io/cloudsql-docker"
ImageName = "gce-proxy"
ImageVersion = "1.11"
initScriptDir = "init"
Port = 3306
SQLInitScripts = "db-init-scripts"
Component = "cloudsqlproxy"
ImageRepo = "b.gcr.io/cloudsql-docker"
ImageName = "gce-proxy"
ImageVersion = "1.11"
Port = 3306
)
8 changes: 5 additions & 3 deletions installer/pkg/components/database/cloudsql/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

package cloudsql

import "github.com/gitpod-io/gitpod/installer/pkg/common"
import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
dbinit "github.com/gitpod-io/gitpod/installer/pkg/components/database/init"
)

var Objects = common.CompositeRenderFunc(
configmap,
deployment,
job,
dbinit.Objects,
common.DefaultServiceAccount(Component),
common.GenerateService(Component, map[string]common.ServicePort{
Component: {
Expand Down
14 changes: 14 additions & 0 deletions installer/pkg/components/database/external/objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package external

import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
dbinit "github.com/gitpod-io/gitpod/installer/pkg/components/database/init"
)

var Objects = common.CompositeRenderFunc(
dbinit.Objects,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cloudsql
package init

import (
"embed"
Expand All @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

//go:embed init/*.sql
//go:embed files/*.sql
var initScriptFiles embed.FS

func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
Expand Down Expand Up @@ -42,7 +42,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
&corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: SQLInitScripts,
Name: sqlInitScripts,
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
},
Expand Down
13 changes: 13 additions & 0 deletions installer/pkg/components/database/init/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package init

const (
Component = "dbinit"
dbSessionsImage = "mysql"
dbSessionsTag = "5.7.34"
initScriptDir = "files"
sqlInitScripts = "db-init-scripts"
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// This runs the init scripts in a non-inCluster DB instance

package cloudsql
package init

import (
"fmt"
Expand Down Expand Up @@ -35,9 +35,9 @@ func job(ctx *common.RenderContext) ([]runtime.Object, error) {
ServiceAccountName: Component,
EnableServiceLinks: pointer.Bool(false),
Volumes: []corev1.Volume{{
Name: SQLInitScripts,
Name: sqlInitScripts,
VolumeSource: corev1.VolumeSource{ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{Name: SQLInitScripts},
LocalObjectReference: corev1.LocalObjectReference{Name: sqlInitScripts},
}},
}},
// The init container is designed to emulate Helm hooks
Expand All @@ -55,7 +55,7 @@ func job(ctx *common.RenderContext) ([]runtime.Object, error) {
"mysql -h $DB_HOST --port $DB_PORT -u $DB_USERNAME -p$DB_PASSWORD < /db-init-scripts/init.sql",
},
VolumeMounts: []corev1.VolumeMount{{
Name: SQLInitScripts,
Name: sqlInitScripts,
MountPath: "/db-init-scripts",
ReadOnly: true,
}},
Expand Down
15 changes: 15 additions & 0 deletions installer/pkg/components/database/init/objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package init

import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
)

var Objects = common.CompositeRenderFunc(
configmap,
job,
common.DefaultServiceAccount(Component),
)
8 changes: 8 additions & 0 deletions installer/pkg/components/database/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package database
import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/components/database/cloudsql"
"github.com/gitpod-io/gitpod/installer/pkg/components/database/external"
"github.com/gitpod-io/gitpod/installer/pkg/components/database/incluster"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
Expand All @@ -16,6 +17,10 @@ func cloudSqlEnabled(cfg *common.RenderContext) bool {
return !pointer.BoolDeref(cfg.Config.Database.InCluster, false) && cfg.Config.Database.CloudSQL != nil
}

func externalEnabled(cfg *common.RenderContext) bool {
return !pointer.BoolDeref(cfg.Config.Database.InCluster, false) && cfg.Config.Database.External != nil
}

func inClusterEnabled(cfg *common.RenderContext) bool {
return pointer.BoolDeref(cfg.Config.Database.InCluster, false)
}
Expand All @@ -28,6 +33,9 @@ var Objects = common.CompositeRenderFunc(
if cloudSqlEnabled(cfg) {
return cloudsql.Objects(cfg)
}
if externalEnabled(cfg) {
return external.Objects(cfg)
}
return nil, nil
}),
)
Expand Down
5 changes: 5 additions & 0 deletions installer/pkg/config/v1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@ func (v version) ClusterValidation(rcfg interface{}) cluster.ValidationChecks {
res = append(res, cluster.CheckSecret(secretName, cluster.CheckSecretRequiredData("credentials.json", "encryptionKeys", "password", "username")))
}

if cfg.Database.External != nil {
secretName := cfg.Database.External.Certificate.Name
res = append(res, cluster.CheckSecret(secretName, cluster.CheckSecretRequiredData("encryptionKeys", "host", "password", "port", "username")))
}

return res
}