(client dynamic.Interface, api apiResource, allNs bool, labelSelector string)
| 60 | } |
| 61 | |
| 62 | func 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 | } |
no test coverage detected