Change:
<!-- Please only use this template for submitting enhancement requests --What would you like to be : add --list option to kubectl annotate command Why is this needed: like kubectl label commandshow annotations quickly
/sig cli These SIGs are my best guesses for this issue. Please comment if I am incorrect about one. I am a bot run by vllry. ‍
/assign

Discussion:
deps = [ "//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", <ins> "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme:go_default_library", </ins> "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",

"k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" <ins> "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme" </ins> "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/json"

// Common user flags overwrite       bool <ins> list            bool </ins> local           bool dryRunStrategy  cmdutil.DryRunStrategy dryRunVerifier  *resource.DryRunVerifier

o.PrintFlags.AddFlags(cmd) cmd.Flags().BoolVar(&o.overwrite, "overwrite", o.overwrite, "If true, allow annotations to be overwritten, otherwise reject annotation updates that overwrite existing annotations.") <ins> cmd.Flags().BoolVar(&o.list, "list", o.list, "If true, display the annotations for a given resource.") </ins> cmd.Flags().BoolVar(&o.local, "local", o.local, "If true, annotation will NOT contact api-server but run locally.") cmd.Flags().StringVarP(&o.selector, "selector", "l", o.selector, "Selector (label query) to filter on, not including uninitialized ones, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2).") cmd.Flags().StringVar(&o.fieldSelector, "field-selector", o.fieldSelector, "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.")

return printer.PrintObj(obj, out) } <ins> if o.list && len(o.outputFormat) > 0 { return fmt.Errorf("--list and --output may not be specified together") } </ins> o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err

return fmt.Errorf("one or more files must be specified as -f rsrc.yaml or --filename=rsrc.json") } } <del> if len(o.newAnnotations) < 1 && len(o.removeAnnotations) < 1 { </del> <ins> if len(o.newAnnotations) < 1 && len(o.removeAnnotations) < 1 && !o.list { </ins> return fmt.Errorf("at least one annotation update is required") } return validateAnnotations(o.removeAnnotations, o.newAnnotations)

var outputObj runtime.Object obj := info.Object <del> if o.dryRunStrategy == cmdutil.DryRunClient || o.local { </del> <ins> if o.dryRunStrategy == cmdutil.DryRunClient || o.local || o.list { </ins> if err := o.updateAnnotations(obj); err != nil { return err }

} } <ins> if o.list { accessor, err := meta.Accessor(outputObj) if err != nil { return err } indent := "" if !singleItemImpliedResource { indent = " " gvks, _, err := unstructuredscheme.NewUnstructuredObjectTyper().ObjectKinds(info.Object) if err != nil { return err } fmt.Fprintf(o.ErrOut, "Listing annotations for %s.%s/%s:n", gvks[0].Kind, gvks[0].Group, info.Name) } for k, v := range accessor.GetAnnotations() { fmt.Fprintf(o.Out, "%s%s=%sn", indent, k, v) } return nil } </ins> return o.PrintObj(outputObj, o.Out) }) }