More linting errors

This commit is contained in:
Priya Wadhwa 2018-09-11 13:56:44 -07:00
parent 99ab68e7f4
commit ccb6259b06
6 changed files with 13 additions and 27 deletions

View File

@ -20,7 +20,6 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" "github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1"
"github.com/moby/buildkit/frontend/dockerfile/instructions" "github.com/moby/buildkit/frontend/dockerfile/instructions"
"github.com/sirupsen/logrus"
) )
type ShellCommand struct { type ShellCommand struct {
@ -29,13 +28,7 @@ type ShellCommand struct {
// ExecuteCommand handles command processing similar to CMD and RUN, // ExecuteCommand handles command processing similar to CMD and RUN,
func (s *ShellCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error { func (s *ShellCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error {
logrus.Info("cmd: SHELL") config.Shell = s.cmd.Shell
var newShell []string
newShell = s.cmd.Shell
logrus.Infof("Replacing Shell in config with %v", newShell)
config.Shell = newShell
return nil return nil
} }

View File

@ -54,8 +54,8 @@ func Stages(opts *config.KanikoOptions) ([]config.KanikoStage, error) {
stage.Name = resolvedBaseName stage.Name = resolvedBaseName
kanikoStages = append(kanikoStages, config.KanikoStage{ kanikoStages = append(kanikoStages, config.KanikoStage{
Stage: stage, Stage: stage,
BaseImageIndex: baseImageIndex(opts, index, stages), BaseImageIndex: baseImageIndex(index, stages),
BaseImageStoredLocally: (baseImageIndex(opts, index, stages) != -1), BaseImageStoredLocally: (baseImageIndex(index, stages) != -1),
SaveStage: saveStage(index, stages), SaveStage: saveStage(index, stages),
FinalStage: index == targetStage, 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 // 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 // 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 { for i, stage := range stages {
if i > currentStage { if i > currentStage {
break break

View File

@ -20,7 +20,6 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/testutil" "github.com/GoogleContainerTools/kaniko/testutil"
"github.com/moby/buildkit/frontend/dockerfile/instructions" "github.com/moby/buildkit/frontend/dockerfile/instructions"
) )
@ -184,7 +183,7 @@ func Test_baseImageIndex(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
actual := baseImageIndex(&config.KanikoOptions{}, test.currentStage, stages) actual := baseImageIndex(test.currentStage, stages)
if actual != test.expected { if actual != test.expected {
t.Fatalf("unexpected result, expected %d got %d", test.expected, actual) t.Fatalf("unexpected result, expected %d got %d", test.expected, actual)
} }

View File

@ -228,10 +228,7 @@ func IsSrcRemoteFileURL(rawurl string) bool {
return false return false
} }
_, err = http.Get(rawurl) _, err = http.Get(rawurl)
if err != nil { return err == nil
return false
}
return true
} }
func UpdateConfigEnv(newEnvs []instructions.KeyValuePair, config *v1.Config, replacementEnvs []string) error { func UpdateConfigEnv(newEnvs []instructions.KeyValuePair, config *v1.Config, replacementEnvs []string) error {

View File

@ -109,7 +109,7 @@ func GetFSFromImage(root string, img v1.Image) error {
// DeleteFilesystem deletes the extracted image file system // DeleteFilesystem deletes the extracted image file system
func DeleteFilesystem() error { func DeleteFilesystem() error {
logrus.Info("Deleting filesystem...") 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, _ error) error {
whitelisted, err := CheckWhitelist(path) whitelisted, err := CheckWhitelist(path)
if err != nil { if err != nil {
return err return err
@ -123,7 +123,6 @@ func DeleteFilesystem() error {
} }
return os.RemoveAll(path) return os.RemoveAll(path)
}) })
return err
} }
// ChildDirInWhitelist returns true if there is a child file or directory of the path in the whitelist // ChildDirInWhitelist returns true if there is a child file or directory of the path in the whitelist
@ -310,6 +309,9 @@ func RelativeFiles(fp string, root string) ([]string, error) {
fullPath := filepath.Join(root, fp) fullPath := filepath.Join(root, fp)
logrus.Debugf("Getting files and contents at root %s", fullPath) logrus.Debugf("Getting files and contents at root %s", fullPath)
err := filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
whitelisted, err := CheckWhitelist(path) whitelisted, err := CheckWhitelist(path)
if err != nil { if err != nil {
return err return err

View File

@ -195,10 +195,10 @@ func fileIsCompressedTar(src string) (bool, archive.Compression) {
func fileIsUncompressedTar(src string) bool { func fileIsUncompressedTar(src string) bool {
r, err := os.Open(src) r, err := os.Open(src)
defer r.Close()
if err != nil { if err != nil {
return false return false
} }
defer r.Close()
fi, err := os.Lstat(src) fi, err := os.Lstat(src)
if err != nil { if err != nil {
return false return false
@ -210,13 +210,8 @@ func fileIsUncompressedTar(src string) bool {
if tr == nil { if tr == nil {
return false return false
} }
for { _, err = tr.Next()
_, err := tr.Next() return err == nil
if err != nil {
return false
}
return true
}
} }
// UnpackCompressedTar unpacks the compressed tar at path to dir // UnpackCompressedTar unpacks the compressed tar at path to dir