aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@redhat.com>2022-08-03 13:49:04 +0200
committerValentin Rothberg <vrothberg@redhat.com>2022-08-04 13:07:58 +0200
commit1cc933c6bb1dbbab56bc1918db4ae358c56bba8b (patch)
tree4f1272118c86e8a33fbb1807254d7de1148c24e6
parent42c4c17c01af746cd1424878a397cb6eeb9c65dd (diff)
downloadpodman-1cc933c6bb1dbbab56bc1918db4ae358c56bba8b.tar.gz
podman-1cc933c6bb1dbbab56bc1918db4ae358c56bba8b.tar.bz2
podman-1cc933c6bb1dbbab56bc1918db4ae358c56bba8b.zip
pkg/autoupdate: introduce status constants
To replace redundant string scattered across the code with proper constants. The "status" will further be useful in a future change as it can be moved into a `task`. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
-rw-r--r--pkg/autoupdate/autoupdate.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go
index 89d0a1ac3..2db85df5d 100644
--- a/pkg/autoupdate/autoupdate.go
+++ b/pkg/autoupdate/autoupdate.go
@@ -60,6 +60,14 @@ type updater struct {
runtime *libpod.Runtime
}
+const (
+ statusFailed = "failed" // The update has failed
+ statusUpdated = "true" // The update succeeded
+ statusNotUpdated = "false" // No update was needed
+ statusPending = "pending" // The update is pending (see options.DryRun)
+ statusRolledBack = "rolled back" // Rollback after a failed update
+)
+
// task includes data and state for updating a container
type task struct {
authfile string // Container-specific authfile
@@ -233,7 +241,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
ImageName: rawImageName,
Policy: PolicyRegistryImage,
SystemdUnit: t.unit,
- Updated: "failed",
+ Updated: statusFailed,
}
if _, updated := t.auto.updatedRawImages[rawImageName]; updated {
@@ -241,7 +249,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
if err := t.auto.restartSystemdUnit(ctx, t.container, t.unit); err != nil {
return report, err
}
- report.Updated = "true"
+ report.Updated = statusUpdated
return report, nil
}
@@ -251,12 +259,12 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
}
if !needsUpdate {
- report.Updated = "false"
+ report.Updated = statusNotUpdated
return report, nil
}
if t.auto.options.DryRun {
- report.Updated = "pending"
+ report.Updated = statusPending
return report, nil
}
@@ -268,7 +276,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
logrus.Infof("Auto-updating container %q using registry image %q", cid, rawImageName)
updateErr := t.auto.restartSystemdUnit(ctx, t.container, t.unit)
if updateErr == nil {
- report.Updated = "true"
+ report.Updated = statusUpdated
return report, nil
}
@@ -286,7 +294,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
return report, fmt.Errorf("restarting unit with old image during fallback: %w", err)
}
- report.Updated = "rolled back"
+ report.Updated = statusRolledBack
return report, nil
}
@@ -308,7 +316,7 @@ func (t *task) updateLocally(ctx context.Context) (*entities.AutoUpdateReport, e
ImageName: rawImageName,
Policy: PolicyLocalImage,
SystemdUnit: t.unit,
- Updated: "failed",
+ Updated: statusFailed,
}
needsUpdate, err := newerLocalImageAvailable(t.auto.runtime, t.image, rawImageName)
@@ -317,19 +325,19 @@ func (t *task) updateLocally(ctx context.Context) (*entities.AutoUpdateReport, e
}
if !needsUpdate {
- report.Updated = "false"
+ report.Updated = statusNotUpdated
return report, nil
}
if t.auto.options.DryRun {
- report.Updated = "pending"
+ report.Updated = statusPending
return report, nil
}
logrus.Infof("Auto-updating container %q using local image %q", cid, rawImageName)
updateErr := t.auto.restartSystemdUnit(ctx, t.container, t.unit)
if updateErr == nil {
- report.Updated = "true"
+ report.Updated = statusUpdated
return report, nil
}
@@ -345,7 +353,7 @@ func (t *task) updateLocally(ctx context.Context) (*entities.AutoUpdateReport, e
return report, fmt.Errorf("restarting unit with old image during fallback: %w", err)
}
- report.Updated = "rolled back"
+ report.Updated = statusRolledBack
return report, nil
}