MCPcopy
hub / github.com/ahmetb/kubectl-tree / queryAPI

Function queryAPI

cmd/kubectl-tree/query.go:62–98  ·  view source on GitHub ↗
(client dynamic.Interface, api apiResource, allNs bool, labelSelector string)

Source from the content-addressed store, hash-verified

60}
61
62func queryAPI(client dynamic.Interface, api apiResource, allNs bool, labelSelector string) ([]unstructured.Unstructured, error) {
63 var out []unstructured.Unstructured
64
65 var next string
66 var ns string
67
68 if !allNs {
69 ns = getNamespace()
70 }
71 for {
72 var intf dynamic.ResourceInterface
73 nintf := client.Resource(api.GroupVersionResource())
74 if !allNs {
75 intf = nintf.Namespace(ns)
76 } else {
77 intf = nintf
78 }
79 listOptions := metav1.ListOptions{
80 Limit: 250,
81 Continue: next,
82 }
83 if labelSelector != "" {
84 listOptions.LabelSelector = labelSelector
85 }
86 resp, err := intf.List(context.TODO(), listOptions)
87 if err != nil {
88 return nil, fmt.Errorf("listing resources failed (%s): %w", api.GroupVersionResource(), err)
89 }
90 out = append(out, resp.Items...)
91
92 next = resp.GetContinue()
93 if next == "" {
94 break
95 }
96 }
97 return out, nil
98}

Callers 1

getAllResourcesFunction · 0.85

Calls 2

getNamespaceFunction · 0.85
GroupVersionResourceMethod · 0.80

Tested by

no test coverage detected