@@ -60,6 +60,14 @@ type updater struct {
6060 runtime * libpod.Runtime
6161}
6262
63+ const (
64+ statusFailed = "failed" // The update has failed
65+ statusUpdated = "true" // The update succeeded
66+ statusNotUpdated = "false" // No update was needed
67+ statusPending = "pending" // The update is pending (see options.DryRun)
68+ statusRolledBack = "rolled back" // Rollback after a failed update
69+ )
70+
6371// task includes data and state for updating a container
6472type task struct {
6573 authfile string // Container-specific authfile
@@ -233,15 +241,15 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
233241 ImageName : rawImageName ,
234242 Policy : PolicyRegistryImage ,
235243 SystemdUnit : t .unit ,
236- Updated : "failed" ,
244+ Updated : statusFailed ,
237245 }
238246
239247 if _ , updated := t .auto .updatedRawImages [rawImageName ]; updated {
240248 logrus .Infof ("Auto-updating container %q using registry image %q" , cid , rawImageName )
241249 if err := t .auto .restartSystemdUnit (ctx , t .container , t .unit ); err != nil {
242250 return report , err
243251 }
244- report .Updated = "true"
252+ report .Updated = statusUpdated
245253 return report , nil
246254 }
247255
@@ -251,12 +259,12 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
251259 }
252260
253261 if ! needsUpdate {
254- report .Updated = "false"
262+ report .Updated = statusNotUpdated
255263 return report , nil
256264 }
257265
258266 if t .auto .options .DryRun {
259- report .Updated = "pending"
267+ report .Updated = statusPending
260268 return report , nil
261269 }
262270
@@ -268,7 +276,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
268276 logrus .Infof ("Auto-updating container %q using registry image %q" , cid , rawImageName )
269277 updateErr := t .auto .restartSystemdUnit (ctx , t .container , t .unit )
270278 if updateErr == nil {
271- report .Updated = "true"
279+ report .Updated = statusUpdated
272280 return report , nil
273281 }
274282
@@ -286,7 +294,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
286294 return report , fmt .Errorf ("restarting unit with old image during fallback: %w" , err )
287295 }
288296
289- report .Updated = "rolled back"
297+ report .Updated = statusRolledBack
290298 return report , nil
291299}
292300
@@ -308,7 +316,7 @@ func (t *task) updateLocally(ctx context.Context) (*entities.AutoUpdateReport, e
308316 ImageName : rawImageName ,
309317 Policy : PolicyLocalImage ,
310318 SystemdUnit : t .unit ,
311- Updated : "failed" ,
319+ Updated : statusFailed ,
312320 }
313321
314322 needsUpdate , err := newerLocalImageAvailable (t .auto .runtime , t .image , rawImageName )
@@ -317,19 +325,19 @@ func (t *task) updateLocally(ctx context.Context) (*entities.AutoUpdateReport, e
317325 }
318326
319327 if ! needsUpdate {
320- report .Updated = "false"
328+ report .Updated = statusNotUpdated
321329 return report , nil
322330 }
323331
324332 if t .auto .options .DryRun {
325- report .Updated = "pending"
333+ report .Updated = statusPending
326334 return report , nil
327335 }
328336
329337 logrus .Infof ("Auto-updating container %q using local image %q" , cid , rawImageName )
330338 updateErr := t .auto .restartSystemdUnit (ctx , t .container , t .unit )
331339 if updateErr == nil {
332- report .Updated = "true"
340+ report .Updated = statusUpdated
333341 return report , nil
334342 }
335343
@@ -345,7 +353,7 @@ func (t *task) updateLocally(ctx context.Context) (*entities.AutoUpdateReport, e
345353 return report , fmt .Errorf ("restarting unit with old image during fallback: %w" , err )
346354 }
347355
348- report .Updated = "rolled back"
356+ report .Updated = statusRolledBack
349357 return report , nil
350358}
351359
0 commit comments