-
Notifications
You must be signed in to change notification settings - Fork 9
/
hub_test.go
178 lines (169 loc) · 4.39 KB
/
hub_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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package helmtest
import (
"testing"
"github.com/gruntwork-io/terratest/modules/helm"
appsV1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/api/networking/v1beta1"
)
func TestHub(t *testing.T) {
var (
objects []interface{}
checks = map[string]bool{
"ingress": false,
"metricsEndpoint": false,
"dash limits": false,
"etcd limits": false,
"loki logging": false,
"docker socket": false,
"pachd service type": false,
"etcd prometheus port": false,
"etcd prometheus scrape": false,
"etcd storage class": false,
}
err error
)
if objects, err = manifestToObjects(helm.RenderTemplate(t,
&helm.Options{
ValuesFiles: []string{"../examples/hub-values.yaml"},
},
"../pachyderm/", "pachd", nil)); err != nil {
t.Fatalf("could not render templates to objects: %v", err)
}
for _, object := range objects {
switch object := object.(type) {
case *v1beta1.Ingress:
for _, rule := range object.Spec.Rules {
if rule.Host == "dash.test" {
checks["ingress"] = true
}
}
case *appsV1.Deployment:
switch object.Name {
case "pachd":
for _, cc := range object.Spec.Template.Spec.Containers {
if cc.Name != "pachd" {
continue
}
for _, v := range cc.Env {
switch v.Name {
case "METRICS_ENDPOINT":
expected := "https://metrics.test/api/v1/metrics"
if v.Value != expected {
t.Errorf("metrics endpoint %q ≠ %q", v.Value, expected)
}
checks["metricsEndpoint"] = true
case "LOKI_LOGGING":
if v.Value != "true" {
t.Error("Loki logging should be enabled")
}
checks["loki logging"] = true
case "NO_EXPOSE_DOCKER_SOCKET":
if v.Value != "false" {
t.Error("Docker socket should be exposed")
}
checks["docker socket"] = true
}
}
}
case "dash":
for _, cc := range object.Spec.Template.Spec.Containers {
if cc.Name != "dash" {
continue
}
if len(cc.Resources.Limits) > 0 {
t.Errorf("dash should have no resource limits")
}
checks["dash limits"] = true
}
}
case *v1.Secret:
if object.Name != "dash-tls" {
continue
}
t.Errorf("there should be no dash-tls secret")
case *v1.Service:
switch object.Name {
case "pachd":
if object.Spec.Type != "ClusterIP" {
t.Errorf("pachd service type should be \"ClusterIP\", not %q", object.Spec.Type)
}
checks["pachd service type"] = true
case "etcd":
for k, v := range object.Annotations {
switch k {
case "prometheus.io/port":
if v != "2379" {
t.Errorf("Promethus port set to %q instead of 2379", v)
}
checks["etcd prometheus port"] = true
case "prometheus.io/scrape":
if v != "true" {
t.Errorf("Prometheus scrape set to %q instead of true", v)
}
checks["etcd prometheus scrape"] = true
}
}
case "pachd-lb":
expectedPorts := map[string]*struct {
port int
found bool
}{
"api-grpc-port": {
port: 31400,
found: false,
},
"api-http-port": {
port: 30652,
found: false,
},
"s3gateway-port": {
port: 30600,
found: false,
},
}
for _, port := range object.Spec.Ports {
ep, ok := expectedPorts[port.Name]
if !ok {
t.Errorf("did not find port %q in expected ports", port.Name)
continue
}
if ep.port != int(port.Port) {
t.Errorf("wanted %q, for port: %q, Got: %d", ep.port, port.Name, port.Port)
continue
}
ep.found = true
}
for portName, check := range expectedPorts {
if !check.found {
t.Errorf("expected port: %q, not found", portName)
}
}
}
case *appsV1.StatefulSet:
if object.Name != "etcd" {
continue
}
for _, pvc := range object.Spec.VolumeClaimTemplates {
if *pvc.Spec.StorageClassName != "ssd-storage-class" {
t.Errorf("storage class is %q, not ssd-storage-class", *pvc.Spec.StorageClassName)
}
checks["etcd storage class"] = true
}
for _, cc := range object.Spec.Template.Spec.Containers {
if cc.Name != "etcd" {
continue
}
if len(cc.Resources.Limits) > 0 {
t.Errorf("etcd should have no resource limits")
}
checks["etcd limits"] = true
}
}
}
for check := range checks {
if !checks[check] {
t.Errorf("%q incomplete", check)
}
}
}