Skip to content

Commit 6a1d3ac

Browse files
committed
feat(update): make image pruning mode configurable
Add pacman.prune_unused_images configuration key and GetImagePruningFlag() helper to control pruning behavior during update completion. By default, only application images are pruned. When the flag is enabled, all unused images are pruned instead. Apply the selected prune mode consistently across retry attempts in completeUpdate(). Signed-off-by: Mike Sul <mike.sul@foundries.io>
1 parent 28cff3b commit 6a1d3ac

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

pkg/config/config.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ type (
4141
)
4242

4343
const (
44-
TagKey = "pacman.tags"
45-
ServerBaseUrlKey = "tls.server"
46-
StorageDirKey = "storage.path"
47-
StorageDBPathKey = "storage.sqldb_path"
48-
HardwareIDKey = "provision.primary_ecu_hardware_id"
49-
StorageUsageWatermark = "pacman.storage_watermark" // in percentage of overall storage, the maximum allowed to be used by apps
50-
ComposeAppsProxyKey = "pacman.compose_apps_proxy"
51-
ComposeAppsProxyCaKey = "import.tls_cacert_path"
44+
TagKey = "pacman.tags"
45+
ServerBaseUrlKey = "tls.server"
46+
StorageDirKey = "storage.path"
47+
StorageDBPathKey = "storage.sqldb_path"
48+
HardwareIDKey = "provision.primary_ecu_hardware_id"
49+
StorageUsageWatermark = "pacman.storage_watermark" // in percentage of overall storage, the maximum allowed to be used by apps
50+
ComposeAppsProxyKey = "pacman.compose_apps_proxy"
51+
ComposeAppsProxyCaKey = "import.tls_cacert_path"
52+
ComposeAppsPruneUnusedImagesKey = "pacman.prune_unused_images"
5253

5354
StorageDefaultDir = "/var/sota"
5455
StorageDefaultDBPath = "sql.db"
@@ -194,6 +195,10 @@ func (c *Config) SetClientForProxy(client proxyHTTPClient) {
194195
}
195196
}
196197

198+
func (c *Config) GetImagePruningFlag() bool {
199+
return c.tomlConfig.GetDefault(ComposeAppsPruneUnusedImagesKey, "0") == "1"
200+
}
201+
197202
func newComposeConfig(config *sotatoml.AppConfig, proxyProvider compose.ProxyProvider) (*compose.Config, error) {
198203
// TODO: set the defaults in cmd/fioup package instead of here
199204
return v1.NewDefaultConfig(

pkg/state/start.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ func (s *Start) Execute(ctx context.Context, updateCtx *UpdateContext) error {
5757

5858
func (u *UpdateContext) completeUpdate(ctx context.Context) {
5959
var err error
60-
// 1. First attempt with pruning
61-
if err = u.UpdateRunner.Complete(ctx, update.CompleteWithPruning()); err == nil {
60+
// 1. First attempt with app pruning, prune images based on the prune type configured by the user
61+
imagePruneType := compose.PruneTypeOnlyAppImages
62+
if u.Config.GetImagePruningFlag() {
63+
imagePruneType = compose.PruneTypeAllUnusedImages
64+
}
65+
if err = u.UpdateRunner.Complete(ctx, update.CompleteWithPruning(imagePruneType)); err == nil {
6266
return
6367
}
6468
slog.Debug("update completion with pruning failed; retrying", "error", err)
6569
// 2. Second attempt with pruning
66-
if err = u.UpdateRunner.Complete(ctx, update.CompleteWithPruning()); err == nil {
70+
if err = u.UpdateRunner.Complete(ctx, update.CompleteWithPruning(imagePruneType)); err == nil {
6771
return
6872
}
6973
slog.Error("update completion with pruning failed; trying without pruning", "error", err)

0 commit comments

Comments
 (0)