-
Notifications
You must be signed in to change notification settings - Fork 596
/
forwarder.go
100 lines (91 loc) · 3.21 KB
/
forwarder.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
/*
* Copyright 2020 The Knative Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package prober
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
testlib "knative.dev/eventing/test/lib"
"knative.dev/eventing/test/lib/duck"
"knative.dev/eventing/test/lib/resources"
)
var (
forwarderName = "wathola-forwarder"
)
func (p *prober) deployForwarder() {
p.log.Infof("Deploy forwarder knative service: %v", forwarderName)
serving := p.client.Dynamic.Resource(resources.KServicesGVR).Namespace(p.client.Namespace)
service := p.forwarderKService(forwarderName, p.client.Namespace)
if _, err := serving.Create(p.config.Ctx, service, metav1.CreateOptions{}); err != nil {
p.client.T.Fatal(err)
}
sc := p.servingClient()
testlib.WaitFor(fmt.Sprintf("forwarder ksvc be ready: %v", forwarderName), func() error {
return duck.WaitForKServiceReady(sc, forwarderName, p.client.Namespace)
})
if p.config.Serving.ScaleToZero {
testlib.WaitFor(fmt.Sprintf("forwarder scales to zero: %v", forwarderName), func() error {
return duck.WaitForKServiceScales(p.config.Ctx, sc, forwarderName, p.client.Namespace, func(scale int) bool {
return scale == 0
})
})
}
}
func (p *prober) removeForwarder() {
p.log.Infof("Remove forwarder knative service: %v", forwarderName)
serving := p.client.Dynamic.Resource(resources.KServicesGVR).Namespace(p.client.Namespace)
err := serving.Delete(p.config.Ctx, forwarderName, metav1.DeleteOptions{})
p.ensureNoError(err)
}
func (p *prober) forwarderKService(name, namespace string) *unstructured.Unstructured {
obj := map[string]interface{}{
"apiVersion": resources.KServiceType.APIVersion,
"kind": resources.KServiceType.Kind,
"metadata": map[string]interface{}{
"name": name,
"namespace": namespace,
"labels": map[string]string{
"networking.knative.dev/visibility": "cluster-local",
},
},
"spec": map[string]interface{}{
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []map[string]interface{}{{
"name": forwarderName,
"image": p.config.ImageResolver(forwarderName),
"volumeMounts": []map[string]interface{}{{
"name": p.config.ConfigMapName,
"mountPath": p.config.ConfigMountPoint,
"readOnly": true,
}},
"readinessProbe": map[string]interface{}{
"httpGet": map[string]interface{}{
"path": p.config.HealthEndpoint,
},
},
}},
"volumes": []map[string]interface{}{{
"name": p.config.ConfigMapName,
"configMap": map[string]interface{}{
"name": p.config.ConfigMapName,
},
}},
},
},
},
}
return &unstructured.Unstructured{Object: obj}
}