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

Function cluster

internal/cmd/plugin/report/cluster_report.go:85–158  ·  view source on GitHub ↗

cluster implements the "report cluster" subcommand Produces a zip file containing - cluster pod and job definitions - cluster resource (same content as `kubectl get cluster -o yaml`) - events in the cluster namespace - logs from the cluster pods (optional - activated with `includeLogs`) - logs from

(ctx context.Context, clusterName, namespace string, format plugin.OutputFormat,
	file string, includeLogs, logTimeStamp bool, timestamp time.Time,
)

Source from the content-addressed store, hash-verified

83// - logs from the cluster pods (optional - activated with `includeLogs`)
84// - logs from the cluster jobs (optional - activated with `includeLogs`)
85func cluster(ctx context.Context, clusterName, namespace string, format plugin.OutputFormat,
86 file string, includeLogs, logTimeStamp bool, timestamp time.Time,
87) error {
88 var events corev1.EventList
89 err := plugin.Client.List(ctx, &events, client.InNamespace(namespace))
90 if err != nil {
91 return fmt.Errorf("could not get events: %w", err)
92 }
93
94 var cluster apiv1.Cluster
95 err = plugin.Client.Get(ctx,
96 types.NamespacedName{Namespace: namespace, Name: clusterName},
97 &cluster)
98 if err != nil {
99 return fmt.Errorf("could not get cluster: %w", err)
100 }
101
102 matchClusterName := client.MatchingLabels{
103 utils.ClusterLabelName: clusterName,
104 }
105
106 var pods corev1.PodList
107 err = plugin.Client.List(ctx, &pods, matchClusterName, client.InNamespace(namespace))
108 if err != nil {
109 return fmt.Errorf("could not get cluster pods: %w", err)
110 }
111
112 var jobs batchv1.JobList
113 err = plugin.Client.List(ctx, &jobs, matchClusterName, client.InNamespace(namespace))
114 if err != nil {
115 return fmt.Errorf("could not get cluster jobs: %w", err)
116 }
117
118 var pvcs corev1.PersistentVolumeClaimList
119 err = plugin.Client.List(ctx, &pvcs, matchClusterName, client.InNamespace(namespace))
120 if err != nil {
121 return fmt.Errorf("could not get cluster pvcs: %w", err)
122 }
123
124 rep := clusterReport{
125 events: events,
126 cluster: cluster,
127 clusterPods: pods,
128 clusterJobs: jobs,
129 clusterPVCs: pvcs,
130 }
131
132 reportZipper := func(zipper *zip.Writer, dirname string) error {
133 return rep.writeToZip(zipper, format, dirname)
134 }
135
136 sections := []zipFileWriter{reportZipper}
137
138 if includeLogs {
139 logsZipper := func(zipper *zip.Writer, dirname string) error {
140 return streamClusterLogsToZip(ctx, clusterName, plugin.Namespace, dirname, logTimeStamp, zipper)
141 }
142

Callers 1

clusterCmdFunction · 0.85

Calls 7

writeToZipMethod · 0.95
streamClusterLogsToZipFunction · 0.85
writeZippedReportFunction · 0.85
reportNameFunction · 0.85
ListMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected