Add support for updating restart policy

This is something Docker does, and we did not do until now. Most
difficult/annoying part was the REST API, where I did not really
want to modify the struct being sent, so I made the new restart
policy parameters query parameters instead.

Testing was also a bit annoying, because testing restart policy
always is.

Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
Matt Heon
2024-04-11 16:38:13 -04:00
parent ddea30e40e
commit 482ef7bfcf
19 changed files with 278 additions and 137 deletions

View File

@ -1,5 +1,9 @@
package define
import (
"fmt"
)
// Valid restart policy types.
const (
// RestartPolicyNone indicates that no restart policy has been requested
@ -27,6 +31,16 @@ var RestartPolicyMap = map[string]string{
RestartPolicyUnlessStopped: RestartPolicyUnlessStopped,
}
// Validate that the given string is a valid restart policy.
func ValidateRestartPolicy(policy string) error {
switch policy {
case RestartPolicyNone, RestartPolicyNo, RestartPolicyOnFailure, RestartPolicyAlways, RestartPolicyUnlessStopped:
return nil
default:
return fmt.Errorf("%q is not a valid restart policy: %w", policy, ErrInvalidArg)
}
}
// InitContainerTypes
const (
// AlwaysInitContainer is an init container that runs on each