Skip to content

Commit

Permalink
improve configurability of probes (grafana#636)
Browse files Browse the repository at this point in the history
* improve configurability of probes

Co-authored-by: Edvin Norling <edvin.norling@xenit.se>
  • Loading branch information
pb82 and Edvin Norling authored Nov 30, 2021
1 parent 64685c6 commit d60ea53
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 44 deletions.
22 changes: 12 additions & 10 deletions api/integreatly/v1alpha1/grafana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ type GrafanaSpec struct {
}

type ReadinessProbeSpec struct {
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
TimeOutSeconds int32 `json:"timeoutSeconds,omitempty"`
PeriodSeconds int32 `json:"periodSeconds,omitempty"`
SuccessThreshold int32 `json:"successThreshold,omitempty"`
FailureThreshold int32 `json:"failureThreshold,omitempty"`
InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"`
TimeOutSeconds *int32 `json:"timeoutSeconds,omitempty"`
PeriodSeconds *int32 `json:"periodSeconds,omitempty"`
SuccessThreshold *int32 `json:"successThreshold,omitempty"`
FailureThreshold *int32 `json:"failureThreshold,omitempty"`
Scheme v1.URIScheme `json:"scheme,omitempty"`
}
type LivenessProbeSpec struct {
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
TimeOutSeconds int32 `json:"timeoutSeconds,omitempty"`
PeriodSeconds int32 `json:"periodSeconds,omitempty"`
SuccessThreshold int32 `json:"successThreshold,omitempty"`
FailureThreshold int32 `json:"failureThreshold,omitempty"`
InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"`
TimeOutSeconds *int32 `json:"timeoutSeconds,omitempty"`
PeriodSeconds *int32 `json:"periodSeconds,omitempty"`
SuccessThreshold *int32 `json:"successThreshold,omitempty"`
FailureThreshold *int32 `json:"failureThreshold,omitempty"`
Scheme v1.URIScheme `json:"scheme,omitempty"`
}

type JsonnetConfig struct {
Expand Down
54 changes: 52 additions & 2 deletions api/integreatly/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/integreatly.org_grafanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4793,6 +4793,10 @@ spec:
periodSeconds:
format: int32
type: integer
scheme:
description: URIScheme identifies the scheme used for connection
to a host for Get actions
type: string
successThreshold:
format: int32
type: integer
Expand All @@ -4811,6 +4815,10 @@ spec:
periodSeconds:
format: int32
type: integer
scheme:
description: URIScheme identifies the scheme used for connection
to a host for Get actions
type: string
successThreshold:
format: int32
type: integer
Expand Down
94 changes: 62 additions & 32 deletions controllers/model/grafanaDeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,61 +435,91 @@ func getVolumeMounts(cr *v1alpha1.Grafana) []v13.VolumeMount {
}

func getLivenessProbe(cr *v1alpha1.Grafana, delay, timeout, failure int32) *v13.Probe {
if cr.Spec.LivenessProbeSpec != nil {
return &v13.Probe{
Handler: v13.Handler{
HTTPGet: &v13.HTTPGetAction{
Path: constants.GrafanaHealthEndpoint,
Port: intstr.FromInt(GetGrafanaPort(cr)),
},
},
InitialDelaySeconds: cr.Spec.LivenessProbeSpec.InitialDelaySeconds,
TimeoutSeconds: cr.Spec.LivenessProbeSpec.TimeOutSeconds,
PeriodSeconds: cr.Spec.LivenessProbeSpec.PeriodSeconds,
SuccessThreshold: cr.Spec.LivenessProbeSpec.SuccessThreshold,
FailureThreshold: cr.Spec.LivenessProbeSpec.FailureThreshold,
}
var period int32 = 10
var success int32 = 1
var scheme = v13.URISchemeHTTP

if cr.Spec.LivenessProbeSpec != nil && cr.Spec.LivenessProbeSpec.InitialDelaySeconds != nil {
delay = *cr.Spec.LivenessProbeSpec.InitialDelaySeconds
}

if cr.Spec.LivenessProbeSpec != nil && cr.Spec.LivenessProbeSpec.TimeOutSeconds != nil {
timeout = *cr.Spec.LivenessProbeSpec.TimeOutSeconds
}

if cr.Spec.LivenessProbeSpec != nil && cr.Spec.LivenessProbeSpec.FailureThreshold != nil {
failure = *cr.Spec.LivenessProbeSpec.FailureThreshold
}

if cr.Spec.LivenessProbeSpec != nil && cr.Spec.LivenessProbeSpec.PeriodSeconds != nil {
period = *cr.Spec.LivenessProbeSpec.PeriodSeconds
}

if cr.Spec.LivenessProbeSpec != nil && cr.Spec.LivenessProbeSpec.SuccessThreshold != nil {
period = *cr.Spec.LivenessProbeSpec.SuccessThreshold
}

if cr.Spec.LivenessProbeSpec != nil && cr.Spec.LivenessProbeSpec.Scheme != "" {
scheme = cr.Spec.LivenessProbeSpec.Scheme
}

return &v13.Probe{
Handler: v13.Handler{
HTTPGet: &v13.HTTPGetAction{
Path: constants.GrafanaHealthEndpoint,
Port: intstr.FromInt(GetGrafanaPort(cr)),
Path: constants.GrafanaHealthEndpoint,
Port: intstr.FromInt(GetGrafanaPort(cr)),
Scheme: scheme,
},
},
InitialDelaySeconds: delay,
TimeoutSeconds: timeout,
PeriodSeconds: period,
SuccessThreshold: success,
FailureThreshold: failure,
}
}

func getReadinessProbe(cr *v1alpha1.Grafana, delay, timeout, failure int32) *v13.Probe {
if cr.Spec.ReadinessProbeSpec != nil {
return &v13.Probe{
Handler: v13.Handler{
HTTPGet: &v13.HTTPGetAction{
Path: constants.GrafanaHealthEndpoint,
Port: intstr.FromInt(GetGrafanaPort(cr)),
},
},
InitialDelaySeconds: cr.Spec.ReadinessProbeSpec.InitialDelaySeconds,
TimeoutSeconds: cr.Spec.ReadinessProbeSpec.TimeOutSeconds,
PeriodSeconds: cr.Spec.ReadinessProbeSpec.PeriodSeconds,
SuccessThreshold: cr.Spec.ReadinessProbeSpec.SuccessThreshold,
FailureThreshold: cr.Spec.ReadinessProbeSpec.FailureThreshold,
}
var period int32 = 10
var success int32 = 1
var scheme = v13.URISchemeHTTP

if cr.Spec.ReadinessProbeSpec != nil && cr.Spec.ReadinessProbeSpec.InitialDelaySeconds != nil {
delay = *cr.Spec.ReadinessProbeSpec.InitialDelaySeconds
}

if cr.Spec.ReadinessProbeSpec != nil && cr.Spec.ReadinessProbeSpec.TimeOutSeconds != nil {
timeout = *cr.Spec.ReadinessProbeSpec.TimeOutSeconds
}

if cr.Spec.ReadinessProbeSpec != nil && cr.Spec.ReadinessProbeSpec.FailureThreshold != nil {
failure = *cr.Spec.ReadinessProbeSpec.FailureThreshold
}

if cr.Spec.ReadinessProbeSpec != nil && cr.Spec.ReadinessProbeSpec.PeriodSeconds != nil {
period = *cr.Spec.ReadinessProbeSpec.PeriodSeconds
}

if cr.Spec.ReadinessProbeSpec != nil && cr.Spec.ReadinessProbeSpec.SuccessThreshold != nil {
period = *cr.Spec.ReadinessProbeSpec.SuccessThreshold
}

if cr.Spec.ReadinessProbeSpec != nil && cr.Spec.ReadinessProbeSpec.Scheme != "" {
scheme = cr.Spec.ReadinessProbeSpec.Scheme
}

return &v13.Probe{
Handler: v13.Handler{
HTTPGet: &v13.HTTPGetAction{
Path: constants.GrafanaHealthEndpoint,
Port: intstr.FromInt(GetGrafanaPort(cr)),
Path: constants.GrafanaHealthEndpoint,
Port: intstr.FromInt(GetGrafanaPort(cr)),
Scheme: scheme,
},
},
InitialDelaySeconds: delay,
TimeoutSeconds: timeout,
PeriodSeconds: period,
SuccessThreshold: success,
FailureThreshold: failure,
}
}
Expand Down
8 changes: 8 additions & 0 deletions deploy/manifests/latest/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5325,6 +5325,10 @@ spec:
periodSeconds:
format: int32
type: integer
scheme:
description: URIScheme identifies the scheme used for connection
to a host for Get actions
type: string
successThreshold:
format: int32
type: integer
Expand All @@ -5343,6 +5347,10 @@ spec:
periodSeconds:
format: int32
type: integer
scheme:
description: URIScheme identifies the scheme used for connection
to a host for Get actions
type: string
successThreshold:
format: int32
type: integer
Expand Down
14 changes: 14 additions & 0 deletions documentation/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12155,6 +12155,13 @@ A label selector requirement is a selector that contains values, a key, and an o
<i>Format</i>: int32<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>scheme</b></td>
<td>string</td>
<td>
URIScheme identifies the scheme used for connection to a host for Get actions<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>successThreshold</b></td>
<td>integer</td>
Expand Down Expand Up @@ -12220,6 +12227,13 @@ A label selector requirement is a selector that contains values, a key, and an o
<i>Format</i>: int32<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>scheme</b></td>
<td>string</td>
<td>
URIScheme identifies the scheme used for connection to a host for Get actions<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>successThreshold</b></td>
<td>integer</td>
Expand Down

0 comments on commit d60ea53

Please sign in to comment.