-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathconfig_test.go
119 lines (110 loc) · 3.13 KB
/
config_test.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
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
package cfg
import (
"os"
"testing"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
)
func TestEnvVars(t *testing.T) {
defer unsetEnv()
os.Setenv("IMAGES", "che-theia=quay.io/eclipse/che-theia:nightly")
os.Setenv("CACHING_INTERVAL_HOURS", "5")
type testcase struct {
name string
env map[string]string
want Config
}
cases := []testcase{
{
name: "default",
env: map[string]string{},
want: Config{
DaemonsetName: "kubernetes-image-puller",
Namespace: "k8s-image-puller",
Images: map[string]string{
"che-theia": "quay.io/eclipse/che-theia:nightly",
},
CachingMemRequest: "1Mi",
CachingMemLimit: "5Mi",
CachingCpuRequest: ".05",
CachingCpuLimit: ".2",
CachingInterval: 5,
NodeSelector: map[string]string{},
ImagePullSecrets: []string{},
Affinity: &v1.Affinity{},
ImagePullerImage: "quay.io/eclipse/kubernetes-image-puller:next",
Tolerations: []v1.Toleration{},
},
},
{
name: "overrides",
env: map[string]string{
"DAEMONSET_NAME": "custom-daemonset-name",
"NAMESPACE": "my-namespace",
"NODE_SELECTOR": "{\"type\": \"compute\"}",
"CACHING_CPU_REQUEST": ".055",
"IMAGE_PULL_SECRETS": "secret1; secret2",
"AFFINITY": `{"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"kubernetes.io/e2e-az-name","operator":"In","values":["e2e-az1","e2e-az2"]}]}]}}}`,
"KIP_IMAGE": "quay.io/my-repo/kubernetes-image-puller:next",
"TOLERATIONS": `[{"effect":"NoSchedule","key":"app","operator":"Equal","value": "prod"}]`,
},
want: Config{
DaemonsetName: "custom-daemonset-name",
Namespace: "my-namespace",
Images: map[string]string{
"che-theia": "quay.io/eclipse/che-theia:nightly",
},
CachingMemRequest: "1Mi",
CachingMemLimit: "5Mi",
CachingCpuRequest: ".055",
CachingCpuLimit: ".2",
CachingInterval: 5,
NodeSelector: map[string]string{
"type": "compute",
},
ImagePullSecrets: []string{"secret1", "secret2"},
Affinity: &v1.Affinity{
NodeAffinity: &v1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
{
MatchExpressions: []v1.NodeSelectorRequirement{
{
Key: "kubernetes.io/e2e-az-name",
Operator: v1.NodeSelectorOpIn,
Values: []string{"e2e-az1", "e2e-az2"},
},
},
},
},
},
},
},
ImagePullerImage: "quay.io/my-repo/kubernetes-image-puller:next",
Tolerations: []v1.Toleration{
{
Key: "app",
Operator: "Equal",
Value: "prod",
Effect: "NoSchedule",
},
},
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
for k, v := range c.env {
os.Setenv(k, v)
}
cfg := GetConfig()
if d := cmp.Diff(c.want, cfg); d != "" {
t.Errorf("Diff (-want, +got): %s", d)
}
})
}
}
func unsetEnv() {
os.Unsetenv("IMAGES")
os.Unsetenv("CACHING_INTERVAL_HOURS")
}