From a15998f46ca53eeef5bbcb97bc0702656909b454 Mon Sep 17 00:00:00 2001 From: hurf Date: Thu, 5 Nov 2015 10:39:32 +0800 Subject: [PATCH] Aggregate errors while validating attach options Return all errors at a time while validating attach options. --- pkg/kubectl/cmd/attach.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/kubectl/cmd/attach.go b/pkg/kubectl/cmd/attach.go index 4de88e80947..3294e7c1cc5 100644 --- a/pkg/kubectl/cmd/attach.go +++ b/pkg/kubectl/cmd/attach.go @@ -31,6 +31,7 @@ import ( client "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/unversioned/remotecommand" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" + utilerrors "k8s.io/kubernetes/pkg/util/errors" ) const ( @@ -137,16 +138,17 @@ func (p *AttachOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn // Validate checks that the provided attach options are specified. func (p *AttachOptions) Validate() error { + allErrs := []error{} if len(p.PodName) == 0 { - return fmt.Errorf("pod name must be specified") + allErrs = append(allErrs, fmt.Errorf("pod name must be specified")) } if p.Out == nil || p.Err == nil { - return fmt.Errorf("both output and error output must be provided") + allErrs = append(allErrs, fmt.Errorf("both output and error output must be provided")) } if p.Attach == nil || p.Client == nil || p.Config == nil { - return fmt.Errorf("client, client config, and attach must be provided") + allErrs = append(allErrs, fmt.Errorf("client, client config, and attach must be provided")) } - return nil + return utilerrors.NewAggregate(allErrs) } // Run executes a validated remote execution against a pod.