Skip to content

Commit

Permalink
fix(cleanup): manage custom tags that do not have associated existent…
Browse files Browse the repository at this point in the history
… stages

Keep set of custom tags without associated existent stage while any of them used in Kubernetes.

Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Apr 4, 2022
1 parent c337269 commit ef6efc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/cleaning/cleanup.go
Expand Up @@ -170,12 +170,12 @@ func (m *cleanupManager) run(ctx context.Context) error {

func (m *cleanupManager) skipStageIDsThatAreUsedInKubernetes(ctx context.Context, deployedDockerImagesNames []string) error {
handledDeployedStages := map[string]bool{}
handleTagFunc := func(tag, stageID string) {
handleTagFunc := func(tag, stageID string, f func()) {
dockerImageName := fmt.Sprintf("%s:%s", m.StorageManager.GetStagesStorage().Address(), tag)
for _, deployedDockerImageName := range deployedDockerImagesNames {
if deployedDockerImageName == dockerImageName {
if !handledDeployedStages[stageID] {
m.stageManager.MarkStageAsProtected(stageID)
f()

logboek.Context(ctx).Default().LogFDetails(" tag: %s\n", tag)
logboek.Context(ctx).LogOptionalLn()
Expand All @@ -188,12 +188,22 @@ func (m *cleanupManager) skipStageIDsThatAreUsedInKubernetes(ctx context.Context
}

for _, stageID := range m.stageManager.GetStageIDList() {
handleTagFunc(stageID, stageID)
handleTagFunc(stageID, stageID, func() {
m.stageManager.MarkStageAsProtected(stageID)
})
}

for stageID, customTagList := range m.stageManager.GetCustomTagsMetadata() {
for _, customTag := range customTagList {
handleTagFunc(customTag, stageID)
handleTagFunc(customTag, stageID, func() {
if m.stageManager.IsStageExist(stageID) {
// keep existent stage and associated custom tags
m.stageManager.MarkStageAsProtected(stageID)
} else {
// keep custom tags that do not have associated existent stage
m.stageManager.ForgetCustomTagsByStageID(stageID)
}
})
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/cleaning/stage_manager/manager.go
Expand Up @@ -370,3 +370,7 @@ func (m *Manager) IsStageExist(stageID string) bool {
func (m *Manager) GetCustomTagsMetadata() map[string][]string {
return m.stageIDCustomTagList
}

func (m *Manager) ForgetCustomTagsByStageID(stageID string) {
delete(m.stageIDCustomTagList, stageID)
}

0 comments on commit ef6efc3

Please sign in to comment.