mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #29319 from juanvallejo/jvallejo_bugfix/single-resource-version-flag
Automatic merge from submit-queue fix annotate.go single resource check ```release-note Fix issue with kubectl annotate when --resource-version is provided. ``` When using `kubectl annotate` with a `--resource-version` on a resource, such as `kubectl annotate pod <pod_name> --resource-version=1820 description='myannotation'`, the command fails with the error: `error: --resource-version may only be used with a single resource`. Upon printing the output of `resources` that the annotate command receives from cli args, it prints: `Resources:[pod <pod_name>]`. In other words, it treats the name of the resource as a second resource. This PR addresses this issue by using the resource builder `Singular` flag to determine if only a single resource was passed.
This commit is contained in:
commit
8770b2e237
@ -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.
|
// Validate checks to the AnnotateOptions to see if there is sufficient information run the command.
|
||||||
func (o AnnotateOptions) Validate(args []string) error {
|
func (o AnnotateOptions) Validate(args []string) error {
|
||||||
if err := validateAnnotations(o.removeAnnotations, o.newAnnotations); err != nil {
|
return validateAnnotations(o.removeAnnotations, o.newAnnotations)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunAnnotate does the work
|
// RunAnnotate does the work
|
||||||
@ -207,6 +198,17 @@ func (o AnnotateOptions) RunAnnotate() error {
|
|||||||
return err
|
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 {
|
return r.Visit(func(info *resource.Info, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user