Skip to content

Commit a733821

Browse files
Adding support for default probes on NIM Deployment (#24)
* Adding support for default probes on NIM Deployment Signed-off-by: Vishesh Tanksale <[email protected]> * Removing logging Signed-off-by: Vishesh Tanksale <[email protected]> --------- Signed-off-by: Vishesh Tanksale <[email protected]>
1 parent 9033166 commit a733821

10 files changed

+2787
-2563
lines changed

api/v1alpha1/common_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ type IngressPath struct {
8282
PathType networkingv1.PathType `json:"pathType,omitempty"`
8383
ServiceType string `json:"serviceType,omitempty"`
8484
}
85+
86+
type Probe struct {
87+
Enabled *bool `json:"enabled,omitempty"`
88+
Probe *corev1.Probe `json:"probe,omitempty"`
89+
}

api/v1alpha1/nimservice_types.go

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
networkingv1 "k8s.io/api/networking/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/util/intstr"
2930
)
3031

3132
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -68,9 +69,9 @@ type NIMServiceSpec struct {
6869
PodAffinity *corev1.PodAffinity `json:"podAffinity,omitempty"`
6970
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
7071
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"`
7475
Scale Autoscaling `json:"scale,omitempty"`
7576
Metrics Metrics `json:"metrics,omitempty"`
7677
Replicas int `json:"replicas,omitempty"`
@@ -270,19 +271,101 @@ func (n *NIMService) GetResources() *corev1.ResourceRequirements {
270271
return n.Spec.Resources
271272
}
272273

274+
func IsProbeEnabled(probe Probe) bool {
275+
if probe.Enabled == nil {
276+
return true
277+
}
278+
return *probe.Enabled
279+
}
280+
273281
// GetLivenessProbe returns liveness probe for the NIMService container
274282
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
276309
}
277310

278311
// GetReadinessProbe returns readiness probe for the NIMService container
279312
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
281339
}
282340

283341
// GetStartupProbe returns startup probe for the NIMService container
284342
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
286369
}
287370

288371
// GetVolumesMounts returns volume mounts for the NIMService container
@@ -439,9 +522,15 @@ func (n *NIMService) GetDeploymentParams() *rendertypes.DeploymentParams {
439522
params.Image = n.GetImage()
440523

441524
// 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+
}
445534

446535
// Set service account
447536
params.ServiceAccountName = n.GetServiceAccountName()

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 28 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)