Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-daemon/pkg/content/config.go
2500 views
1
// Copyright (c) 2020 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 content
6
7
import (
8
"encoding/json"
9
"strings"
10
11
"github.com/gitpod-io/gitpod/common-go/util"
12
cntntcfg "github.com/gitpod-io/gitpod/content-service/api/config"
13
"github.com/gitpod-io/gitpod/ws-daemon/api"
14
"golang.org/x/xerrors"
15
)
16
17
// Config configures the workspace content service
18
type Config struct {
19
// WorkingArea is the location on-disk where we create workspaces
20
WorkingArea string `json:"workingArea"`
21
22
// WorkingAreaNode is the location on-disk where we create workspaces,
23
// as seen from the root/node mount namespace. This is the same path as WorkingArea,
24
// except not from within the container, but on the node (the "other side" of the hostPath volume
25
// of the ws-daemon pod).
26
WorkingAreaNode string `json:"workingAreaNode"`
27
28
// TmpDir is the temp working diretory for creating tar files during upload
29
TmpDir string `json:"tempDir"`
30
31
// Storage is some form of permanent file store to which we back up workspaces
32
Storage cntntcfg.StorageConfig `json:"storage"`
33
34
// Backup configures the behaviour of ws-daemon during backup
35
Backup BackupConfig `json:"backup,omitempty"`
36
37
// UserNamespaces configures the behaviour of the user-namespace support
38
UserNamespaces UserNamespacesConfig `json:"userNamespaces,omitempty"`
39
40
// Initializer configures the isolated content initializer runtime
41
Initializer InitializerConfig `json:"initializer"`
42
}
43
44
type BackupConfig struct {
45
// Timeout configures the maximum time the remote storage upload can take
46
// per attempt. Defaults to 10 minutes.
47
Timeout util.Duration `json:"timeout,omitempty"`
48
49
// Attempts configures how many backup attempts we will make.
50
// Detaults to 3
51
Attempts int `json:"attempts"`
52
53
// Period is the time between regular workspace backups
54
Period util.Duration `json:"period"`
55
}
56
57
type UserNamespacesConfig struct {
58
FSShift FSShiftMethod `json:"fsShift"`
59
}
60
61
type FSShiftMethod api.FSShiftMethod
62
63
// MarshalJSON marshals the api.FSShiftMethod to the api.FSShiftMethod_value
64
func (m FSShiftMethod) MarshalJSON() ([]byte, error) {
65
methodInt := int32(m)
66
v, ok := api.FSShiftMethod_name[methodInt]
67
if !ok {
68
return nil, xerrors.Errorf("invalid shift method: %i", methodInt)
69
}
70
return json.Marshal(v)
71
}
72
73
// UnmarshalJSON unmarshals the lowercase shift method string as defined in
74
// api.FSShiftMethod_value to api.FSShiftMethod
75
func (m *FSShiftMethod) UnmarshalJSON(data []byte) error {
76
input := strings.ToUpper(strings.Trim(string(data), "\""))
77
v, ok := api.FSShiftMethod_value[input]
78
if !ok {
79
return xerrors.Errorf("invalid shift method: %v", input)
80
}
81
*m = FSShiftMethod(v)
82
return nil
83
}
84
85
type InitializerConfig struct {
86
// Command is the path to content-initializer executable
87
Command string `json:"command"`
88
89
// Args are additional arguments to pass to the CI runtime
90
Args []string `json:"args"`
91
}
92
93