Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/database/init/configmap.go
2504 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package init
6
7
import (
8
"embed"
9
"fmt"
10
"io/fs"
11
12
"github.com/gitpod-io/gitpod/installer/pkg/common"
13
corev1 "k8s.io/api/core/v1"
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
"k8s.io/apimachinery/pkg/runtime"
16
)
17
18
//go:embed files/*.sql
19
var initScriptFiles embed.FS
20
21
func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
22
if disableMigration := common.IsDatabaseMigrationDisabled(ctx); disableMigration {
23
return nil, nil
24
}
25
26
initScripts, err := fs.ReadDir(initScriptFiles, initScriptDir)
27
if err != nil {
28
return nil, err
29
}
30
31
initScriptData := ""
32
33
for _, script := range initScripts {
34
file, err := fs.ReadFile(initScriptFiles, fmt.Sprintf("%s/%s", initScriptDir, script.Name()))
35
36
if err != nil {
37
return nil, err
38
}
39
40
fileStr := string(file)
41
42
// Add the file name for debugging purposes
43
initScriptData += fmt.Sprintf("-- %s\n\n%s", script.Name(), fileStr)
44
}
45
46
return []runtime.Object{
47
&corev1.ConfigMap{
48
TypeMeta: common.TypeMetaConfigmap,
49
ObjectMeta: metav1.ObjectMeta{
50
Name: sqlInitScripts,
51
Namespace: ctx.Namespace,
52
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
53
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
54
},
55
Data: map[string]string{
56
"init.sql": initScriptData,
57
},
58
},
59
}, nil
60
}
61
62