Skip to content

Commit

Permalink
Tidy up deployment probes
Browse files Browse the repository at this point in the history
This change moves the *probes into their own functions.
This makes the deployment code easier to write functional tests for.

Signed-off-by: Brendan Shephard <bshephar@redhat.com>
  • Loading branch information
bshephar committed Feb 11, 2025
1 parent a1fec48 commit a51f748
Showing 1 changed file with 54 additions and 38 deletions.
92 changes: 54 additions & 38 deletions pkg/horizon/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (

const (
// ServiceCommand is the command used to run Kolla and launch the initial Apache process
ServiceCommand = "/usr/local/bin/kolla_start"
ServiceCommand = "/usr/local/bin/kolla_start"
horizonDashboardURL = "/dashboard/auth/login/?next=/dashboard/"
horizonContainerPortName = "horizon"
)

// Deployment creates the k8s deployment structure required to run Horizon
Expand All @@ -47,47 +49,11 @@ func Deployment(
args := []string{"-c", ServiceCommand}

containerPort := corev1.ContainerPort{
Name: "horizon",
Name: horizonContainerPortName,
Protocol: corev1.ProtocolTCP,
ContainerPort: HorizonPort,
}

livenessProbe := &corev1.Probe{
TimeoutSeconds: 5,
PeriodSeconds: 10,
InitialDelaySeconds: 10,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/dashboard/auth/login/?next=/dashboard/",
Port: intstr.FromString("horizon"),
},
},
}
readinessProbe := &corev1.Probe{
TimeoutSeconds: 5,
PeriodSeconds: 10,
InitialDelaySeconds: 10,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/dashboard/auth/login/?next=/dashboard/",
Port: intstr.FromString("horizon"),
},
},
}

startupProbe := &corev1.Probe{
TimeoutSeconds: 5,
PeriodSeconds: 10,
FailureThreshold: 30,
InitialDelaySeconds: 10,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/dashboard/auth/login/?next=/dashboard/",
Port: intstr.FromString("horizon"),
},
},
}

envVars := map[string]env.Setter{}
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
envVars["ENABLE_DESIGNATE"] = env.SetValue("yes")
Expand All @@ -108,6 +74,10 @@ func Deployment(
volumeMounts = append(volumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
}

readinessProbe := formatReadinessProbe()
livenessProbe := formatLivenessProbe()
startupProbe := formatStartupProbe()

if instance.Spec.TLS.Enabled() {
svc, err := instance.Spec.TLS.GenericService.ToService()
if err != nil {
Expand Down Expand Up @@ -193,3 +163,49 @@ func Deployment(

return deployment, nil
}

func formatLivenessProbe() *corev1.Probe {

return &corev1.Probe{
TimeoutSeconds: 5,
PeriodSeconds: 10,
InitialDelaySeconds: 10,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: horizonDashboardURL,
Port: intstr.FromString(horizonContainerPortName),
},
},
}
}

func formatReadinessProbe() *corev1.Probe {

return &corev1.Probe{
TimeoutSeconds: 5,
PeriodSeconds: 10,
InitialDelaySeconds: 10,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: horizonContainerPortName,
Port: intstr.FromString(horizonContainerPortName),
},
},
}
}

func formatStartupProbe() *corev1.Probe {

return &corev1.Probe{
TimeoutSeconds: 5,
PeriodSeconds: 10,
FailureThreshold: 30,
InitialDelaySeconds: 10,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: horizonDashboardURL,
Port: intstr.FromString(horizonContainerPortName),
},
},
}
}

0 comments on commit a51f748

Please sign in to comment.