-
Notifications
You must be signed in to change notification settings - Fork 16
/
options.go
94 lines (77 loc) · 3.48 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package options
import (
"fmt"
"os"
"reflect"
)
type Options struct {
ComparableOptions
KubernetesContext string `json:"-"`
KubernetesConfig string `json:"-"`
KubernetesNamespace string `json:"-"`
KubectlPath string `json:"-"`
PodTimeout string `json:"-"`
}
type ComparableOptions struct {
DevContainerID string `json:"devcontainerId,omitempty"`
KubernetesPullSecretsEnabled string `json:"kubernetesPullSecretsEnabled,omitempty"`
CreateNamespace string `json:"createNamespace,omitempty"`
ClusterRole string `json:"clusterRole,omitempty"`
ServiceAccount string `json:"serviceAccount,omitempty"`
HelperImage string `json:"helperImage,omitempty"`
HelperResources string `json:"helperResources,omitempty"`
InactivityTimeout string `json:"inactivityTimeout,omitempty"`
StorageClass string `json:"storageClass,omitempty"`
DiskSize string `json:"diskSize,omitempty"`
PvcAccessMode string `json:"pvcAccessMode,omitempty"`
NodeSelector string `json:"nodeSelector,omitempty"`
Resources string `json:"resources,omitempty"`
WorkspaceVolumeMount string `json:"workspaceVolumeMount,omitempty"`
PodManifestTemplate string `json:"podManifestTemplate,omitempty"`
ArchDetectionPodManifestTemplate string `json:"archDetectionPodManifestTemplate,omitempty"`
Labels string `json:"labels,omitempty"`
DangerouslyOverrideImage string `json:"dangerouslyOverrideImage,omitempty"`
StrictSecurity bool `json:"strictSecurity,omitEmpty"`
}
func FromEnv() (*Options, error) {
retOptions := &Options{}
var err error
retOptions.DevContainerID, err = fromEnvOrError("DEVCONTAINER_ID")
if err != nil {
return nil, err
}
retOptions.DiskSize = os.Getenv("DISK_SIZE")
retOptions.KubernetesContext = os.Getenv("KUBERNETES_CONTEXT")
retOptions.KubernetesConfig = os.Getenv("KUBERNETES_CONFIG")
retOptions.KubernetesNamespace = os.Getenv("KUBERNETES_NAMESPACE")
retOptions.KubernetesPullSecretsEnabled = os.Getenv("KUBERNETES_PULL_SECRETS_ENABLED")
retOptions.CreateNamespace = os.Getenv("CREATE_NAMESPACE")
retOptions.ClusterRole = os.Getenv("CLUSTER_ROLE")
retOptions.ServiceAccount = os.Getenv("SERVICE_ACCOUNT")
retOptions.HelperImage = os.Getenv("HELPER_IMAGE")
retOptions.HelperResources = os.Getenv("HELPER_RESOURCES")
retOptions.KubectlPath = os.Getenv("KUBECTL_PATH")
retOptions.InactivityTimeout = os.Getenv("INACTIVITY_TIMEOUT")
retOptions.StorageClass = os.Getenv("STORAGE_CLASS")
retOptions.PvcAccessMode = os.Getenv("PVC_ACCESS_MODE")
retOptions.NodeSelector = os.Getenv("NODE_SELECTOR")
retOptions.Resources = os.Getenv("RESOURCES")
retOptions.PodManifestTemplate = os.Getenv("POD_MANIFEST_TEMPLATE")
retOptions.Labels = os.Getenv("LABELS")
retOptions.PodTimeout = os.Getenv("POD_TIMEOUT")
retOptions.DangerouslyOverrideImage = os.Getenv("DANGEROUSLY_OVERRIDE_IMAGE")
retOptions.StrictSecurity = os.Getenv("STRICT_SECURITY") == "true"
retOptions.ArchDetectionPodManifestTemplate = os.Getenv("ARCH_DETECTION_POD_MANIFEST_TEMPLATE")
retOptions.WorkspaceVolumeMount = os.Getenv("WORKSPACE_VOLUME_MOUNT")
return retOptions, nil
}
func Equal(a *ComparableOptions, b *ComparableOptions) bool {
return reflect.DeepEqual(a, b)
}
func fromEnvOrError(name string) (string, error) {
val := os.Getenv(name)
if val == "" {
return "", fmt.Errorf("couldn't find option %s in environment, please make sure %s is defined", name, name)
}
return val, nil
}