diff --git a/pkg/commands/shell.go b/pkg/commands/shell.go index bb763828e4..f9f24d4af6 100644 --- a/pkg/commands/shell.go +++ b/pkg/commands/shell.go @@ -29,13 +29,7 @@ type ShellCommand struct { // ExecuteCommand handles command processing similar to CMD and RUN, func (s *ShellCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error { - logrus.Info("cmd: SHELL") - var newShell []string - - newShell = s.cmd.Shell - - logrus.Infof("Replacing Shell in config with %v", newShell) - config.Shell = newShell + config.Shell = s.cmd.Shell return nil } diff --git a/pkg/dockerfile/dockerfile.go b/pkg/dockerfile/dockerfile.go index 5f37a16cf6..00fc71cb78 100644 --- a/pkg/dockerfile/dockerfile.go +++ b/pkg/dockerfile/dockerfile.go @@ -54,8 +54,8 @@ func Stages(opts *config.KanikoOptions) ([]config.KanikoStage, error) { stage.Name = resolvedBaseName kanikoStages = append(kanikoStages, config.KanikoStage{ Stage: stage, - BaseImageIndex: baseImageIndex(opts, index, stages), - BaseImageStoredLocally: (baseImageIndex(opts, index, stages) != -1), + BaseImageIndex: baseImageIndex(index, stages), + BaseImageStoredLocally: (baseImageIndex(index, stages) != -1), SaveStage: saveStage(index, stages), FinalStage: index == targetStage, }) @@ -68,7 +68,7 @@ func Stages(opts *config.KanikoOptions) ([]config.KanikoStage, error) { // baseImageIndex returns the index of the stage the current stage is built off // returns -1 if the current stage isn't built off a previous stage -func baseImageIndex(opts *config.KanikoOptions, currentStage int, stages []instructions.Stage) int { +func baseImageIndex(currentStage int, stages []instructions.Stage) int { for i, stage := range stages { if i > currentStage { break diff --git a/pkg/dockerfile/dockerfile_test.go b/pkg/dockerfile/dockerfile_test.go index bd09c26ba5..76878e5ccb 100644 --- a/pkg/dockerfile/dockerfile_test.go +++ b/pkg/dockerfile/dockerfile_test.go @@ -184,7 +184,7 @@ func Test_baseImageIndex(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - actual := baseImageIndex(&config.KanikoOptions{}, test.currentStage, stages) + actual := baseImageIndex(test.currentStage, stages) if actual != test.expected { t.Fatalf("unexpected result, expected %d got %d", test.expected, actual) } diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index c8bb50709b..b6574faa8d 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -228,10 +228,7 @@ func IsSrcRemoteFileURL(rawurl string) bool { return false } _, err = http.Get(rawurl) - if err != nil { - return false - } - return true + return err == nil } func UpdateConfigEnv(newEnvs []instructions.KeyValuePair, config *v1.Config, replacementEnvs []string) error { diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 4c6dd9ffff..cf719d161c 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -109,7 +109,10 @@ func GetFSFromImage(root string, img v1.Image) error { // DeleteFilesystem deletes the extracted image file system func DeleteFilesystem() error { logrus.Info("Deleting filesystem...") - err := filepath.Walk(constants.RootDir, func(path string, info os.FileInfo, err error) error { + return filepath.Walk(constants.RootDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } whitelisted, err := CheckWhitelist(path) if err != nil { return err @@ -123,7 +126,6 @@ func DeleteFilesystem() error { } return os.RemoveAll(path) }) - return err } // ChildDirInWhitelist returns true if there is a child file or directory of the path in the whitelist @@ -310,6 +312,9 @@ func RelativeFiles(fp string, root string) ([]string, error) { fullPath := filepath.Join(root, fp) logrus.Debugf("Getting files and contents at root %s", fullPath) err := filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } whitelisted, err := CheckWhitelist(path) if err != nil { return err diff --git a/pkg/util/tar_util.go b/pkg/util/tar_util.go index a109d41111..bc1cc67a0c 100644 --- a/pkg/util/tar_util.go +++ b/pkg/util/tar_util.go @@ -195,10 +195,10 @@ func fileIsCompressedTar(src string) (bool, archive.Compression) { func fileIsUncompressedTar(src string) bool { r, err := os.Open(src) - defer r.Close() if err != nil { return false } + defer r.Close() fi, err := os.Lstat(src) if err != nil { return false @@ -210,13 +210,8 @@ func fileIsUncompressedTar(src string) bool { if tr == nil { return false } - for { - _, err := tr.Next() - if err != nil { - return false - } - return true - } + _, err = tr.Next() + return err == nil } // UnpackCompressedTar unpacks the compressed tar at path to dir