better shdTakeSnapshot
This commit is contained in:
parent
b7462742c1
commit
c85d64c8ae
|
|
@ -52,6 +52,6 @@ func (b *BaseCommand) ShouldCacheOutput() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (a *BaseCommand) ShouldDetectDeletedFiles() bool {
|
||||
func (b *BaseCommand) ShouldDetectDeletedFiles() bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,8 +372,7 @@ func (s *stageBuilder) build() error {
|
|||
files = command.FilesToSnapshot()
|
||||
timing.DefaultRun.Stop(t)
|
||||
|
||||
if !s.shouldTakeSnapshot(index, files, command.ProvidesFilesToSnapshot(),
|
||||
command.ShouldDetectDeletedFiles()) {
|
||||
if !s.shouldTakeSnapshot(index, files, command.MetadataOnly()) {
|
||||
continue
|
||||
}
|
||||
if isCacheCommand {
|
||||
|
|
@ -433,7 +432,7 @@ func (s *stageBuilder) takeSnapshot(files []string, shdDelete bool) (string, err
|
|||
return snapshot, err
|
||||
}
|
||||
|
||||
func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, provideFiles bool, detectDeletion bool) bool {
|
||||
func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, isMetadatCmd bool) bool {
|
||||
isLastCommand := index == len(s.cmds)-1
|
||||
|
||||
// We only snapshot the very end with single snapshot mode on.
|
||||
|
|
@ -446,20 +445,8 @@ func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, provideFile
|
|||
return true
|
||||
}
|
||||
|
||||
// if command does not provide files, snapshot everything.
|
||||
if !provideFiles {
|
||||
return true
|
||||
}
|
||||
|
||||
if detectDeletion {
|
||||
return true
|
||||
}
|
||||
// Don't snapshot an empty list.
|
||||
if len(files) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
// if command is a metadata command, do not snapshot.
|
||||
return !isMetadatCmd
|
||||
}
|
||||
|
||||
func (s *stageBuilder) saveSnapshotToImage(createdBy string, tarPath string) error {
|
||||
|
|
|
|||
|
|
@ -103,9 +103,9 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
|
|||
cmds []commands.DockerCommand
|
||||
}
|
||||
type args struct {
|
||||
index int
|
||||
files []string
|
||||
hasFiles bool
|
||||
index int
|
||||
files []string
|
||||
metadataOnly bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
@ -158,9 +158,9 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
|
|||
stage: config.KanikoStage{},
|
||||
},
|
||||
args: args{
|
||||
index: 0,
|
||||
files: []string{},
|
||||
hasFiles: true,
|
||||
index: 0,
|
||||
files: []string{},
|
||||
metadataOnly: true,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
|
|
@ -172,9 +172,9 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
|
|||
},
|
||||
},
|
||||
args: args{
|
||||
index: 0,
|
||||
files: nil,
|
||||
hasFiles: false,
|
||||
index: 0,
|
||||
files: nil,
|
||||
metadataOnly: false,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
|
|
@ -204,7 +204,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
|
|||
opts: tt.fields.opts,
|
||||
cmds: tt.fields.cmds,
|
||||
}
|
||||
if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files, tt.args.hasFiles, false); got != tt.want {
|
||||
if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files, !tt.args.metadataOnly); got != tt.want {
|
||||
t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool) (string,
|
|||
}
|
||||
}
|
||||
}
|
||||
logrus.Infof("whiteouts %s", filesToWhiteout)
|
||||
t := util.NewTar(f)
|
||||
defer t.Close()
|
||||
if err := writeToTar(t, filesToAdd, filesToWhiteout); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue