@@ -20,6 +20,17 @@ import (
20
20
21
21
// +kubebuilder:rbac:namespace=egress-operator-system,groups=apps,resources=deployments,verbs=get;list;watch;create;patch
22
22
23
+ var validLogLevels = map [string ]bool {
24
+ "trace" : true ,
25
+ "debug" : true ,
26
+ "info" : true ,
27
+ "warning" : true ,
28
+ "warn" : true ,
29
+ "error" : true ,
30
+ "critical" : true ,
31
+ "off" : true ,
32
+ }
33
+
23
34
func (r * ExternalServiceReconciler ) reconcileDeployment (ctx context.Context , req ctrl.Request , es * egressv1.ExternalService , configHash string ) error {
24
35
desired := deployment (es , configHash )
25
36
if err := ctrl .SetControllerReference (es , desired , r .Scheme ); err != nil {
@@ -157,93 +168,84 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
157
168
},
158
169
}
159
170
}
160
-
161
- return & appsv1.Deployment {
162
- ObjectMeta : metav1.ObjectMeta {
163
- Name : es .Name ,
164
- Namespace : namespace ,
165
- Labels : labels (es ),
166
- Annotations : annotations (es ),
171
+ deploymentSpec := appsv1.DeploymentSpec {
172
+ ProgressDeadlineSeconds : proto .Int (600 ),
173
+ RevisionHistoryLimit : proto .Int (10 ),
174
+ Strategy : appsv1.DeploymentStrategy {
175
+ Type : appsv1 .RollingUpdateDeploymentStrategyType ,
176
+ RollingUpdate : & appsv1.RollingUpdateDeployment {
177
+ MaxUnavailable : intstr .ValueOrDefault (nil , intstr .FromString ("25%" )),
178
+ MaxSurge : intstr .ValueOrDefault (nil , intstr .FromString ("25%" )),
179
+ },
167
180
},
168
- Spec : appsv1.DeploymentSpec {
169
- ProgressDeadlineSeconds : proto .Int (600 ),
170
- RevisionHistoryLimit : proto .Int (10 ),
171
- Strategy : appsv1.DeploymentStrategy {
172
- Type : appsv1 .RollingUpdateDeploymentStrategyType ,
173
- RollingUpdate : & appsv1.RollingUpdateDeployment {
174
- MaxUnavailable : intstr .ValueOrDefault (nil , intstr .FromString ("25%" )),
175
- MaxSurge : intstr .ValueOrDefault (nil , intstr .FromString ("25%" )),
176
- },
181
+ Selector : labelSelector ,
182
+ Template : corev1.PodTemplateSpec {
183
+ ObjectMeta : metav1.ObjectMeta {
184
+ Labels : labels (es ),
185
+ Annotations : a ,
177
186
},
178
- Selector : labelSelector ,
179
- Template : corev1.PodTemplateSpec {
180
- ObjectMeta : metav1.ObjectMeta {
181
- Labels : labels (es ),
182
- Annotations : a ,
183
- },
184
- Spec : corev1.PodSpec {
185
- Tolerations : tolerations ,
186
- NodeSelector : nodeSelector ,
187
- TopologySpreadConstraints : podTopologySpread ,
188
- Containers : []corev1.Container {
189
- {
190
- Name : "gateway" ,
191
- Image : img ,
192
- ImagePullPolicy : corev1 .PullIfNotPresent ,
193
- Ports : deploymentPorts (es ),
194
- VolumeMounts : []corev1.VolumeMount {
195
- {
196
- Name : "envoy-config" ,
197
- MountPath : "/etc/envoy" ,
198
- },
187
+ Spec : corev1.PodSpec {
188
+ Tolerations : tolerations ,
189
+ NodeSelector : nodeSelector ,
190
+ TopologySpreadConstraints : podTopologySpread ,
191
+ Containers : []corev1.Container {
192
+ {
193
+ Name : "gateway" ,
194
+ Image : img ,
195
+ ImagePullPolicy : corev1 .PullIfNotPresent ,
196
+ Ports : deploymentPorts (es ),
197
+ VolumeMounts : []corev1.VolumeMount {
198
+ {
199
+ Name : "envoy-config" ,
200
+ MountPath : "/etc/envoy" ,
199
201
},
200
- // Copying istio; don't try drain outbound listeners, but after going into terminating state ,
201
- // wait 25 seconds for connections to naturally close before going ahead with stop.
202
- Lifecycle : & corev1. Lifecycle {
203
- PreStop : & corev1.LifecycleHandler {
204
- Exec : & corev1.ExecAction {
205
- Command : [] string { "/bin/sleep" , "25" },
206
- },
202
+ } ,
203
+ // Copying istio; don't try drain outbound listeners, but after going into terminating state,
204
+ // wait 25 seconds for connections to naturally close before going ahead with stop.
205
+ Lifecycle : & corev1.Lifecycle {
206
+ PreStop : & corev1.LifecycleHandler {
207
+ Exec : & corev1. ExecAction {
208
+ Command : [] string { "/bin/sleep" , "25" },
207
209
},
208
210
},
209
- TerminationMessagePath : corev1 . TerminationMessagePathDefault ,
210
- TerminationMessagePolicy : corev1 .TerminationMessageReadFile ,
211
- ReadinessProbe : & corev1.Probe {
212
- ProbeHandler : corev1.ProbeHandler {
213
- HTTPGet : & corev1.HTTPGetAction {
214
- Path : "/ready" ,
215
- Port : intstr . FromInt ( int ( adPort )) ,
216
- Scheme : corev1 . URISchemeHTTP ,
217
- } ,
211
+ } ,
212
+ TerminationMessagePath : corev1 .TerminationMessagePathDefault ,
213
+ TerminationMessagePolicy : corev1 .TerminationMessageReadFile ,
214
+ ReadinessProbe : & corev1.Probe {
215
+ ProbeHandler : corev1.ProbeHandler {
216
+ HTTPGet : & corev1. HTTPGetAction {
217
+ Path : "/ready" ,
218
+ Port : intstr . FromInt ( int ( adPort )) ,
219
+ Scheme : corev1 . URISchemeHTTP ,
218
220
},
219
- FailureThreshold : 3 ,
220
- PeriodSeconds : 10 ,
221
- SuccessThreshold : 1 ,
222
- TimeoutSeconds : 1 ,
223
221
},
224
- Resources : resources ,
225
- Env : []corev1.EnvVar {
226
- {
227
- Name : "ENVOY_UID" ,
228
- Value : "0" ,
229
- },
222
+ FailureThreshold : 3 ,
223
+ PeriodSeconds : 10 ,
224
+ SuccessThreshold : 1 ,
225
+ TimeoutSeconds : 1 ,
226
+ },
227
+ Resources : resources ,
228
+ Env : []corev1.EnvVar {
229
+ {
230
+ Name : "ENVOY_UID" ,
231
+ Value : "0" ,
230
232
},
231
233
},
232
234
},
233
- RestartPolicy : corev1 . RestartPolicyAlways ,
234
- SchedulerName : corev1 .DefaultSchedulerName ,
235
- SecurityContext : & corev1.PodSecurityContext {} ,
236
- TerminationGracePeriodSeconds : proto . Int64 ( 30 ) ,
237
- DNSPolicy : corev1 . DNSDefault ,
238
- Volumes : [] corev1.Volume {
239
- {
240
- Name : "envoy-config" ,
241
- VolumeSource : corev1. VolumeSource {
242
- ConfigMap : & corev1.ConfigMapVolumeSource {
243
- DefaultMode : proto . Int ( 420 ),
244
- LocalObjectReference : corev1. LocalObjectReference {
245
- Name : es . Name ,
246
- } ,
235
+ } ,
236
+ RestartPolicy : corev1 .RestartPolicyAlways ,
237
+ SchedulerName : corev1 .DefaultSchedulerName ,
238
+ SecurityContext : & corev1. PodSecurityContext {} ,
239
+ TerminationGracePeriodSeconds : proto . Int64 ( 30 ) ,
240
+ DNSPolicy : corev1 .DNSDefault ,
241
+ Volumes : []corev1. Volume {
242
+ {
243
+ Name : "envoy-config" ,
244
+ VolumeSource : corev1.VolumeSource {
245
+ ConfigMap : & corev1. ConfigMapVolumeSource {
246
+ DefaultMode : proto . Int ( 420 ),
247
+ LocalObjectReference : corev1. LocalObjectReference {
248
+ Name : es . Name ,
247
249
},
248
250
},
249
251
},
@@ -252,4 +254,19 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
252
254
},
253
255
},
254
256
}
257
+
258
+ defaultArgs := []string {"-c" , "/etc/envoy/envoy.yaml" }
259
+ if validLogLevels [es .Spec .EnvoyLogLevel ] {
260
+ deploymentSpec .Template .Spec .Containers [0 ].Args = append (defaultArgs , "--log-level" , es .Spec .EnvoyLogLevel )
261
+ }
262
+
263
+ return & appsv1.Deployment {
264
+ ObjectMeta : metav1.ObjectMeta {
265
+ Name : es .Name ,
266
+ Namespace : namespace ,
267
+ Labels : labels (es ),
268
+ Annotations : annotations (es ),
269
+ },
270
+ Spec : deploymentSpec ,
271
+ }
255
272
}
0 commit comments