MCPcopy
hub / github.com/kubernetes/kubectl / Run

Method Run

pkg/cmd/get/get.go:443–575  ·  view source on GitHub ↗

Run performs the get operation. TODO: remove the need to pass these arguments, like other commands.

(f cmdutil.Factory, args []string)

Source from the content-addressed store, hash-verified

441// Run performs the get operation.
442// TODO: remove the need to pass these arguments, like other commands.
443func (o *GetOptions) Run(f cmdutil.Factory, args []string) error {
444 if len(o.Raw) > 0 {
445 restClient, err := f.RESTClient()
446 if err != nil {
447 return err
448 }
449 return rawhttp.RawGet(restClient, o.IOStreams, o.Raw)
450 }
451 if o.Watch || o.WatchOnly {
452 return o.watch(f, args)
453 }
454
455 chunkSize := o.ChunkSize
456 if len(o.SortBy) > 0 {
457 // TODO(juanvallejo): in the future, we could have the client use chunking
458 // to gather all results, then sort them all at the end to reduce server load.
459 chunkSize = 0
460 }
461
462 r := f.NewBuilder().
463 Unstructured().
464 NamespaceParam(o.Namespace).DefaultNamespace().AllNamespaces(o.AllNamespaces).
465 FilenameParam(o.ExplicitNamespace, &o.FilenameOptions).
466 LabelSelectorParam(o.LabelSelector).
467 FieldSelectorParam(o.FieldSelector).
468 Subresource(o.Subresource).
469 RequestChunksOf(chunkSize).
470 ResourceTypeOrNameArgs(true, args...).
471 ContinueOnError().
472 Latest().
473 Flatten().
474 TransformRequests(o.transformRequests).
475 Do()
476
477 if o.IgnoreNotFound {
478 r.IgnoreErrors(apierrors.IsNotFound)
479 }
480 if err := r.Err(); err != nil {
481 return err
482 }
483
484 if !o.IsHumanReadablePrinter {
485 return o.printGeneric(r)
486 }
487
488 allErrs := []error{}
489 errs := sets.New[string]()
490 infos, err := r.Infos()
491 if err != nil {
492 allErrs = append(allErrs, err)
493 }
494 printWithKind := multipleGVKsRequested(infos)
495
496 objs := make([]runtime.Object, len(infos))
497 for ix := range infos {
498 objs[ix] = infos[ix].Object
499 }
500

Callers 15

NewCmdGetFunction · 0.95
CompGetFromTemplateFunction · 0.95
TestGetSchemaObjectFunction · 0.45
TestGetObjectsFunction · 0.45
TestGetTableObjectsFunction · 0.45
TestGetV1TableObjectsFunction · 0.45
TestGetObjectsShowKindFunction · 0.45

Calls 15

watchMethod · 0.95
printGenericMethod · 0.95
SortMethod · 0.95
OriginalPositionMethod · 0.95
SetReadyMethod · 0.95
RawGetFunction · 0.92
multipleGVKsRequestedFunction · 0.85
NewRuntimeSorterFunction · 0.85
HasMethod · 0.80
RESTClientMethod · 0.65
NewBuilderMethod · 0.65