Browse code

api/types/swarm: define type for FailureAction

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/11/05 19:25:31
Showing 3 changed files
... ...
@@ -106,14 +106,19 @@ type ReplicatedJob struct {
106 106
 // This type is deliberately empty.
107 107
 type GlobalJob struct{}
108 108
 
109
+// FailureAction is the action to perform when updating a service fails.
110
+type FailureAction string
111
+
109 112
 const (
110 113
 	// UpdateFailureActionPause PAUSE
111
-	UpdateFailureActionPause = "pause"
114
+	UpdateFailureActionPause FailureAction = "pause"
112 115
 	// UpdateFailureActionContinue CONTINUE
113
-	UpdateFailureActionContinue = "continue"
116
+	UpdateFailureActionContinue FailureAction = "continue"
114 117
 	// UpdateFailureActionRollback ROLLBACK
115
-	UpdateFailureActionRollback = "rollback"
118
+	UpdateFailureActionRollback FailureAction = "rollback"
119
+)
116 120
 
121
+const (
117 122
 	// UpdateOrderStopFirst STOP_FIRST
118 123
 	UpdateOrderStopFirst = "stop-first"
119 124
 	// UpdateOrderStartFirst START_FIRST
... ...
@@ -130,7 +135,7 @@ type UpdateConfig struct {
130 130
 	Delay time.Duration `json:",omitempty"`
131 131
 
132 132
 	// FailureAction is the action to take when an update failures.
133
-	FailureAction string `json:",omitempty"`
133
+	FailureAction FailureAction `json:",omitempty"`
134 134
 
135 135
 	// Monitor indicates how long to monitor a task for failure after it is
136 136
 	// created. If the task fails by ending up in one of the states
... ...
@@ -705,7 +705,7 @@ func setImage(image string) testdaemon.ServiceConstructor {
705 705
 	}
706 706
 }
707 707
 
708
-func setFailureAction(failureAction string) testdaemon.ServiceConstructor {
708
+func setFailureAction(failureAction swarm.FailureAction) testdaemon.ServiceConstructor {
709 709
 	return func(s *swarm.Service) {
710 710
 		s.Spec.UpdateConfig.FailureAction = failureAction
711 711
 	}
... ...
@@ -106,14 +106,19 @@ type ReplicatedJob struct {
106 106
 // This type is deliberately empty.
107 107
 type GlobalJob struct{}
108 108
 
109
+// FailureAction is the action to perform when updating a service fails.
110
+type FailureAction string
111
+
109 112
 const (
110 113
 	// UpdateFailureActionPause PAUSE
111
-	UpdateFailureActionPause = "pause"
114
+	UpdateFailureActionPause FailureAction = "pause"
112 115
 	// UpdateFailureActionContinue CONTINUE
113
-	UpdateFailureActionContinue = "continue"
116
+	UpdateFailureActionContinue FailureAction = "continue"
114 117
 	// UpdateFailureActionRollback ROLLBACK
115
-	UpdateFailureActionRollback = "rollback"
118
+	UpdateFailureActionRollback FailureAction = "rollback"
119
+)
116 120
 
121
+const (
117 122
 	// UpdateOrderStopFirst STOP_FIRST
118 123
 	UpdateOrderStopFirst = "stop-first"
119 124
 	// UpdateOrderStartFirst START_FIRST
... ...
@@ -130,7 +135,7 @@ type UpdateConfig struct {
130 130
 	Delay time.Duration `json:",omitempty"`
131 131
 
132 132
 	// FailureAction is the action to take when an update failures.
133
-	FailureAction string `json:",omitempty"`
133
+	FailureAction FailureAction `json:",omitempty"`
134 134
 
135 135
 	// Monitor indicates how long to monitor a task for failure after it is
136 136
 	// created. If the task fails by ending up in one of the states