Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/helm/common.go
2500 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 helm
6
7
import (
8
"fmt"
9
"os"
10
"strings"
11
12
"github.com/gitpod-io/gitpod/installer/pkg/common"
13
)
14
15
// KeyValue ensure that a key/value pair is correctly formatted for Values
16
func KeyValue(key string, value string) string {
17
return fmt.Sprintf("%s=%s", key, value)
18
}
19
20
// KeyValueArray ensure that a key/value pair is correctly formatted for Arrays
21
func KeyValueArray(key string, arr []string) string {
22
// Helm array nomenclature
23
return KeyValue(key, fmt.Sprintf("{%s}", strings.Join(arr, ",")))
24
}
25
26
// KeyFileValue ensure that a key/value pair is correctly formatted for FileValues
27
func KeyFileValue(key string, data []byte) (string, error) {
28
dir, err := os.MkdirTemp("", "helm")
29
if err != nil {
30
return "", err
31
}
32
33
filePath := fmt.Sprintf("%s/file-value", dir)
34
err = os.WriteFile(filePath, data, 0644)
35
if err != nil {
36
return "", err
37
}
38
39
return KeyValue(key, filePath), nil
40
}
41
42
type PkgConfig func(cfg *common.RenderContext) (*common.HelmConfig, error)
43
44