MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / DumpNamespaceObjects

Function DumpNamespaceObjects

tests/utils/namespaces/namespace.go:255–359  ·  view source on GitHub ↗

DumpNamespaceObjects logs the clusters, pods, pvcs etc. found in a namespace as JSON sections

(
	ctx context.Context,
	crudClient client.Client,
	namespace, filename string,
)

Source from the content-addressed store, hash-verified

253
254// DumpNamespaceObjects logs the clusters, pods, pvcs etc. found in a namespace as JSON sections
255func DumpNamespaceObjects(
256 ctx context.Context,
257 crudClient client.Client,
258 namespace, filename string,
259) {
260 f, err := os.Create(filepath.Clean(filename))
261 if err != nil {
262 fmt.Println(err)
263 return
264 }
265 defer func() {
266 _ = f.Sync()
267 _ = f.Close()
268 }()
269 w := bufio.NewWriter(f)
270 clusterList := &apiv1.ClusterList{}
271 _ = objects.List(ctx, crudClient, clusterList, client.InNamespace(namespace))
272
273 for _, cluster := range clusterList.Items {
274 out, _ := json.MarshalIndent(cluster, "", " ")
275 _, _ = fmt.Fprintf(w, "Dumping %v/%v cluster\n", namespace, cluster.Name)
276 _, _ = fmt.Fprintln(w, string(out))
277 }
278
279 podList, _ := pods.List(ctx, crudClient, namespace)
280 for _, pod := range podList.Items {
281 out, _ := json.MarshalIndent(pod, "", " ")
282 _, _ = fmt.Fprintf(w, "Dumping %v/%v pod\n", namespace, pod.Name)
283 _, _ = fmt.Fprintln(w, string(out))
284 }
285
286 pvcList, _ := storage.GetPVCList(ctx, crudClient, namespace)
287 for _, pvc := range pvcList.Items {
288 out, _ := json.MarshalIndent(pvc, "", " ")
289 _, _ = fmt.Fprintf(w, "Dumping %v/%v PVC\n", namespace, pvc.Name)
290 _, _ = fmt.Fprintln(w, string(out))
291 }
292
293 jobList := &batchv1.JobList{}
294 _ = crudClient.List(
295 ctx, jobList, client.InNamespace(namespace),
296 )
297 for _, job := range jobList.Items {
298 out, _ := json.MarshalIndent(job, "", " ")
299 _, _ = fmt.Fprintf(w, "Dumping %v/%v job\n", namespace, job.Name)
300 _, _ = fmt.Fprintln(w, string(out))
301 }
302
303 eventList, _ := GetEventList(ctx, crudClient, namespace)
304 out, _ := json.MarshalIndent(eventList.Items, "", " ")
305 _, _ = fmt.Fprintf(w, "Dumping events for namespace %v\n", namespace)
306 _, _ = fmt.Fprintln(w, string(out))
307
308 serviceAccountList, _ := GetServiceAccountList(ctx, crudClient, namespace)
309 for _, sa := range serviceAccountList.Items {
310 out, _ := json.MarshalIndent(sa, "", " ")
311 _, _ = fmt.Fprintf(w, "Dumping %v/%v serviceaccount\n", namespace, sa.Name)
312 _, _ = fmt.Fprintln(w, string(out))

Callers 2

upgrade_test.goFile · 0.92
cleanupNamespaceFunction · 0.85

Calls 12

ListFunction · 0.92
ListFunction · 0.92
GetPVCListFunction · 0.92
ListFunction · 0.92
GetSnapshotListFunction · 0.92
GetEventListFunction · 0.85
GetServiceAccountListFunction · 0.85
GetScheduledBackupListFunction · 0.85
CreateMethod · 0.65
CloseMethod · 0.65
ListMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected