@@ -716,9 +716,9 @@ func (m *cleanupManager) cleanupUnusedStages(ctx context.Context) error {
716716 {
717717 for protectionReason , stageDescToKeepSet := range m .stageManager .GetProtectedStageDescSetByReason () {
718718 // Git history based policy keeps import sources more effectively, other policies do not keep them.
719- withImportSources := protectionReason != stage_manager .ProtectionReasonGitPolicy
719+ withImportOrDependencySources := protectionReason != stage_manager .ProtectionReasonGitPolicy
720720 for stageDescToKeep := range stageDescToKeepSet .Iter () {
721- m .protectRelativeStageDescSetByStageDesc (stageDescToKeep , withImportSources )
721+ m .protectRelativeStageDescSetByStageDesc (stageDescToKeep , withImportOrDependencySources )
722722 }
723723 }
724724
@@ -882,7 +882,7 @@ func deleteImportsMetadata(ctx context.Context, projectName string, storageManag
882882 })
883883}
884884
885- func (m * cleanupManager ) protectRelativeStageDescSetByStageDesc (targetStageDesc * image.StageDesc , withImportSource bool ) {
885+ func (m * cleanupManager ) protectRelativeStageDescSetByStageDesc (targetStageDesc * image.StageDesc , withImportOrDependencySources bool ) {
886886 targetStageDescSet := image .NewStageDescSet ()
887887 if targetStageDesc .Info .IsIndex {
888888 for _ , platformImageInfo := range targetStageDesc .Info .Index {
@@ -909,11 +909,11 @@ func (m *cleanupManager) protectRelativeStageDescSetByStageDesc(targetStageDesc
909909 handledStageDescSet .Add (currentStageDesc )
910910 }
911911
912- // Import source checking.
913- if withImportSource {
914- for label , checksum := range currentStageDesc .Info .Labels {
912+ // Import or Dependency source checking.
913+ if withImportOrDependencySources {
914+ for label , value := range currentStageDesc .Info .Labels {
915915 if strings .HasPrefix (label , image .WerfImportChecksumLabelPrefix ) {
916- sourceStageIDs , ok := m .checksumSourceStageIDs [checksum ]
916+ sourceStageIDs , ok := m .checksumSourceStageIDs [value ]
917917 if ! ok {
918918 continue
919919 }
@@ -925,6 +925,12 @@ func (m *cleanupManager) protectRelativeStageDescSetByStageDesc(targetStageDesc
925925 m .stageManager .MarkStageDescAsProtected (sourceStageDesc , stage_manager .ProtectionReasonImportSource , false )
926926 }
927927 }
928+ } else if strings .HasPrefix (label , image .WerfDependencySourceStageIDLabelPrefix ) {
929+ sourceStageDesc := m .stageManager .GetStageDescByStageID (value )
930+ if sourceStageDesc != nil {
931+ currentStageDescSet .Add (sourceStageDesc )
932+ m .stageManager .MarkStageDescAsProtected (sourceStageDesc , stage_manager .ProtectionReasonDependencySource , false )
933+ }
928934 }
929935 }
930936 }
0 commit comments