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

Function PrintClusterResources

tests/utils/utils.go:46–147  ·  view source on GitHub ↗

PrintClusterResources prints a summary of the cluster pods, jobs, pvcs etc.

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

Source from the content-addressed store, hash-verified

44
45// PrintClusterResources prints a summary of the cluster pods, jobs, pvcs etc.
46func PrintClusterResources(ctx context.Context, crudClient client.Client, namespace, clusterName string) string {
47 cluster, err := clusterutils.Get(ctx, crudClient, namespace, clusterName)
48 if err != nil {
49 return fmt.Sprintf("Error while Getting Object %v", err)
50 }
51
52 buffer := &bytes.Buffer{}
53 w := tabwriter.NewWriter(buffer, 0, 0, 4, ' ', 0)
54 clusterInfo := tabby.NewCustom(w)
55 clusterInfo.AddLine("Timeout while waiting for cluster ready, dumping more cluster information for analysis...")
56 clusterInfo.AddLine()
57 clusterInfo.AddLine()
58 clusterInfo.AddLine("Cluster information:")
59 clusterInfo.AddLine("Name", cluster.GetName())
60 clusterInfo.AddLine("Namespace", cluster.GetNamespace())
61 clusterInfo.AddLine()
62 clusterInfo.AddHeader("Items", "Values")
63 clusterInfo.AddLine("Spec.Instances", cluster.Spec.Instances)
64 clusterInfo.AddLine("Wal storage", cluster.ShouldCreateWalArchiveVolume())
65 clusterInfo.AddLine("Cluster phase", cluster.Status.Phase)
66 clusterInfo.AddLine("Phase reason", cluster.Status.PhaseReason)
67 clusterInfo.AddLine("Cluster target primary", cluster.Status.TargetPrimary)
68 clusterInfo.AddLine("Cluster current primary", cluster.Status.CurrentPrimary)
69 clusterInfo.AddLine()
70
71 podList, _ := clusterutils.ListPods(ctx, crudClient, cluster.GetNamespace(), cluster.GetName())
72
73 clusterInfo.AddLine("Cluster Pods information:")
74 clusterInfo.AddLine("Ready pod number: ", utils2.CountReadyPods(podList.Items))
75 clusterInfo.AddLine()
76 clusterInfo.AddHeader("Items", "Values")
77 for i := range podList.Items {
78 pod := &podList.Items[i]
79 clusterInfo.AddLine("Pod name", pod.Name)
80 clusterInfo.AddLine("Pod phase", pod.Status.Phase)
81 if cluster.Status.InstancesReportedState != nil {
82 if instanceReportState, ok := cluster.Status.InstancesReportedState[apiv1.PodName(pod.Name)]; ok {
83 clusterInfo.AddLine("Is Primary", instanceReportState.IsPrimary)
84 clusterInfo.AddLine("TimeLineID", instanceReportState.TimeLineID)
85 clusterInfo.AddLine("---", "---")
86 }
87 } else {
88 clusterInfo.AddLine("InstanceReportState not reported", "")
89 }
90 }
91
92 clusterInfo.AddLine("Jobs information:")
93 clusterInfo.AddLine()
94 clusterInfo.AddHeader("Items", "Values")
95 jobList := &batchv1.JobList{}
96 _ = crudClient.List(
97 ctx, jobList, client.InNamespace(namespace),
98 )
99 for i := range jobList.Items {
100 job := &jobList.Items[i]
101 clusterInfo.AddLine("Job name", job.Name)
102 clusterInfo.AddLine("Job status", fmt.Sprintf("%#v", job.Status))
103 }

Callers

nothing calls this directly

Calls 14

GetFunction · 0.92
ListPodsFunction · 0.92
ListFunction · 0.92
GetPVCListFunction · 0.92
GetSnapshotListFunction · 0.92
GetEventListFunction · 0.92
printPodDiagnosticsFunction · 0.85
printPVCDiagnosticsFunction · 0.85
printNamespaceEventsFunction · 0.85
GetNameMethod · 0.65
GetNamespaceMethod · 0.45

Tested by

no test coverage detected