Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/spicedb/schema.go
2501 views
1
// Copyright (c) 2023 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 spicedb
6
7
import (
8
"crypto/sha256"
9
"encoding/hex"
10
"fmt"
11
"path/filepath"
12
13
spicedb_component "github.com/gitpod-io/gitpod/components/spicedb"
14
15
"github.com/gitpod-io/gitpod/installer/pkg/common"
16
corev1 "k8s.io/api/core/v1"
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
"k8s.io/apimachinery/pkg/runtime"
19
)
20
21
func bootstrap(ctx *common.RenderContext) ([]runtime.Object, error) {
22
23
files, err := spicedb_component.GetBootstrapFiles()
24
if err != nil {
25
return nil, fmt.Errorf("failed to read bootstrap files: %w", err)
26
}
27
28
cmData := make(map[string]string)
29
for _, f := range files {
30
cmData[f.Name] = f.Data
31
}
32
33
return []runtime.Object{
34
&corev1.ConfigMap{
35
TypeMeta: common.TypeMetaConfigmap,
36
ObjectMeta: metav1.ObjectMeta{
37
Name: BootstrapConfigMapName,
38
Namespace: ctx.Namespace,
39
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
40
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
41
},
42
Data: cmData,
43
},
44
}, nil
45
}
46
47
func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.VolumeMount, []string, string, error) {
48
var volume corev1.Volume
49
var mount corev1.VolumeMount
50
var paths []string
51
52
mountPath := "/bootstrap"
53
54
volume = corev1.Volume{
55
Name: "spicedb-bootstrap",
56
VolumeSource: corev1.VolumeSource{
57
ConfigMap: &corev1.ConfigMapVolumeSource{
58
LocalObjectReference: corev1.LocalObjectReference{
59
Name: BootstrapConfigMapName,
60
},
61
},
62
},
63
}
64
65
mount = corev1.VolumeMount{
66
Name: "spicedb-bootstrap",
67
MountPath: mountPath,
68
ReadOnly: true,
69
}
70
71
files, err := spicedb_component.GetBootstrapFiles()
72
if err != nil {
73
return corev1.Volume{}, corev1.VolumeMount{}, nil, "", fmt.Errorf("failed to get bootstrap files: %w", err)
74
}
75
76
for _, f := range files {
77
paths = append(paths, filepath.Join(mountPath, f.Name))
78
}
79
80
concatenated := ""
81
for _, f := range files {
82
concatenated += f.Data
83
}
84
85
hasher := sha256.New()
86
hasher.Write([]byte(concatenated))
87
hash := hex.EncodeToString(hasher.Sum(nil))
88
89
return volume, mount, paths, hash, nil
90
}
91
92