-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathconfig.go
More file actions
102 lines (90 loc) · 4.9 KB
/
config.go
File metadata and controls
102 lines (90 loc) · 4.9 KB
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
95
96
97
98
99
100
101
102
package gitreceive
import (
"strings"
"time"
)
const (
builderPodTick = 100
objectStorageTick = 500
)
// Config is the envconfig (http://github.com/kelseyhightower/envconfig) compatible struct for the
// builder's git-receive hook.
type Config struct {
// k8s service discovery env vars
ControllerHost string `envconfig:"DEIS_CONTROLLER_SERVICE_HOST" required:"true"`
ControllerPort string `envconfig:"DEIS_CONTROLLER_SERVICE_PORT" required:"true"`
RegistryHost string `envconfig:"DEIS_REGISTRY_SERVICE_HOST" required:"true"`
RegistryPort string `envconfig:"DEIS_REGISTRY_SERVICE_PORT" required:"true"`
RegistryProxyPort string `envconfig:"DEIS_REGISTRY_PROXY_PORT" default:"5555"`
RegistryLocation string `envconfig:"DEIS_REGISTRY_LOCATION" default:"on-cluster"`
RegistrySecretPrefix string `envconfig:"DEIS_REGISTRY_SECRET_PREFIX" default:"private-registry"`
GitHome string `envconfig:"GIT_HOME" required:"true"`
SSHConnection string `envconfig:"SSH_CONNECTION" required:"true"`
SSHOriginalCommand string `envconfig:"SSH_ORIGINAL_COMMAND" required:"true"`
Repository string `envconfig:"REPOSITORY" required:"true"`
Username string `envconfig:"USERNAME" required:"true"`
Fingerprint string `envconfig:"FINGERPRINT" required:"true"`
PodNamespace string `envconfig:"POD_NAMESPACE" required:"true"`
StorageRegion string `envconfig:"STORAGE_REGION" default:"us-east-1"`
Debug bool `envconfig:"DEIS_DEBUG" default:"false"`
BuilderPodTickDurationMSec int `envconfig:"BUILDER_POD_TICK_DURATION" default:"100"`
BuilderPodWaitDurationMSec int `envconfig:"BUILDER_POD_WAIT_DURATION" default:"900000"` // 15 minutes
ObjectStorageTickDurationMSec int `envconfig:"OBJECT_STORAGE_TICK_DURATION" default:"500"`
ObjectStorageWaitDurationMSec int `envconfig:"OBJECT_STORAGE_WAIT_DURATION" default:"300000"` // 5 minutes
SessionIdleIntervalMsec int `envconfig:"SESSION_IDLE_INTERVAL" default:"10000"` // 10 seconds
SlugBuilderImage string `envconfig:"SLUGBUILDER_IMAGE_NAME" required:"true"`
DockerBuilderImage string `envconfig:"DOCKERBUILDER_IMAGE_NAME" required:"true"`
SlugBuilderImagePullPolicy string `envconfig:"SLUG_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
DockerBuilderImagePullPolicy string `envconfig:"DOCKER_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
StorageType string `envconfig:"BUILDER_STORAGE" default:"minio"`
BuilderPodNodeSelector string `envconfig:"BUILDER_POD_NODE_SELECTOR" default:""`
}
// App returns the application name represented by c. The app name is the same as c.Repository
// with the last '.' and beyond stripped off.
func (c Config) App() string {
li := strings.LastIndex(c.Repository, ".")
if li == -1 {
return c.Repository
}
return c.Repository[0:li]
}
// BuilderPodTickDuration returns the size of the interval used to check for
// the end of the execution of a Pod building an application.
func (c Config) BuilderPodTickDuration() time.Duration {
return time.Duration(time.Duration(c.BuilderPodTickDurationMSec) * time.Millisecond)
}
// BuilderPodWaitDuration returns the maximum time to wait for the end
// of the execution of a Pod building an application.
func (c Config) BuilderPodWaitDuration() time.Duration {
return time.Duration(time.Duration(c.BuilderPodWaitDurationMSec) * time.Millisecond)
}
// ObjectStorageTickDuration returns the size of the interval used to check for
// the end of an operation that involves the object storage.
func (c Config) ObjectStorageTickDuration() time.Duration {
return time.Duration(time.Duration(c.ObjectStorageTickDurationMSec) * time.Millisecond)
}
// ObjectStorageWaitDuration returns the maximum time to wait for the end of an
// operation that involves the object storage.
func (c Config) ObjectStorageWaitDuration() time.Duration {
return time.Duration(time.Duration(c.ObjectStorageWaitDurationMSec) * time.Millisecond)
}
// SessionIdleInterval returns the ticker interval to wait for status
func (c Config) SessionIdleInterval() time.Duration {
return time.Duration(time.Duration(c.SessionIdleIntervalMsec) * time.Millisecond)
}
// CheckDurations checks if ticks for builder and object storage are not bigger
// than the maximum duration. In case of this it will set the tick to the default.
func (c *Config) CheckDurations() {
if c.BuilderPodTickDurationMSec >= c.BuilderPodWaitDurationMSec {
c.BuilderPodTickDurationMSec = builderPodTick
}
if c.BuilderPodTickDurationMSec < builderPodTick {
c.BuilderPodTickDurationMSec = builderPodTick
}
if c.ObjectStorageTickDurationMSec >= c.ObjectStorageWaitDurationMSec {
c.ObjectStorageTickDurationMSec = objectStorageTick
}
if c.ObjectStorageTickDurationMSec < objectStorageTick {
c.ObjectStorageTickDurationMSec = objectStorageTick
}
}