From d867eadbb0d493eaf24c1aeb1f0d3ee6b91763e4 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 23 Aug 2018 14:27:13 -0700 Subject: [PATCH] Review code comments; improved error messages for push --- cmd/executor/cmd/root.go | 8 ++------ pkg/executor/push.go | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index 517f1cdbf..c05c21b67 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -39,7 +39,8 @@ var ( ) func init() { - addSetupFlags(RootCmd) + RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic") + RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container") addKanikoOptionsFlags(RootCmd) addHiddenFlags(RootCmd) } @@ -76,11 +77,6 @@ var RootCmd = &cobra.Command{ }, } -func addSetupFlags(cmd *cobra.Command) { - RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic") - RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container") -} - // addKanikoOptionsFlags configures opts func addKanikoOptionsFlags(cmd *cobra.Command) { RootCmd.PersistentFlags().StringVarP(&opts.DockerfilePath, "dockerfile", "f", "Dockerfile", "Path to the dockerfile to be built.") diff --git a/pkg/executor/push.go b/pkg/executor/push.go index 9279e3c5a..74bf33b39 100644 --- a/pkg/executor/push.go +++ b/pkg/executor/push.go @@ -29,6 +29,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/tarball" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -52,13 +53,13 @@ func DoPush(image v1.Image, opts *options.KanikoOptions) error { // Push the image destRef, err := name.NewTag(destination, name.WeakValidation) if err != nil { - return err + return errors.Wrap(err, "getting tag for destination") } if opts.DockerInsecureSkipTLSVerify { newReg, err := name.NewInsecureRegistry(destRef.Repository.Registry.Name(), name.WeakValidation) if err != nil { - return err + return errors.Wrap(err, "getting new insecure registry") } destRef.Repository.Registry = newReg } @@ -69,12 +70,12 @@ func DoPush(image v1.Image, opts *options.KanikoOptions) error { k8sc, err := k8schain.NewNoClient() if err != nil { - return err + return errors.Wrap(err, "getting k8schain client") } kc := authn.NewMultiKeychain(authn.DefaultKeychain, k8sc) pushAuth, err := kc.Resolve(destRef.Context().Registry) if err != nil { - return err + return errors.Wrap(err, "resolving pushAuth") } // Create a transport to set our user-agent. @@ -87,8 +88,7 @@ func DoPush(image v1.Image, opts *options.KanikoOptions) error { rt := &withUserAgent{t: tr} if err := remote.Write(destRef, image, pushAuth, rt, remote.WriteOptions{}); err != nil { - logrus.Error(fmt.Errorf("Failed to push to destination %s", destination)) - return err + return errors.Wrap(err, fmt.Sprintf("failed to push to destination %s", destination)) } } return nil