Merge pull request #32284 from aaronlehmann/fix-service-defaults

Improve default handling for "service create"
Upstream-commit: a258ef58d8a100467d5d948b026a884ebe58eaf4
Component: engine
This commit is contained in:
Sebastiaan van Stijn
2017-04-11 13:06:53 +02:00
committed by GitHub
26 changed files with 392 additions and 148 deletions
@@ -17,7 +17,7 @@ type Backend interface {
GetUnlockKey() (string, error)
UnlockSwarm(req types.UnlockRequest) error
GetServices(basictypes.ServiceListOptions) ([]types.Service, error)
GetService(string) (types.Service, error)
GetService(idOrName string, insertDefaults bool) (types.Service, error)
CreateService(types.ServiceSpec, string) (*basictypes.ServiceCreateResponse, error)
UpdateService(string, uint64, types.ServiceSpec, basictypes.ServiceUpdateOptions) (*basictypes.ServiceUpdateResponse, error)
RemoveService(string) error
@@ -30,7 +30,7 @@ type Backend interface {
GetTask(string) (types.Task, error)
GetSecrets(opts basictypes.SecretListOptions) ([]types.Secret, error)
CreateSecret(s types.SecretSpec) (string, error)
RemoveSecret(id string) error
RemoveSecret(idOrName string) error
GetSecret(id string) (types.Secret, error)
UpdateSecret(id string, version uint64, spec types.SecretSpec) error
UpdateSecret(idOrName string, version uint64, spec types.SecretSpec) error
}
@@ -151,7 +151,17 @@ func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r
}
func (sr *swarmRouter) getService(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
service, err := sr.backend.GetService(vars["id"])
var insertDefaults bool
if value := r.URL.Query().Get("insertDefaults"); value != "" {
var err error
insertDefaults, err = strconv.ParseBool(value)
if err != nil {
err := fmt.Errorf("invalid value for insertDefaults: %s", value)
return errors.NewBadRequestError(err)
}
}
service, err := sr.backend.GetService(vars["id"], insertDefaults)
if err != nil {
logrus.Errorf("Error getting service %s: %v", vars["id"], err)
return err
@@ -39,7 +39,7 @@ func (sr *swarmRouter) swarmLogs(ctx context.Context, w http.ResponseWriter, r *
// checking for whether logs are TTY involves iterating over every service
// and task. idk if there is a better way
for _, service := range selector.Services {
s, err := sr.backend.GetService(service)
s, err := sr.backend.GetService(service, false)
if err != nil {
// maybe should return some context with this error?
return err
+5
View File
@@ -7584,6 +7584,11 @@ paths:
description: "ID or name of service."
required: true
type: "string"
- name: "insertDefaults"
in: "query"
description: "Fill empty fields with default values."
type: "boolean"
default: false
tags: ["Service"]
delete:
summary: "Delete a service"
+8 -2
View File
@@ -316,12 +316,18 @@ type ServiceUpdateOptions struct {
Rollback string
}
// ServiceListOptions holds parameters to list services with.
// ServiceListOptions holds parameters to list services with.
type ServiceListOptions struct {
Filters filters.Args
}
// TaskListOptions holds parameters to list tasks with.
// ServiceInspectOptions holds parameters related to the "service inspect"
// operation.
type ServiceInspectOptions struct {
InsertDefaults bool
}
// TaskListOptions holds parameters to list tasks with.
type TaskListOptions struct {
Filters filters.Args
}