@@ -39,8 +39,8 @@ type State struct {
39
39
Health * Health
40
40
Removed bool `json:"-"`
41
41
42
- stopWaiters []chan <- StateStatus
43
- removeOnlyWaiters []chan <- StateStatus
42
+ stopWaiters []chan <- container. StateStatus
43
+ removeOnlyWaiters []chan <- container. StateStatus
44
44
45
45
// The libcontainerd reference fields are unexported to force consumers
46
46
// to access them through the getter methods with multi-valued returns
@@ -55,21 +55,9 @@ type State struct {
55
55
// Implements exec.ExitCode interface.
56
56
// This type is needed as State include a sync.Mutex field which make
57
57
// copying it unsafe.
58
- type StateStatus struct {
59
- exitCode int
60
- err error
61
- }
62
-
63
- // ExitCode returns current exitcode for the state.
64
- func (s StateStatus ) ExitCode () int {
65
- return s .exitCode
66
- }
67
-
68
- // Err returns current error for the state. Returns nil if the container had
69
- // exited on its own.
70
- func (s StateStatus ) Err () error {
71
- return s .err
72
- }
58
+ //
59
+ // Deprecated: use [container.StateStatus] instead.
60
+ type StateStatus = container.StateStatus
73
61
74
62
// NewState creates a default state object.
75
63
func NewState () * State {
@@ -162,7 +150,9 @@ func IsValidStateString(s string) bool {
162
150
}
163
151
164
152
// WaitCondition is an enum type for different states to wait for.
165
- type WaitCondition int
153
+ //
154
+ // Deprecated: use [container.WaitCondition] instead.
155
+ type WaitCondition = container.WaitCondition
166
156
167
157
// Possible WaitCondition Values.
168
158
//
@@ -176,9 +166,12 @@ type WaitCondition int
176
166
//
177
167
// WaitConditionRemoved is used to wait for the container to be removed.
178
168
const (
179
- WaitConditionNotRunning WaitCondition = iota
180
- WaitConditionNextExit
181
- WaitConditionRemoved
169
+ // Deprecated: use [container.WaitConditionNotRunning] instead.
170
+ WaitConditionNotRunning = container .WaitConditionNotRunning
171
+ // Deprecated: use [container.WaitConditionNextExit] instead.
172
+ WaitConditionNextExit = container .WaitConditionNextExit
173
+ // Deprecated: use [container.WaitConditionRemoved] instead.
174
+ WaitConditionRemoved = container .WaitConditionRemoved
182
175
)
183
176
184
177
// Wait waits until the container is in a certain state indicated by the given
@@ -189,28 +182,25 @@ const (
189
182
// be nil and its ExitCode() method will return the container's exit code,
190
183
// otherwise, the results Err() method will return an error indicating why the
191
184
// wait operation failed.
192
- func (s * State ) Wait (ctx context.Context , condition WaitCondition ) <- chan StateStatus {
185
+ func (s * State ) Wait (ctx context.Context , condition WaitCondition ) <- chan container. StateStatus {
193
186
s .Lock ()
194
187
defer s .Unlock ()
195
188
196
189
// Buffer so we can put status and finish even nobody receives it.
197
- resultC := make (chan StateStatus , 1 )
190
+ resultC := make (chan container. StateStatus , 1 )
198
191
199
192
if s .conditionAlreadyMet (condition ) {
200
- resultC <- StateStatus {
201
- exitCode : s .ExitCode (),
202
- err : s .Err (),
203
- }
193
+ resultC <- container .NewStateStatus (s .ExitCode (), s .Err ())
204
194
205
195
return resultC
206
196
}
207
197
208
- waitC := make (chan StateStatus , 1 )
198
+ waitC := make (chan container. StateStatus , 1 )
209
199
210
200
// Removal wakes up both removeOnlyWaiters and stopWaiters
211
201
// Container could be removed while still in "created" state
212
202
// in which case it is never actually stopped
213
- if condition == WaitConditionRemoved {
203
+ if condition == container . WaitConditionRemoved {
214
204
s .removeOnlyWaiters = append (s .removeOnlyWaiters , waitC )
215
205
} else {
216
206
s .stopWaiters = append (s .stopWaiters , waitC )
@@ -220,10 +210,8 @@ func (s *State) Wait(ctx context.Context, condition WaitCondition) <-chan StateS
220
210
select {
221
211
case <- ctx .Done ():
222
212
// Context timeout or cancellation.
223
- resultC <- StateStatus {
224
- exitCode : - 1 ,
225
- err : ctx .Err (),
226
- }
213
+ resultC <- container .NewStateStatus (- 1 , ctx .Err ())
214
+
227
215
return
228
216
case status := <- waitC :
229
217
resultC <- status
@@ -233,11 +221,11 @@ func (s *State) Wait(ctx context.Context, condition WaitCondition) <-chan StateS
233
221
return resultC
234
222
}
235
223
236
- func (s * State ) conditionAlreadyMet (condition WaitCondition ) bool {
224
+ func (s * State ) conditionAlreadyMet (condition container. WaitCondition ) bool {
237
225
switch condition {
238
- case WaitConditionNotRunning :
226
+ case container . WaitConditionNotRunning :
239
227
return ! s .Running
240
- case WaitConditionRemoved :
228
+ case container . WaitConditionRemoved :
241
229
return s .Removed
242
230
default :
243
231
// TODO(thaJeztah): how do we want to handle "WaitConditionNextExit"?
@@ -423,11 +411,8 @@ func (s *State) Err() error {
423
411
return nil
424
412
}
425
413
426
- func (s * State ) notifyAndClear (waiters * []chan <- StateStatus ) {
427
- result := StateStatus {
428
- exitCode : s .ExitCodeValue ,
429
- err : s .Err (),
430
- }
414
+ func (s * State ) notifyAndClear (waiters * []chan <- container.StateStatus ) {
415
+ result := container .NewStateStatus (s .ExitCodeValue , s .Err ())
431
416
432
417
for _ , c := range * waiters {
433
418
c <- result
0 commit comments