Do not send zero values in LivenessProbe, blocking deployments in some cases

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-11-06 11:37:47 +01:00
parent f6509ac814
commit 37737c3887
2 changed files with 44 additions and 4 deletions

View File

@ -130,7 +130,7 @@ func ToContainerGroup(ctx context.Context, aciContext store.AciContext, p types.
}
func durationToSeconds(d *types.Duration) *int32 {
if d == nil {
if d == nil || *d == 0 {
return nil
}
v := int32(time.Duration(*d).Seconds())
@ -262,16 +262,19 @@ func (s serviceConfigAciHelper) getLivenessProbe() *containerinstance.ContainerP
if s.HealthCheck.Retries != nil {
retries = to.Int32Ptr(int32(*s.HealthCheck.Retries))
}
return &containerinstance.ContainerProbe{
probe := containerinstance.ContainerProbe{
Exec: &containerinstance.ContainerExec{
Command: to.StringSlicePtr(testArray),
},
InitialDelaySeconds: durationToSeconds(s.HealthCheck.StartPeriod),
PeriodSeconds: durationToSeconds(s.HealthCheck.Interval),
FailureThreshold: retries,
SuccessThreshold: retries,
TimeoutSeconds: durationToSeconds(s.HealthCheck.Timeout),
}
if retries != nil && *retries > 0 {
probe.FailureThreshold = retries
probe.SuccessThreshold = retries
}
return &probe
}
return nil
}

View File

@ -195,6 +195,43 @@ func TestHealthcheckTranslation(t *testing.T) {
assert.Assert(t, (*group.Containers)[0].LivenessProbe == nil)
}
func TestHealthcheckTranslationZeroValues(t *testing.T) {
test := []string{
"my",
"command",
"--option",
}
interval := types.Duration(0)
retries := uint64(0)
startPeriod := types.Duration(0)
timeout := types.Duration(0)
project := types.Project{
Services: []types.ServiceConfig{
{
Name: "service1",
Image: "image1",
HealthCheck: &types.HealthCheckConfig{
Test: test,
Timeout: &timeout,
Interval: &interval,
Retries: &retries,
StartPeriod: &startPeriod,
Disable: false,
},
},
},
}
group, err := ToContainerGroup(context.TODO(), convertCtx, project, mockStorageHelper)
assert.NilError(t, err)
assert.DeepEqual(t, (*group.Containers)[0].LivenessProbe.Exec.Command, to.StringSlicePtr(test))
assert.Assert(t, (*group.Containers)[0].LivenessProbe.PeriodSeconds == nil)
assert.Assert(t, (*group.Containers)[0].LivenessProbe.SuccessThreshold == nil)
assert.Assert(t, (*group.Containers)[0].LivenessProbe.FailureThreshold == nil)
assert.Assert(t, (*group.Containers)[0].LivenessProbe.InitialDelaySeconds == nil)
assert.Assert(t, (*group.Containers)[0].LivenessProbe.TimeoutSeconds == nil)
}
func TestContainerGroupToServiceStatus(t *testing.T) {
myContainerGroup := containerinstance.ContainerGroup{
ContainerGroupProperties: &containerinstance.ContainerGroupProperties{