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

fix annotate.go single resource check #29319

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pkg/kubectl/cmd/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,7 @@ func (o *AnnotateOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra

// Validate checks to the AnnotateOptions to see if there is sufficient information run the command.
func (o AnnotateOptions) Validate(args []string) error {
if err := validateAnnotations(o.removeAnnotations, o.newAnnotations); err != nil {
return err
}

// only apply resource version locking on a single resource
if len(o.resources) > 1 && len(o.resourceVersion) > 0 {
return fmt.Errorf("--resource-version may only be used with a single resource")
}

return nil
return validateAnnotations(o.removeAnnotations, o.newAnnotations)
}

// RunAnnotate does the work
Expand All @@ -207,6 +198,17 @@ func (o AnnotateOptions) RunAnnotate() error {
return err
}

var singularResource bool
r.IntoSingular(&singularResource)

// only apply resource version locking on a single resource.
// we must perform this check after o.builder.Do() as
// []o.resources can not not accurately return the proper number
// of resources when they are not passed in "resource/name" format.
if !singularResource && len(o.resourceVersion) > 0 {
return fmt.Errorf("--resource-version may only be used with a single resource")
}

return r.Visit(func(info *resource.Info, err error) error {
if err != nil {
return err
Expand Down