Path: blob/main/install/installer/pkg/components/spicedb/schema.go
2501 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package spicedb56import (7"crypto/sha256"8"encoding/hex"9"fmt"10"path/filepath"1112spicedb_component "github.com/gitpod-io/gitpod/components/spicedb"1314"github.com/gitpod-io/gitpod/installer/pkg/common"15corev1 "k8s.io/api/core/v1"16metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"17"k8s.io/apimachinery/pkg/runtime"18)1920func bootstrap(ctx *common.RenderContext) ([]runtime.Object, error) {2122files, err := spicedb_component.GetBootstrapFiles()23if err != nil {24return nil, fmt.Errorf("failed to read bootstrap files: %w", err)25}2627cmData := make(map[string]string)28for _, f := range files {29cmData[f.Name] = f.Data30}3132return []runtime.Object{33&corev1.ConfigMap{34TypeMeta: common.TypeMetaConfigmap,35ObjectMeta: metav1.ObjectMeta{36Name: BootstrapConfigMapName,37Namespace: ctx.Namespace,38Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),39Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),40},41Data: cmData,42},43}, nil44}4546func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.VolumeMount, []string, string, error) {47var volume corev1.Volume48var mount corev1.VolumeMount49var paths []string5051mountPath := "/bootstrap"5253volume = corev1.Volume{54Name: "spicedb-bootstrap",55VolumeSource: corev1.VolumeSource{56ConfigMap: &corev1.ConfigMapVolumeSource{57LocalObjectReference: corev1.LocalObjectReference{58Name: BootstrapConfigMapName,59},60},61},62}6364mount = corev1.VolumeMount{65Name: "spicedb-bootstrap",66MountPath: mountPath,67ReadOnly: true,68}6970files, err := spicedb_component.GetBootstrapFiles()71if err != nil {72return corev1.Volume{}, corev1.VolumeMount{}, nil, "", fmt.Errorf("failed to get bootstrap files: %w", err)73}7475for _, f := range files {76paths = append(paths, filepath.Join(mountPath, f.Name))77}7879concatenated := ""80for _, f := range files {81concatenated += f.Data82}8384hasher := sha256.New()85hasher.Write([]byte(concatenated))86hash := hex.EncodeToString(hasher.Sum(nil))8788return volume, mount, paths, hash, nil89}909192