-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathhelpers.go
148 lines (123 loc) · 3.42 KB
/
helpers.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
package jobs
import (
"fmt"
"strconv"
"github.com/grafana/k6-operator/pkg/types"
"github.com/grafana/k6-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
)
func newLabels(name string) map[string]string {
return map[string]string{
"app": "k6",
"k6_cr": name,
}
}
func newIstioCommand(istioEnabled string, inheritedCommands []string) ([]string, bool) {
istio := false
if istioEnabled != "" {
istio, _ = strconv.ParseBool(istioEnabled)
}
var command []string
if istio {
command = append(command, "scuttle")
}
command = append(command, inheritedCommands...)
return command, istio
}
func newIstioEnvVar(istio v1alpha1.K6Scuttle, istioEnabled bool) []corev1.EnvVar {
env := []corev1.EnvVar{}
if istioEnabled {
var istioQuitApi string
var envoyAdminApi string
var waitForEnvoyTimeout string
if istio.EnvoyAdminApi != "" {
envoyAdminApi = istio.EnvoyAdminApi
} else {
envoyAdminApi = "http://127.0.0.1:15000"
}
env = append(env, corev1.EnvVar{
Name: "ENVOY_ADMIN_API",
Value: envoyAdminApi,
})
if istio.IstioQuitApi != "" {
istioQuitApi = istio.IstioQuitApi
} else {
istioQuitApi = "http://127.0.0.1:15020"
}
env = append(env, corev1.EnvVar{
Name: "ISTIO_QUIT_API",
Value: istioQuitApi,
})
if istio.WaitForEnvoyTimeout != "" {
waitForEnvoyTimeout = istio.WaitForEnvoyTimeout
} else {
waitForEnvoyTimeout = "15"
}
env = append(env, corev1.EnvVar{
Name: "WAIT_FOR_ENVOY_TIMEOUT",
Value: waitForEnvoyTimeout,
})
if istio.NeverKillIstio {
env = append(env, corev1.EnvVar{
Name: "NEVER_KILL_ISTIO",
Value: strconv.FormatBool(istio.NeverKillIstio),
})
}
if istio.NeverKillIstioOnFailure {
env = append(env, corev1.EnvVar{
Name: "NEVER_KILL_ISTIO_ON_FAILURE",
Value: strconv.FormatBool(istio.NeverKillIstioOnFailure),
})
}
if istio.DisableLogging {
env = append(env, corev1.EnvVar{
Name: "SCUTTLE_LOGGING",
Value: strconv.FormatBool(false),
})
}
if istio.StartWithoutEnvoy {
env = append(env, corev1.EnvVar{
Name: "START_WITHOUT_ENVOY",
Value: strconv.FormatBool(istio.StartWithoutEnvoy),
})
}
if istio.GenericQuitEndpoint != "" {
env = append(env, corev1.EnvVar{
Name: "GENERIC_QUIT_ENDPOINT",
Value: istio.GenericQuitEndpoint,
})
}
if istio.QuitWithoutEnvoyTimeout != "" {
env = append(env, corev1.EnvVar{
Name: "QUIT_WITHOUT_ENVOY_TIMEOUT",
Value: istio.QuitWithoutEnvoyTimeout,
})
}
}
return env
}
// TODO: Envoy variables are not passed to init containers
func getInitContainers(pod *v1alpha1.Pod, script *types.Script) []corev1.Container {
var initContainers []corev1.Container
for i, k6InitContainer := range pod.InitContainers {
name := fmt.Sprintf("k6-init-%d", i)
if k6InitContainer.Name != "" {
name = k6InitContainer.Name
}
volumeMounts := append(script.VolumeMount(), k6InitContainer.VolumeMounts...)
initContainer := corev1.Container{
Name: name,
Image: k6InitContainer.Image,
Command: k6InitContainer.Command,
Args: k6InitContainer.Args,
WorkingDir: k6InitContainer.WorkingDir,
EnvFrom: k6InitContainer.EnvFrom,
Env: k6InitContainer.Env,
VolumeMounts: volumeMounts,
ImagePullPolicy: pod.ImagePullPolicy,
SecurityContext: &pod.ContainerSecurityContext,
}
initContainers = append(initContainers, initContainer)
}
return initContainers
}