PrintClusterResources prints a summary of the cluster pods, jobs, pvcs etc.
(ctx context.Context, crudClient client.Client, namespace, clusterName string)
| 44 | |
| 45 | // PrintClusterResources prints a summary of the cluster pods, jobs, pvcs etc. |
| 46 | func 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 | } |
nothing calls this directly
no test coverage detected