Fix conversion of restart-policy from GRPC
restart-condition for services from "on_failure" to "on-failure".
Since GRPC does not support dashes in properties, this change
added a conversion when _setting_ the restart-condition.
However, when inspecting a service, no conversion took place
from the internal GRPC value, resulting in "on_failure" to
be shown.
This change updates the conversion to fix this, and removes
a "hack" that was previously used for this, now using a
Switch to compare to actual types.
Before this change:
docker service create --name web --restart-condition=on-failure nginx:alpine
docker service inspect --format '{{ json .Spec.TaskTemplate.RestartPolicy }}' web
{"Condition":"on_failure","MaxAttempts":0}
Afer this change:
docker service create --name web --restart-condition=on-failure nginx:alpine
docker service inspect --format '{{ json .Spec.TaskTemplate.RestartPolicy }}' web
{"Condition":"on-failure","MaxAttempts":0}
Signed-off-by: Kay Yan <kay.yan@daocloud.io>
(cherry picked from commit bc32fcabeb
)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
defb41068c
commit
3b9269760c
|
@ -236,7 +236,18 @@ func restartPolicyFromGRPC(p *swarmapi.RestartPolicy) *types.RestartPolicy {
|
|||
var rp *types.RestartPolicy
|
||||
if p != nil {
|
||||
rp = &types.RestartPolicy{}
|
||||
rp.Condition = types.RestartPolicyCondition(strings.ToLower(p.Condition.String()))
|
||||
|
||||
switch p.Condition {
|
||||
case swarmapi.RestartOnNone:
|
||||
rp.Condition = types.RestartPolicyConditionNone
|
||||
case swarmapi.RestartOnFailure:
|
||||
rp.Condition = types.RestartPolicyConditionOnFailure
|
||||
case swarmapi.RestartOnAny:
|
||||
rp.Condition = types.RestartPolicyConditionAny
|
||||
default:
|
||||
rp.Condition = types.RestartPolicyConditionAny
|
||||
}
|
||||
|
||||
if p.Delay != nil {
|
||||
delay, _ := ptypes.Duration(p.Delay)
|
||||
rp.Delay = &delay
|
||||
|
@ -255,13 +266,19 @@ func restartPolicyToGRPC(p *types.RestartPolicy) (*swarmapi.RestartPolicy, error
|
|||
var rp *swarmapi.RestartPolicy
|
||||
if p != nil {
|
||||
rp = &swarmapi.RestartPolicy{}
|
||||
sanatizedCondition := strings.ToUpper(strings.Replace(string(p.Condition), "-", "_", -1))
|
||||
if condition, ok := swarmapi.RestartPolicy_RestartCondition_value[sanatizedCondition]; ok {
|
||||
rp.Condition = swarmapi.RestartPolicy_RestartCondition(condition)
|
||||
} else if string(p.Condition) == "" {
|
||||
|
||||
switch p.Condition {
|
||||
case types.RestartPolicyConditionNone:
|
||||
rp.Condition = swarmapi.RestartOnNone
|
||||
case types.RestartPolicyConditionOnFailure:
|
||||
rp.Condition = swarmapi.RestartOnFailure
|
||||
case types.RestartPolicyConditionAny:
|
||||
rp.Condition = swarmapi.RestartOnAny
|
||||
default:
|
||||
if string(p.Condition) != "" {
|
||||
return nil, fmt.Errorf("invalid RestartCondition: %q", p.Condition)
|
||||
}
|
||||
rp.Condition = swarmapi.RestartOnAny
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid RestartCondition: %q", p.Condition)
|
||||
}
|
||||
|
||||
if p.Delay != nil {
|
||||
|
|
Loading…
Reference in New Issue