Skip to content
Permalink
Browse files
fix(cleanup): manage custom tags that do not have associated existent…
… 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 ef6efc3718a61248d08ee8230c347245d073ff0d
Showing with 18 additions and 4 deletions.
  1. +14 −4 pkg/cleaning/cleanup.go
  2. +4 −0 pkg/cleaning/stage_manager/manager.go
@@ -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()
@@ -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)
}
})
}
}

@@ -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.