/
sink.go
76 lines (67 loc) · 2.47 KB
/
sink.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
/*
Copyright 2022 The Numaproj 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 v1alpha1
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
type Sink struct {
Log *Log `json:"log,omitempty" protobuf:"bytes,1,opt,name=log"`
Kafka *KafkaSink `json:"kafka,omitempty" protobuf:"bytes,2,opt,name=kafka"`
Blackhole *Blackhole `json:"blackhole,omitempty" protobuf:"bytes,3,opt,name=blackhole"`
UDSink *UDSink `json:"udsink,omitempty" protobuf:"bytes,4,opt,name=udsink"`
}
func (s Sink) getContainers(req getContainerReq) ([]corev1.Container, error) {
containers := []corev1.Container{
s.getMainContainer(req),
}
if s.UDSink != nil {
containers = append(containers, s.getUDSinkContainer(req))
}
return containers, nil
}
func (s Sink) getMainContainer(req getContainerReq) corev1.Container {
return containerBuilder{}.init(req).args("processor", "--type="+string(VertexTypeSink), "--isbsvc-type="+string(req.isbSvcType)).build()
}
func (s Sink) getUDSinkContainer(mainContainerReq getContainerReq) corev1.Container {
c := containerBuilder{}.
name(CtrUdsink).
imagePullPolicy(mainContainerReq.imagePullPolicy). // Use the same image pull policy as the main container
appendVolumeMounts(mainContainerReq.volumeMounts...)
x := s.UDSink.Container
c = c.image(x.Image)
if len(x.Command) > 0 {
c = c.command(x.Command...)
}
if len(x.Args) > 0 {
c = c.args(x.Args...)
}
c = c.appendEnv(x.Env...).appendVolumeMounts(x.VolumeMounts...).resources(x.Resources).securityContext(x.SecurityContext).appendEnvFrom(x.EnvFrom...)
if x.ImagePullPolicy != nil {
c = c.imagePullPolicy(*x.ImagePullPolicy)
}
container := c.build()
container.LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/sidecar-livez",
Port: intstr.FromInt(VertexMetricsPort),
Scheme: corev1.URISchemeHTTPS,
},
},
InitialDelaySeconds: 30,
PeriodSeconds: 60,
TimeoutSeconds: 30,
}
return container
}