opts: ParseRestartPolicy: improve validation of max restart-counts
- relates to https://github.com/moby/moby/pull/44704
- [x] depends on https://github.com/docker/cli/pull/4534
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
Codecov Report
:x: Patch coverage is 56.25000% with 21 lines in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| cli/compose/convert/service.go | 71.05% | 8 Missing and 3 partials :warning: |
| opts/parse.go | 0.00% | 10 Missing :warning: |
:loudspeaker: Thoughts on this report? Let us know!
⚠️ For reviewers; I'm leaning two ways on this PR;
- 👍 validate early
- 👎 there IS a potential (although unlikely that these combinations could be supported by a future API version
- 👍 then again, the CLI does not support "future" versions of the API
- 👍 and .. there's already code invalidating "unknown" restart policies
- 🤷♂️ so I guess this doesn't make things worse
Honestly, I'm still a bit on the fence on this one, and not sure how much validation we can do on the client side (as "what's supported" may change on the daemon side, and even between API versions).
To some extent considering if we should go the reverse; just parse the general format, and let the daemon return errors where things are invalid.
I'm kinda neutral here - even if we'd change anything, that would still be gated by the API version which would require a newer CLI anyway.
But on the other hand... We will have the error message even without it, so there's no real gain for the UX.
@thaJeztah are we still considering this?
I need to look at this one again; it's probably not urgent, so might be fine for later
OK; I went the reverse: make the parsing more agnostic, and leave validation to the daemon side, except for the "stack" (compose file) conversion, because for those we still need to map "container" restart policies to "swarm" restart policies.
#18 69.72
#18 69.72 === Failed
#18 69.72 === FAIL: cli/compose/convert TestConvertRestartPolicy/always (0.00s)
#18 69.72 service_test.go:64: assertion failed: &{any <nil> <nil> <nil>} (policy *swarm.RestartPolicy) != &{any <nil> <nil> <nil>} (tc.expected *swarm.RestartPolicy)
#18 69.72
#18 69.72 === FAIL: cli/compose/convert TestConvertRestartPolicy/on-failure:4 (0.00s)
#18 69.72 service_test.go:64: assertion failed: &{on-failure <nil> 0x371e56d2c610 <nil>} (policy *swarm.RestartPolicy) != &{on-failure <nil> 0x371e56c16f60 <nil>} (tc.expected *swarm.RestartPolicy)
#18 69.72
That's weird; I think it was green before and I only updated the import? 🤔
Will have a look when I'm at my computer
Fixed; looks like I had changed a is.DeepEqual to an is.Equal; I probably was trying to simplify the check; should be good now 👍