Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate errors while validating attach options #16833

Merged
merged 1 commit into from
Nov 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/kubectl/cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down