Skip to content

Commit

Permalink
Merge pull request #3092 from thaJeztah/fix_healthcheck_interval
Browse files Browse the repository at this point in the history
frontend: fix Healthcheck intervals and retries not accepting default values
  • Loading branch information
crazy-max authored Sep 8, 2022
2 parents 7b34166 + 20c7fda commit abde08a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions frontend/dockerfile/instructions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func nodeArgs(node *parser.Node) []string {
if len(arg.Children) == 0 {
result = append(result, arg.Value)
} else if len(arg.Children) == 1 {
//sub command
// sub command
result = append(result, arg.Children[0].Value)
result = append(result, nodeArgs(arg.Children[0])...)
}
Expand Down Expand Up @@ -505,6 +505,9 @@ func parseOptInterval(f *Flag) (time.Duration, error) {
if err != nil {
return 0, err
}
if d == 0 {
return 0, nil
}
if d < container.MinimumDuration {
return 0, fmt.Errorf("Interval %#v cannot be less than %s", f.name, container.MinimumDuration)
}
Expand Down Expand Up @@ -579,8 +582,8 @@ func parseHealthcheck(req parseRequest) (*HealthCheckCommand, error) {
if err != nil {
return nil, err
}
if retries < 1 {
return nil, fmt.Errorf("--retries must be at least 1 (not %d)", retries)
if retries < 0 {
return nil, fmt.Errorf("--retries cannot be negative (%d)", retries)
}
healthcheck.Retries = int(retries)
} else {
Expand Down
4 changes: 4 additions & 0 deletions frontend/dockerfile/instructions/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func TestParseOptInterval(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "cannot be less than 1ms")

flInterval.Value = "0ms"
_, err = parseOptInterval(flInterval)
require.NoError(t, err)

flInterval.Value = "1ms"
_, err = parseOptInterval(flInterval)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions frontend/dockerfile/parser/testfiles/health/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ HEALTHCHECK CMD
HEALTHCHECK CMD a b
HEALTHCHECK --timeout=3s CMD ["foo"]
HEALTHCHECK CONNECT TCP 7000
HEALTHCHECK --start-period=0s --interval=5s --timeout=0s --retries=0 CMD ["foo"]
1 change: 1 addition & 0 deletions frontend/dockerfile/parser/testfiles/health/result
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
(healthcheck "CMD" "a b")
(healthcheck ["--timeout=3s"] "CMD" "foo")
(healthcheck "CONNECT" "TCP 7000")
(healthcheck ["--start-period=0s" "--interval=5s" "--timeout=0s" "--retries=0"] "CMD" "foo")

0 comments on commit abde08a

Please sign in to comment.