Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/helm/settings.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
"bytes"
9
"fmt"
10
"helm.sh/helm/v3/pkg/action"
11
"helm.sh/helm/v3/pkg/cli"
12
"helm.sh/helm/v3/pkg/cli/values"
13
"log"
14
"time"
15
)
16
17
type Config struct {
18
Debug bool
19
KubeConfig string
20
KubeContext string
21
Name string
22
Namespace string
23
Timeout time.Duration
24
}
25
26
type Settings struct {
27
ActionConfig *action.Configuration
28
Chart string
29
Config *Config
30
Env *cli.EnvSettings
31
Values *values.Options
32
}
33
34
func SettingsFactory(config *Config, chart string, vals *values.Options) Settings {
35
if vals == nil {
36
vals = &values.Options{}
37
}
38
39
settings := Settings{
40
ActionConfig: new(action.Configuration),
41
Config: config,
42
Env: cli.New(),
43
Chart: chart, // This can be a directory or a change name
44
Values: vals,
45
}
46
47
if config.KubeConfig != "" {
48
settings.Env.KubeConfig = config.KubeConfig
49
}
50
51
if config.KubeContext != "" {
52
settings.Env.KubeContext = config.KubeContext
53
}
54
55
if !settings.Config.Debug {
56
// If not debugging, send logs to a buffer
57
log.SetOutput(&bytes.Buffer{})
58
}
59
60
return settings
61
}
62
63
func (settings *Settings) Write(format string, v ...interface{}) {
64
format = fmt.Sprintf("[Gitpod] %s\n", format)
65
log.Output(2, fmt.Sprintf(format, v...))
66
}
67
68