From b73b99b0d05dc974b4ccdd429b9d496a41e48b57 Mon Sep 17 00:00:00 2001 From: Pete Savage Date: Fri, 14 Jan 2022 09:22:06 +0000 Subject: [PATCH] Fix deployment probes --- .../providers/deployment/impl.go | 61 +++++++++++-------- .../cloud.redhat.com/providers/job/impl.go | 10 +++ 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/controllers/cloud.redhat.com/providers/deployment/impl.go b/controllers/cloud.redhat.com/providers/deployment/impl.go index c8f4963aa..d6193a87c 100644 --- a/controllers/cloud.redhat.com/providers/deployment/impl.go +++ b/controllers/cloud.redhat.com/providers/deployment/impl.go @@ -3,6 +3,7 @@ package deployment import ( "fmt" "strconv" + "strings" crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1/common" @@ -107,42 +108,42 @@ func initDeployment(app *crd.ClowdApp, env *crd.ClowdEnvironment, d *apps.Deploy } if pod.LivenessProbe != nil { livenessProbe = *pod.LivenessProbe + + if livenessProbe.SuccessThreshold == 0 { + livenessProbe.SuccessThreshold = 1 + } + if livenessProbe.TimeoutSeconds == 0 { + livenessProbe.TimeoutSeconds = 1 + } + if livenessProbe.PeriodSeconds == 0 { + livenessProbe.PeriodSeconds = 10 + } + if livenessProbe.FailureThreshold == 0 { + livenessProbe.FailureThreshold = 3 + } } else if bool(deployment.Web) || deployment.WebServices.Public.Enabled { livenessProbe = baseProbe } if pod.ReadinessProbe != nil { readinessProbe = *pod.ReadinessProbe + + if readinessProbe.SuccessThreshold == 0 { + readinessProbe.SuccessThreshold = 1 + } + if readinessProbe.TimeoutSeconds == 0 { + readinessProbe.TimeoutSeconds = 1 + } + if readinessProbe.PeriodSeconds == 0 { + readinessProbe.PeriodSeconds = 10 + } + if readinessProbe.FailureThreshold == 0 { + readinessProbe.FailureThreshold = 3 + } } else if bool(deployment.Web) || deployment.WebServices.Public.Enabled { readinessProbe = baseProbe readinessProbe.InitialDelaySeconds = 45 } - if livenessProbe.SuccessThreshold == 0 { - livenessProbe.SuccessThreshold = 1 - } - if livenessProbe.TimeoutSeconds == 0 { - livenessProbe.TimeoutSeconds = 1 - } - if livenessProbe.PeriodSeconds == 0 { - livenessProbe.PeriodSeconds = 10 - } - if livenessProbe.FailureThreshold == 0 { - livenessProbe.FailureThreshold = 3 - } - - if readinessProbe.SuccessThreshold == 0 { - readinessProbe.SuccessThreshold = 1 - } - if readinessProbe.TimeoutSeconds == 0 { - readinessProbe.TimeoutSeconds = 1 - } - if readinessProbe.PeriodSeconds == 0 { - readinessProbe.PeriodSeconds = 10 - } - if readinessProbe.FailureThreshold == 0 { - readinessProbe.FailureThreshold = 3 - } - c := core.Container{ Name: nn.Name, Image: pod.Image, @@ -158,6 +159,14 @@ func initDeployment(app *crd.ClowdApp, env *crd.ClowdEnvironment, d *apps.Deploy if !env.Spec.Providers.Deployment.OmitPullPolicy { c.ImagePullPolicy = core.PullIfNotPresent + } else { + imageComponents := strings.Split(c.Image, ":") + if len(imageComponents) > 1 { + if imageComponents[1] == "latest" { + c.ImagePullPolicy = core.PullAlways + } + } + c.ImagePullPolicy = core.PullIfNotPresent } if (core.Probe{}) != livenessProbe { diff --git a/controllers/cloud.redhat.com/providers/job/impl.go b/controllers/cloud.redhat.com/providers/job/impl.go index 17346ce2c..15426ffcf 100644 --- a/controllers/cloud.redhat.com/providers/job/impl.go +++ b/controllers/cloud.redhat.com/providers/job/impl.go @@ -1,6 +1,8 @@ package job import ( + "strings" + crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" batchv1 "k8s.io/api/batch/v1" core "k8s.io/api/core/v1" @@ -66,6 +68,14 @@ func CreateJobResource(cji *crd.ClowdJobInvocation, env *crd.ClowdEnvironment, a if !env.Spec.Providers.Deployment.OmitPullPolicy { c.ImagePullPolicy = core.PullIfNotPresent + } else { + imageComponents := strings.Split(c.Image, ":") + if len(imageComponents) > 1 { + if imageComponents[1] == "latest" { + c.ImagePullPolicy = core.PullAlways + } + } + c.ImagePullPolicy = core.PullIfNotPresent } if (core.Probe{}) != livenessProbe {