-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
149 lines (131 loc) · 5.31 KB
/
config.go
File metadata and controls
149 lines (131 loc) · 5.31 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package api
import (
"bytes"
"fmt"
"text/template"
)
// ConfigTags is the key, value for tag
type ConfigTags map[string]interface{}
// ConfigValues is the key, value for env
type ConfigValues map[string]interface{}
// ConfigSet is the definition of POST /v2/apps/<app id>/config/.
type ConfigSet struct {
Values ConfigValues `json:"values"`
TypedValues map[string]ConfigValues `json:"typed_values"`
}
// ConfigUnset is the definition of POST /v2/apps/<app id>/config/.
type ConfigUnset struct {
Values ConfigValues `json:"values"`
TypedValues map[string]ConfigValues `json:"typed_values"`
}
// Config is the structure of an app's config.
type Config struct {
// Owner is the app owner. It cannot be updated with config.Set(). See app.Transfer().
Owner string `json:"owner,omitempty"`
// App is the app name. It cannot be updated at all right now.
App string `json:"app,omitempty"`
// Values are exposed as environment variables to the app.
Values ConfigValues `json:"values,omitempty"`
// Typed values are exposed as environment variables to the app.
TypedValues map[string]ConfigValues `json:"typed_values,omitempty"`
// Limits is used to set process resources limits. The key is the process name
// and the value is a limit plan. Ex: std1.xlarge.c1m1
Limits map[string]interface{} `json:"limits,omitempty"`
// Timeout is used to set termination grace period. The key is the process name
// and the value is a number in seconds, e.g. 30
Timeout map[string]interface{} `json:"termination_grace_period,omitempty"`
// Healthcheck is map of healthchecks for each process that the application uses.
Healthcheck map[string]*Healthchecks `json:"healthcheck,omitempty"`
// Tags restrict applications to run on k8s nodes with that label.
Tags map[string]ConfigTags `json:"tags,omitempty"`
// Registry is a key-value pair to provide authentication for container registries.
// The key is the username and the value is the password.
Registry map[string]interface{} `json:"registry,omitempty"`
// Created is the time that the application was created and cannot be updated.
Created string `json:"created,omitempty"`
// Updated is the last time the configuration was changed and cannot be updated.
Updated string `json:"updated,omitempty"`
// UUID is a unique string reflecting the configuration in its current state.
// It changes every time the configuration is changed and cannot be updated.
UUID string `json:"uuid,omitempty"`
}
// ConfigHookRequest defines the request for configuration from the config hook.
type ConfigHookRequest struct {
User string `json:"receive_user"`
App string `json:"receive_repo"`
}
// Healthchecks is a map of healthcheck probes.
// The valid values are "startupProbe" "livenessProbe" and "readinessProbe".
type Healthchecks map[string]*Healthcheck
// Healthcheck is the structure for an application healthcheck.
// Healthchecks only need to provide information about themselves.
// All the information is pushed to the server and handled by kubernetes.
type Healthcheck struct {
InitialDelaySeconds int `json:"initialDelaySeconds"`
TimeoutSeconds int `json:"timeoutSeconds"`
PeriodSeconds int `json:"periodSeconds"`
SuccessThreshold int `json:"successThreshold"`
FailureThreshold int `json:"failureThreshold"`
Exec *ExecProbe `json:"exec,omitempty"`
HTTPGet *HTTPGetProbe `json:"httpGet,omitempty"`
TCPSocket *TCPSocketProbe `json:"tcpSocket,omitempty"`
}
// String displays the HealthcheckHTTPGetProbe in a readable format.
func (h Healthcheck) String() string {
var doc bytes.Buffer
tmpl, err := template.New("healthcheck").Parse(`Initial Delay (seconds): {{.InitialDelaySeconds}}
Timeout (seconds): {{.TimeoutSeconds}}
Period (seconds): {{.PeriodSeconds}}
Success Threshold: {{.SuccessThreshold}}
Failure Threshold: {{.FailureThreshold}}
Exec Probe: {{or .Exec "N/A"}}
HTTP GET Probe: {{or .HTTPGet "N/A"}}
TCP Socket Probe: {{or .TCPSocket "N/A"}}`)
if err != nil {
panic(err)
}
if err := tmpl.Execute(&doc, h); err != nil {
panic(err)
}
return doc.String()
}
// KVPair is a key/value pair used to parse values from
// strings into a formal structure.
type KVPair struct {
Name string `json:"name"`
Value string `json:"value"`
}
func (k KVPair) String() string {
return k.Name + "=" + k.Value
}
// ExecProbe executes a command within a Pod.
type ExecProbe struct {
Command []string `json:"command"`
}
// String displays the ExecProbe in a readable format.
func (e ExecProbe) String() string {
return fmt.Sprintf(`Command=%s`, e.Command)
}
// HTTPGetProbe performs an HTTP GET request to the Pod
// with the given path, port and headers.
type HTTPGetProbe struct {
Path string `json:"path,omitempty"`
Port int `json:"port"`
HTTPHeaders []*KVPair `json:"httpHeaders,omitempty"`
}
// String displays the HTTPGetProbe in a readable format.
func (h HTTPGetProbe) String() string {
return fmt.Sprintf(`Path="%s" Port=%d HTTPHeaders=%s`,
h.Path,
h.Port,
h.HTTPHeaders)
}
// TCPSocketProbe attempts to open a socket connection to the
// Pod on the given port.
type TCPSocketProbe struct {
Port int `json:"port"`
}
// String displays the TCPSocketProbe in a readable format.
func (t TCPSocketProbe) String() string {
return fmt.Sprintf("Port=%d", t.Port)
}