Skip to content
Permalink
Browse files
feat(cleanup): optimization of cleaning images which are used when im…
…porting

Remove import checksum-based policy and, as a result, use only git history-based policy for such images.

Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Feb 24, 2022
1 parent b0615b0 commit 1b82a476af8d97f4e4abd0852fc4635ad1aac63d
Showing with 3 additions and 30 deletions.
  1. +0 −2 go.sum
  2. +3 −28 pkg/cleaning/cleanup.go
2 go.sum
@@ -1989,8 +1989,6 @@ github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f h1:81YscYTF9mmTf0ULOsCmm
github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f/go.mod h1:OMONwLWU9zEENgaVjWEX+M+xik2QakejzKHG1+6mnUo=
github.com/werf/helm/v3 v3.0.0-20211112190515-e733b755e5af h1:MakPeB2Rpww0G9wYd4Xv7gS1lF0is8M3VstHRU9PP0g=
github.com/werf/helm/v3 v3.0.0-20211112190515-e733b755e5af/go.mod h1:3eOeBD3Z+O/ELiuu19zynZSN8jP1ErXLuyP21SZeMq8=
github.com/werf/kubedog v0.6.3-0.20211020172441-2ae4bcd3d36f h1:TTJxZTkHvsmDQdjjwCHuJ9an2/PshDv75VUxifexC5Y=
github.com/werf/kubedog v0.6.3-0.20211020172441-2ae4bcd3d36f/go.mod h1:QQZtZEKQf9HMKjMkbkrrwX9VDf5XKsn4TVmbWjsHn7M=
github.com/werf/kubedog v0.6.4-0.20220222141823-4ca722ade0ef h1:jidfI8MH4qRvWHlxGw06VKWiKRdBIfGFcjQ3pGwsquc=
github.com/werf/kubedog v0.6.4-0.20220222141823-4ca722ade0ef/go.mod h1:QQZtZEKQf9HMKjMkbkrrwX9VDf5XKsn4TVmbWjsHn7M=
github.com/werf/lockgate v0.0.0-20200729113342-ec2c142f71ea h1:R5tJUhL5a3YfHTrHWyuAdJW3h//fmONrpHJjjAZ79e4=
@@ -60,7 +60,6 @@ func newCleanupManager(projectName string, storageManager *manager.StorageManage
type cleanupManager struct {
stageManager stage_manager.Manager

checksumSourceImageIDs map[string][]string
nonexistentImportMetadataIDs []string

ProjectName string
@@ -702,8 +701,6 @@ FilterOutFinalStages:
}

func (m *cleanupManager) initImportsMetadata(ctx context.Context, stageDescriptionList []*image.StageDescription) error {
m.checksumSourceImageIDs = map[string][]string{}

importMetadataIDs, err := m.StorageManager.GetStagesStorage().GetImportMetadataIDs(ctx, m.ProjectName)
if err != nil {
return err
@@ -726,22 +723,13 @@ func (m *cleanupManager) initImportsMetadata(ctx context.Context, stageDescripti
return nil
}

importSourceID := metadata.ImportSourceID
sourceImageID := metadata.SourceImageID
checksum := metadata.Checksum

mutex.Lock()
defer mutex.Unlock()

sourceImageID := metadata.SourceImageID
importSourceID := metadata.ImportSourceID
stage := findStageByImageID(stageDescriptionList, sourceImageID)
if stage != nil {
sourceImageIDs, ok := m.checksumSourceImageIDs[checksum]
if !ok {
sourceImageIDs = []string{}
}

m.checksumSourceImageIDs[checksum] = append(sourceImageIDs, sourceImageID)
} else {
if stage == nil {
m.nonexistentImportMetadataIDs = append(m.nonexistentImportMetadataIDs, importSourceID)
}

@@ -811,19 +799,6 @@ func (m *cleanupManager) excludeStageAndRelativesByStage(stages []*image.StageDe
}
}

for label, checksum := range stage.Info.Labels {
if strings.HasPrefix(label, image.WerfImportChecksumLabelPrefix) {
sourceImageIDs, ok := m.checksumSourceImageIDs[checksum]
if ok {
for _, sourceImageID := range sourceImageIDs {
var excludedImportStages []*image.StageDescription
stages, excludedImportStages = m.excludeStageAndRelativesByImageID(stages, sourceImageID)
excludedStages = append(excludedStages, excludedImportStages...)
}
}
}
}

return stages, excludedStages
}

0 comments on commit 1b82a47

Please sign in to comment.