Skip to content

refactor parsing restart-policies#4535

Open
thaJeztah wants to merge 1 commit intodocker:masterfrom
thaJeztah:restart_policy_more_validate
Open

refactor parsing restart-policies#4535
thaJeztah wants to merge 1 commit intodocker:masterfrom
thaJeztah:restart_policy_more_validate

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Aug 28, 2023


  • opts.ParseRestartPolicy: use a struct-literal and clarify that this
    function only parses, but does not validate invalid combinations.
  • cli/compose/convert: convertRestartPolicy: update doc to be more
    clear on the order of preference and intent.
  • cli/compose/convert: convertRestartPolicy: use a switch based on
    known values to allow the exhaustive linter to catch missing options.
  • cli/compose/convert: convertRestartPolicy: add validation for negative
    values when converting the legacy service.restart policy.
  • cli/compose/convert: convertRestartPolicy: always set MaxAttempts
    and leave validation to the daemon.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 28, 2023

Codecov Report

❌ Patch coverage is 51.78571% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/compose/convert/service.go 65.90% 12 Missing and 3 partials ⚠️
opts/parse.go 0.00% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@thaJeztah thaJeztah force-pushed the restart_policy_more_validate branch 5 times, most recently from cfd30ac to ced6336 Compare August 28, 2023 21:05
@thaJeztah thaJeztah marked this pull request as ready for review August 29, 2023 12:24
@thaJeztah
Copy link
Copy Markdown
Member Author

⚠️ 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

@thaJeztah thaJeztah modified the milestones: 25.0.0, 26.0.0 Jan 19, 2024
vvoland
vvoland previously approved these changes Feb 21, 2024
@thaJeztah
Copy link
Copy Markdown
Member Author

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.

@vvoland
Copy link
Copy Markdown
Collaborator

vvoland commented Feb 22, 2024

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.

@vvoland vvoland modified the milestones: 26.0.0, 27.0.0 Mar 14, 2024
@vvoland vvoland modified the milestones: 27.0.0, v-future Jun 20, 2024
@vvoland
Copy link
Copy Markdown
Collaborator

vvoland commented Jun 20, 2024

@thaJeztah are we still considering this?

@thaJeztah
Copy link
Copy Markdown
Member Author

I need to look at this one again; it's probably not urgent, so might be fine for later

@thaJeztah thaJeztah force-pushed the restart_policy_more_validate branch from ced6336 to 1fb63eb Compare December 8, 2025 13:46
@thaJeztah thaJeztah force-pushed the restart_policy_more_validate branch 2 times, most recently from 6006ff0 to f1c3df1 Compare April 22, 2026 08:57
@thaJeztah thaJeztah changed the title opts: ParseRestartPolicy: improve validation of max restart-counts refactor parsing restart-policies Apr 22, 2026
@thaJeztah thaJeztah removed this from the v-future milestone Apr 22, 2026
@thaJeztah thaJeztah added this to the 29.5.0 milestone Apr 22, 2026
@thaJeztah thaJeztah added kind/refactor PR's that refactor, or clean-up code and removed impact/changelog kind/enhancement labels Apr 22, 2026
- opts.ParseRestartPolicy: use a struct-literal and clarify that this
  function only parses, but does not validate invalid combinations.
- cli/compose/convert: convertRestartPolicy: update doc to be more
  clear on the order of preference and intent.
- cli/compose/convert: convertRestartPolicy: use a switch based on
  known values to allow the exhaustive linter to catch missing options.
- cli/compose/convert: convertRestartPolicy: add validation for negative
  values when converting the legacy service.restart policy.
- cli/compose/convert: convertRestartPolicy: always set MaxAttempts
  and leave validation to the daemon.

opts: ParseRestartPolicy: improve validation of max restart-counts

Use the new container.ValidateRestartPolicy utility to verify if a max-restart-count
is allowed for the given restart-policy.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the restart_policy_more_validate branch from f1c3df1 to e4a49e1 Compare April 22, 2026 22:53
@thaJeztah
Copy link
Copy Markdown
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants