generated from broadinstitute/golang-project-template
/
reloader.go
65 lines (53 loc) · 1.76 KB
/
reloader.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
package linter
import "strings"
// if "true", reloader will reload on all CMs/Secrets used by the Deployment/StatefulSet
const autoAnnotation = "reloader.stakater.com/auto"
// if "true", reloader will reload on CMs/Secrets used by the Deployment/StatefulSet that have a "match" annotation.
// (Yale adds this annotation to secrets it creates)
const searchAnnotation = "reloader.stakater.com/search"
// reloader will reload on a configured list of Secrets used by the Deployment/StatefulSet
const secretListAnnotation = "secret.reloader.stakater.com/reload"
// reloaderCfg describes how reloader is configured to manage a given resource
type reloaderCfg struct {
auto bool
search bool
list map[string]struct{}
}
func (r reloaderCfg) reloadsOnSecret(secretName string) (string, bool) {
if r.auto {
return "has annotation " + autoAnnotation, true
}
if r.search {
return "has annotation " + searchAnnotation, true
}
_, exists := r.list[secretName]
if exists {
return "annotation " + secretListAnnotation + " includes " + secretName, true
}
return "", false
}
// parseReloaderAnnotations parses the reloader annotations on a resource and returns a reloaderCfg
func parseReloaderAnnotations(annotations map[string]string) reloaderCfg {
parsed := reloaderCfg{
auto: false,
search: false,
list: make(map[string]struct{}),
}
auto, exists := annotations[autoAnnotation]
if exists && auto == "true" {
parsed.auto = true
}
search, exists := annotations[searchAnnotation]
if exists && search == "true" {
parsed.search = true
}
list, exists := annotations[secretListAnnotation]
if exists {
secrets := strings.Split(list, ",")
for _, secret := range secrets {
secret = strings.TrimSpace(secret)
parsed.list[secret] = struct{}{}
}
}
return parsed
}