From b552b8b729390ddf761e73dc3bd4eaca8312f1a6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 5 Nov 2025 11:25:31 +0100 Subject: [PATCH 1/3] api/types/swarm: define type for FailureAction Signed-off-by: Sebastiaan van Stijn --- api/types/swarm/service.go | 13 +++++++++---- integration-cli/docker_api_swarm_test.go | 2 +- .../github.com/moby/moby/api/types/swarm/service.go | 13 +++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/api/types/swarm/service.go b/api/types/swarm/service.go index b5a6b4f89a..985e91500d 100644 --- a/api/types/swarm/service.go +++ b/api/types/swarm/service.go @@ -106,14 +106,19 @@ type ReplicatedJob struct { // This type is deliberately empty. type GlobalJob struct{} +// FailureAction is the action to perform when updating a service fails. +type FailureAction string + const ( // UpdateFailureActionPause PAUSE - UpdateFailureActionPause = "pause" + UpdateFailureActionPause FailureAction = "pause" // UpdateFailureActionContinue CONTINUE - UpdateFailureActionContinue = "continue" + UpdateFailureActionContinue FailureAction = "continue" // UpdateFailureActionRollback ROLLBACK - UpdateFailureActionRollback = "rollback" + UpdateFailureActionRollback FailureAction = "rollback" +) +const ( // UpdateOrderStopFirst STOP_FIRST UpdateOrderStopFirst = "stop-first" // UpdateOrderStartFirst START_FIRST @@ -130,7 +135,7 @@ type UpdateConfig struct { Delay time.Duration `json:",omitempty"` // FailureAction is the action to take when an update failures. - FailureAction string `json:",omitempty"` + FailureAction FailureAction `json:",omitempty"` // Monitor indicates how long to monitor a task for failure after it is // created. If the task fails by ending up in one of the states diff --git a/integration-cli/docker_api_swarm_test.go b/integration-cli/docker_api_swarm_test.go index d8243af167..05344f4cbb 100644 --- a/integration-cli/docker_api_swarm_test.go +++ b/integration-cli/docker_api_swarm_test.go @@ -705,7 +705,7 @@ func setImage(image string) testdaemon.ServiceConstructor { } } -func setFailureAction(failureAction string) testdaemon.ServiceConstructor { +func setFailureAction(failureAction swarm.FailureAction) testdaemon.ServiceConstructor { return func(s *swarm.Service) { s.Spec.UpdateConfig.FailureAction = failureAction } diff --git a/vendor/github.com/moby/moby/api/types/swarm/service.go b/vendor/github.com/moby/moby/api/types/swarm/service.go index b5a6b4f89a..985e91500d 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/service.go +++ b/vendor/github.com/moby/moby/api/types/swarm/service.go @@ -106,14 +106,19 @@ type ReplicatedJob struct { // This type is deliberately empty. type GlobalJob struct{} +// FailureAction is the action to perform when updating a service fails. +type FailureAction string + const ( // UpdateFailureActionPause PAUSE - UpdateFailureActionPause = "pause" + UpdateFailureActionPause FailureAction = "pause" // UpdateFailureActionContinue CONTINUE - UpdateFailureActionContinue = "continue" + UpdateFailureActionContinue FailureAction = "continue" // UpdateFailureActionRollback ROLLBACK - UpdateFailureActionRollback = "rollback" + UpdateFailureActionRollback FailureAction = "rollback" +) +const ( // UpdateOrderStopFirst STOP_FIRST UpdateOrderStopFirst = "stop-first" // UpdateOrderStartFirst START_FIRST @@ -130,7 +135,7 @@ type UpdateConfig struct { Delay time.Duration `json:",omitempty"` // FailureAction is the action to take when an update failures. - FailureAction string `json:",omitempty"` + FailureAction FailureAction `json:",omitempty"` // Monitor indicates how long to monitor a task for failure after it is // created. If the task fails by ending up in one of the states From d299e5be837563ed89a865ec9b71236ba20c2f73 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 5 Nov 2025 11:37:15 +0100 Subject: [PATCH 2/3] api/types/swarm: define type for UpdateOrder Signed-off-by: Sebastiaan van Stijn --- api/types/swarm/service.go | 10 +++++++--- integration-cli/docker_api_swarm_test.go | 4 ++-- vendor/github.com/moby/moby/api/types/swarm/service.go | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/api/types/swarm/service.go b/api/types/swarm/service.go index 985e91500d..90df7deeed 100644 --- a/api/types/swarm/service.go +++ b/api/types/swarm/service.go @@ -118,11 +118,15 @@ const ( UpdateFailureActionRollback FailureAction = "rollback" ) +// UpdateOrder is the order of operations when rolling out or rolling back +// an updated tasks for a service. +type UpdateOrder string + const ( // UpdateOrderStopFirst STOP_FIRST - UpdateOrderStopFirst = "stop-first" + UpdateOrderStopFirst UpdateOrder = "stop-first" // UpdateOrderStartFirst START_FIRST - UpdateOrderStartFirst = "start-first" + UpdateOrderStartFirst UpdateOrder = "start-first" ) // UpdateConfig represents the update configuration. @@ -161,7 +165,7 @@ type UpdateConfig struct { // Order indicates the order of operations when rolling out an updated // task. Either the old task is shut down before the new task is // started, or the new task is started before the old task is shut down. - Order string + Order UpdateOrder } // ServiceStatus represents the number of running tasks in a service and the diff --git a/integration-cli/docker_api_swarm_test.go b/integration-cli/docker_api_swarm_test.go index 05344f4cbb..0721935f22 100644 --- a/integration-cli/docker_api_swarm_test.go +++ b/integration-cli/docker_api_swarm_test.go @@ -678,7 +678,7 @@ func setInstances(replicas int) testdaemon.ServiceConstructor { } } -func setUpdateOrder(order string) testdaemon.ServiceConstructor { +func setUpdateOrder(order swarm.UpdateOrder) testdaemon.ServiceConstructor { return func(s *swarm.Service) { if s.Spec.UpdateConfig == nil { s.Spec.UpdateConfig = &swarm.UpdateConfig{} @@ -687,7 +687,7 @@ func setUpdateOrder(order string) testdaemon.ServiceConstructor { } } -func setRollbackOrder(order string) testdaemon.ServiceConstructor { +func setRollbackOrder(order swarm.UpdateOrder) testdaemon.ServiceConstructor { return func(s *swarm.Service) { if s.Spec.RollbackConfig == nil { s.Spec.RollbackConfig = &swarm.UpdateConfig{} diff --git a/vendor/github.com/moby/moby/api/types/swarm/service.go b/vendor/github.com/moby/moby/api/types/swarm/service.go index 985e91500d..90df7deeed 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/service.go +++ b/vendor/github.com/moby/moby/api/types/swarm/service.go @@ -118,11 +118,15 @@ const ( UpdateFailureActionRollback FailureAction = "rollback" ) +// UpdateOrder is the order of operations when rolling out or rolling back +// an updated tasks for a service. +type UpdateOrder string + const ( // UpdateOrderStopFirst STOP_FIRST - UpdateOrderStopFirst = "stop-first" + UpdateOrderStopFirst UpdateOrder = "stop-first" // UpdateOrderStartFirst START_FIRST - UpdateOrderStartFirst = "start-first" + UpdateOrderStartFirst UpdateOrder = "start-first" ) // UpdateConfig represents the update configuration. @@ -161,7 +165,7 @@ type UpdateConfig struct { // Order indicates the order of operations when rolling out an updated // task. Either the old task is shut down before the new task is // started, or the new task is started before the old task is shut down. - Order string + Order UpdateOrder } // ServiceStatus represents the number of running tasks in a service and the From 39ccd04ca8dc023d723a4b9221589c781a9fce40 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 5 Nov 2025 11:45:22 +0100 Subject: [PATCH 3/3] api/types/swarm: define type for RegistryAuthSource Signed-off-by: Sebastiaan van Stijn --- api/types/swarm/service.go | 8 ++++++-- client/service_update.go | 4 ++-- daemon/server/router/swarm/cluster_routes.go | 9 ++++++++- daemon/server/swarmbackend/swarm.go | 7 +++++-- vendor/github.com/moby/moby/api/types/swarm/service.go | 8 ++++++-- vendor/github.com/moby/moby/client/service_update.go | 4 ++-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/api/types/swarm/service.go b/api/types/swarm/service.go index 90df7deeed..0b678dea33 100644 --- a/api/types/swarm/service.go +++ b/api/types/swarm/service.go @@ -207,8 +207,12 @@ type JobStatus struct { LastExecution time.Time `json:",omitempty"` } +// RegistryAuthSource defines options for the "registryAuthFrom" query parameter +// on service update. +type RegistryAuthSource string + // Values for RegistryAuthFrom in ServiceUpdateOptions const ( - RegistryAuthFromSpec = "spec" - RegistryAuthFromPreviousSpec = "previous-spec" + RegistryAuthFromSpec RegistryAuthSource = "spec" + RegistryAuthFromPreviousSpec RegistryAuthSource = "previous-spec" ) diff --git a/client/service_update.go b/client/service_update.go index 36061c9d16..9e6b52781e 100644 --- a/client/service_update.go +++ b/client/service_update.go @@ -28,7 +28,7 @@ type ServiceUpdateOptions struct { // RegistryAuthFrom specifies where to find the registry authorization // credentials if they are not given in EncodedRegistryAuth. Valid // values are "spec" and "previous-spec". - RegistryAuthFrom string + RegistryAuthFrom swarm.RegistryAuthSource // Rollback indicates whether a server-side rollback should be // performed. When this is set, the provided spec will be ignored. @@ -65,7 +65,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, options query := url.Values{} if options.RegistryAuthFrom != "" { - query.Set("registryAuthFrom", options.RegistryAuthFrom) + query.Set("registryAuthFrom", string(options.RegistryAuthFrom)) } if options.Rollback != "" { diff --git a/daemon/server/router/swarm/cluster_routes.go b/daemon/server/router/swarm/cluster_routes.go index 7b47198c99..e4ec2d9757 100644 --- a/daemon/server/router/swarm/cluster_routes.go +++ b/daemon/server/router/swarm/cluster_routes.go @@ -276,7 +276,14 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter, // Get returns "" if the header does not exist flags.EncodedRegistryAuth = r.Header.Get(registry.AuthHeader) - flags.RegistryAuthFrom = r.URL.Query().Get("registryAuthFrom") + if v := r.URL.Query().Get("registryAuthFrom"); v != "" { + switch val := types.RegistryAuthSource(v); val { + case types.RegistryAuthFromSpec, types.RegistryAuthFromPreviousSpec: + flags.RegistryAuthFrom = val + default: + return errdefs.InvalidParameter(fmt.Errorf("invalid registryAuthFrom '%s'", v)) + } + } flags.Rollback = r.URL.Query().Get("rollback") queryRegistry := false if v := httputils.VersionFromContext(ctx); v != "" { diff --git a/daemon/server/swarmbackend/swarm.go b/daemon/server/swarmbackend/swarm.go index e18cbe27c4..7419da0162 100644 --- a/daemon/server/swarmbackend/swarm.go +++ b/daemon/server/swarmbackend/swarm.go @@ -1,6 +1,9 @@ package swarmbackend -import "github.com/moby/moby/v2/daemon/internal/filters" +import ( + "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/v2/daemon/internal/filters" +) type ConfigListOptions struct { Filters filters.Args @@ -34,7 +37,7 @@ type ServiceUpdateOptions struct { // RegistryAuthFrom specifies where to find the registry authorization // credentials if they are not given in EncodedRegistryAuth. Valid // values are "spec" and "previous-spec". - RegistryAuthFrom string + RegistryAuthFrom swarm.RegistryAuthSource // Rollback indicates whether a server-side rollback should be // performed. When this is set, the provided spec will be ignored. diff --git a/vendor/github.com/moby/moby/api/types/swarm/service.go b/vendor/github.com/moby/moby/api/types/swarm/service.go index 90df7deeed..0b678dea33 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/service.go +++ b/vendor/github.com/moby/moby/api/types/swarm/service.go @@ -207,8 +207,12 @@ type JobStatus struct { LastExecution time.Time `json:",omitempty"` } +// RegistryAuthSource defines options for the "registryAuthFrom" query parameter +// on service update. +type RegistryAuthSource string + // Values for RegistryAuthFrom in ServiceUpdateOptions const ( - RegistryAuthFromSpec = "spec" - RegistryAuthFromPreviousSpec = "previous-spec" + RegistryAuthFromSpec RegistryAuthSource = "spec" + RegistryAuthFromPreviousSpec RegistryAuthSource = "previous-spec" ) diff --git a/vendor/github.com/moby/moby/client/service_update.go b/vendor/github.com/moby/moby/client/service_update.go index 36061c9d16..9e6b52781e 100644 --- a/vendor/github.com/moby/moby/client/service_update.go +++ b/vendor/github.com/moby/moby/client/service_update.go @@ -28,7 +28,7 @@ type ServiceUpdateOptions struct { // RegistryAuthFrom specifies where to find the registry authorization // credentials if they are not given in EncodedRegistryAuth. Valid // values are "spec" and "previous-spec". - RegistryAuthFrom string + RegistryAuthFrom swarm.RegistryAuthSource // Rollback indicates whether a server-side rollback should be // performed. When this is set, the provided spec will be ignored. @@ -65,7 +65,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, options query := url.Values{} if options.RegistryAuthFrom != "" { - query.Set("registryAuthFrom", options.RegistryAuthFrom) + query.Set("registryAuthFrom", string(options.RegistryAuthFrom)) } if options.Rollback != "" {