@@ -26,6 +26,7 @@ import (
26
26
corev1 "k8s.io/api/core/v1"
27
27
networkingv1 "k8s.io/api/networking/v1"
28
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
+ "k8s.io/apimachinery/pkg/util/intstr"
29
30
)
30
31
31
32
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -68,9 +69,9 @@ type NIMServiceSpec struct {
68
69
PodAffinity * corev1.PodAffinity `json:"podAffinity,omitempty"`
69
70
Resources * corev1.ResourceRequirements `json:"resources,omitempty"`
70
71
Expose Expose `json:"expose,omitempty"`
71
- LivenessProbe * corev1. Probe `json:"livenessProbe,omitempty"`
72
- ReadinessProbe * corev1. Probe `json:"readinessProbe,omitempty"`
73
- StartupProbe * corev1. Probe `json:"startupProbe,omitempty"`
72
+ LivenessProbe Probe `json:"livenessProbe,omitempty"`
73
+ ReadinessProbe Probe `json:"readinessProbe,omitempty"`
74
+ StartupProbe Probe `json:"startupProbe,omitempty"`
74
75
Scale Autoscaling `json:"scale,omitempty"`
75
76
Metrics Metrics `json:"metrics,omitempty"`
76
77
Replicas int `json:"replicas,omitempty"`
@@ -270,19 +271,101 @@ func (n *NIMService) GetResources() *corev1.ResourceRequirements {
270
271
return n .Spec .Resources
271
272
}
272
273
274
+ func IsProbeEnabled (probe Probe ) bool {
275
+ if probe .Enabled == nil {
276
+ return true
277
+ }
278
+ return * probe .Enabled
279
+ }
280
+
273
281
// GetLivenessProbe returns liveness probe for the NIMService container
274
282
func (n * NIMService ) GetLivenessProbe () * corev1.Probe {
275
- return n .Spec .LivenessProbe
283
+ if n .Spec .LivenessProbe .Probe == nil {
284
+ return GetDefaultLivenessProbe ()
285
+ }
286
+ return n .Spec .LivenessProbe .Probe
287
+ }
288
+
289
+ // GetDefaultLivenessProbe returns the default liveness probe for the NIMService container
290
+ func GetDefaultLivenessProbe () * corev1.Probe {
291
+ probe := corev1.Probe {
292
+ InitialDelaySeconds : 15 ,
293
+ TimeoutSeconds : 1 ,
294
+ PeriodSeconds : 10 ,
295
+ SuccessThreshold : 1 ,
296
+ FailureThreshold : 3 ,
297
+ ProbeHandler : corev1.ProbeHandler {
298
+ HTTPGet : & corev1.HTTPGetAction {
299
+ Path : "/v1/health/live" ,
300
+ Port : intstr.IntOrString {
301
+ Type : intstr .Type (0 ),
302
+ IntVal : 8000 ,
303
+ },
304
+ },
305
+ },
306
+ }
307
+
308
+ return & probe
276
309
}
277
310
278
311
// GetReadinessProbe returns readiness probe for the NIMService container
279
312
func (n * NIMService ) GetReadinessProbe () * corev1.Probe {
280
- return n .Spec .ReadinessProbe
313
+ if n .Spec .ReadinessProbe .Probe == nil {
314
+ return GetDefaultReadinessProbe ()
315
+ }
316
+ return n .Spec .ReadinessProbe .Probe
317
+ }
318
+
319
+ // GetDefaultReadinessProbe returns the default readiness probe for the NIMService container
320
+ func GetDefaultReadinessProbe () * corev1.Probe {
321
+ probe := corev1.Probe {
322
+ InitialDelaySeconds : 15 ,
323
+ TimeoutSeconds : 1 ,
324
+ PeriodSeconds : 10 ,
325
+ SuccessThreshold : 1 ,
326
+ FailureThreshold : 3 ,
327
+ ProbeHandler : corev1.ProbeHandler {
328
+ HTTPGet : & corev1.HTTPGetAction {
329
+ Path : "/v1/health/ready" ,
330
+ Port : intstr.IntOrString {
331
+ Type : intstr .Type (0 ),
332
+ IntVal : 8000 ,
333
+ },
334
+ },
335
+ },
336
+ }
337
+
338
+ return & probe
281
339
}
282
340
283
341
// GetStartupProbe returns startup probe for the NIMService container
284
342
func (n * NIMService ) GetStartupProbe () * corev1.Probe {
285
- return n .Spec .StartupProbe
343
+ if n .Spec .StartupProbe .Probe == nil {
344
+ return GetDefaultStartupProbe ()
345
+ }
346
+ return n .Spec .StartupProbe .Probe
347
+ }
348
+
349
+ // GetDefaultStartupProbe returns the default startup probe for the NIMService container
350
+ func GetDefaultStartupProbe () * corev1.Probe {
351
+ probe := corev1.Probe {
352
+ InitialDelaySeconds : 40 ,
353
+ TimeoutSeconds : 1 ,
354
+ PeriodSeconds : 10 ,
355
+ SuccessThreshold : 1 ,
356
+ FailureThreshold : 180 ,
357
+ ProbeHandler : corev1.ProbeHandler {
358
+ HTTPGet : & corev1.HTTPGetAction {
359
+ Path : "/v1/health/ready" ,
360
+ Port : intstr.IntOrString {
361
+ Type : intstr .Type (0 ),
362
+ IntVal : 8000 ,
363
+ },
364
+ },
365
+ },
366
+ }
367
+
368
+ return & probe
286
369
}
287
370
288
371
// GetVolumesMounts returns volume mounts for the NIMService container
@@ -439,9 +522,15 @@ func (n *NIMService) GetDeploymentParams() *rendertypes.DeploymentParams {
439
522
params .Image = n .GetImage ()
440
523
441
524
// Set container probes
442
- params .LivenessProbe = n .GetLivenessProbe ()
443
- params .ReadinessProbe = n .GetReadinessProbe ()
444
- params .StartupProbe = n .GetStartupProbe ()
525
+ if IsProbeEnabled (n .Spec .LivenessProbe ) {
526
+ params .LivenessProbe = n .GetLivenessProbe ()
527
+ }
528
+ if IsProbeEnabled (n .Spec .ReadinessProbe ) {
529
+ params .ReadinessProbe = n .GetReadinessProbe ()
530
+ }
531
+ if IsProbeEnabled (n .Spec .StartupProbe ) {
532
+ params .StartupProbe = n .GetStartupProbe ()
533
+ }
445
534
446
535
// Set service account
447
536
params .ServiceAccountName = n .GetServiceAccountName ()
0 commit comments