Skip to content

Commit

Permalink
fix: more correct handling of storage.ErrBrokenImage
Browse files Browse the repository at this point in the history
Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Feb 18, 2022
1 parent bcf8205 commit fbbdd54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/storage/manager/storage_manager.go
Expand Up @@ -549,7 +549,7 @@ func (m *StorageManager) FetchStage(ctx context.Context, containerRuntime contai
return ErrShouldResetStagesStorageCache
}

if err == storage.ErrBrokenImage {
if storage.IsErrBrokenImage(err) {
logboek.Context(ctx).Error().LogF("Invalid stage %s image %q! Stage image is broken and is no longer available in the %s. Stages storage cache for project %q should be reset!\n", stg.LogDetailedName(), stg.GetImage().Name(), m.StagesStorage.String(), m.ProjectName)

logboek.Context(ctx).Error().LogF("Will mark image %q as rejected in the stages storage %s\n", stg.GetImage().Name(), m.StagesStorage.String())
Expand Down Expand Up @@ -994,7 +994,7 @@ func getStageDescription(ctx context.Context, projectName string, stageID image.
logboek.Context(ctx).Debug().LogF("Getting digest %q uniqueID %d stage info from %s...\n", stageID.Digest, stageID.UniqueID, stagesStorage.String())
stageDesc, err := stagesStorage.GetStageDescription(ctx, projectName, stageID.Digest, stageID.UniqueID)
switch {
case err == storage.ErrBrokenImage:
case storage.IsErrBrokenImage(err):
if opts.AllowStagesStorageCacheReset {
stageImageName := stagesStorage.ConstructStageImageName(projectName, stageID.Digest, stageID.UniqueID)

Expand Down
5 changes: 5 additions & 0 deletions pkg/storage/stages_storage.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/werf/werf/pkg/container_runtime"
"github.com/werf/werf/pkg/image"
Expand All @@ -18,6 +19,10 @@ const (

var ErrBrokenImage = errors.New("broken image")

func IsErrBrokenImage(err error) bool {
return err != nil && strings.HasSuffix(err.Error(), ErrBrokenImage.Error())
}

type StagesStorage interface {
GetStagesIDs(ctx context.Context, projectName string) ([]image.StageID, error)
GetStagesIDsByDigest(ctx context.Context, projectName, digest string) ([]image.StageID, error)
Expand Down

0 comments on commit fbbdd54

Please sign in to comment.