func restartPolicyToGRPC(p *types.RestartPolicy) (*swarmapi.RestartPolicy, error) { var rp *swarmapi.RestartPolicy if p != nil { rp = &swarmapi.RestartPolicy{} 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 } if p.Delay != nil { rp.Delay = ptypes.DurationProto(*p.Delay) } if p.Window != nil { rp.Window = ptypes.DurationProto(*p.Window) } if p.MaxAttempts != nil { rp.MaxAttempts = *p.MaxAttempts } } return rp, nil }
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) == "" { rp.Condition = swarmapi.RestartOnAny } else { return nil, fmt.Errorf("invalid RestartCondition: %q", p.Condition) } if p.Delay != nil { rp.Delay = ptypes.DurationProto(*p.Delay) } if p.Window != nil { rp.Window = ptypes.DurationProto(*p.Window) } if p.MaxAttempts != nil { rp.MaxAttempts = *p.MaxAttempts } } return rp, nil }