Skip to content

Commit b258f9c

Browse files
authored
Add pgbackrest info to support export (#81)
* Add pgbackrest info to support export Issue: PGO-648
1 parent 6e833b7 commit b258f9c

File tree

3 files changed

+88
-28
lines changed

3 files changed

+88
-28
lines changed

docs/content/reference/pgo_support_export.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Collecting Postgres logs...
9696
Collecting PostgresCluster pod logs...
9797
Collecting monitoring pod logs...
9898
Collecting Patroni info...
99+
Collecting pgBackRest info...
99100
Collecting processes...
100101
Collecting system times from containers...
101102
Collecting PGO CLI logs...

internal/cmd/export.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ Collecting Postgres logs...
259259
Collecting PostgresCluster pod logs...
260260
Collecting monitoring pod logs...
261261
Collecting Patroni info...
262+
Collecting pgBackRest info...
262263
Collecting processes...
263264
Collecting system times from containers...
264265
Collecting PGO CLI logs...
@@ -434,6 +435,10 @@ Collecting PGO CLI logs...
434435
err = gatherPatroniInfo(ctx, clientset, restConfig, namespace, clusterName, tw, cmd)
435436
}
436437

438+
if err == nil {
439+
err = gatherPgBackRestInfo(ctx, clientset, restConfig, namespace, clusterName, tw, cmd)
440+
}
441+
437442
// Exec to get Container processes
438443
if err == nil {
439444
err = gatherProcessInfo(ctx, clientset, restConfig, namespace, clusterName, tw, cmd)
@@ -994,7 +999,7 @@ func gatherPodLogs(ctx context.Context,
994999
return nil
9951000
}
9961001

997-
// gatherExecInfo takes a client and buffer
1002+
// gatherPatroniInfo takes a client and buffer
9981003
// execs into relevant pods to grab information
9991004
func gatherPatroniInfo(ctx context.Context,
10001005
clientset *kubernetes.Clientset,
@@ -1072,6 +1077,65 @@ func gatherPatroniInfo(ctx context.Context,
10721077
return nil
10731078
}
10741079

1080+
// gatherPgBackRestInfo takes a client and buffer
1081+
// execs into relevant pods to grab information
1082+
func gatherPgBackRestInfo(ctx context.Context,
1083+
clientset *kubernetes.Clientset,
1084+
config *rest.Config,
1085+
namespace string,
1086+
clusterName string,
1087+
tw *tar.Writer,
1088+
cmd *cobra.Command,
1089+
) error {
1090+
writeInfo(cmd, "Collecting pgBackRest info...")
1091+
// Get the primary instance Pod by its labels
1092+
pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
1093+
LabelSelector: util.PrimaryInstanceLabels(clusterName),
1094+
})
1095+
if err != nil {
1096+
if apierrors.IsForbidden(err) {
1097+
writeInfo(cmd, err.Error())
1098+
return nil
1099+
}
1100+
return err
1101+
}
1102+
if len(pods.Items) < 1 {
1103+
writeInfo(cmd, "No pod found for pgBackRest info")
1104+
return nil
1105+
}
1106+
1107+
podExec, err := util.NewPodExecutor(config)
1108+
if err != nil {
1109+
return err
1110+
}
1111+
1112+
exec := func(stdin io.Reader, stdout, stderr io.Writer, command ...string,
1113+
) error {
1114+
return podExec(namespace, pods.Items[0].GetName(), util.ContainerDatabase,
1115+
stdin, stdout, stderr, command...)
1116+
}
1117+
1118+
var buf bytes.Buffer
1119+
1120+
buf.Write([]byte("pgbackrest info\n"))
1121+
stdout, stderr, err := Executor(exec).pgBackRestInfo("text", "")
1122+
if err != nil {
1123+
if apierrors.IsForbidden(err) {
1124+
writeInfo(cmd, err.Error())
1125+
return nil
1126+
}
1127+
return err
1128+
}
1129+
1130+
buf.Write([]byte(stdout))
1131+
if stderr != "" {
1132+
buf.Write([]byte(stderr))
1133+
}
1134+
1135+
path := clusterName + "/pgbackrest-info"
1136+
return writeTar(tw, buf.Bytes(), path, cmd)
1137+
}
1138+
10751139
// gatherSystemTime takes a client and buffer and collects system time
10761140
// in each Pod and calculates the delta against client system time.
10771141
func gatherSystemTime(ctx context.Context,

testing/kuttl/e2e/support-export/01--support_export.yaml

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ commands:
88
#!/bin/bash
99
1010
CLEANUP="rm -r ./kuttl-support-cluster ./crunchy_k8s_support_export_*.tar.gz"
11+
check_file() {
12+
if [[ ! -s ./kuttl-support-cluster/"${1}" ]]
13+
then
14+
echo "Expected ${1} file to not be empty"
15+
eval "$CLEANUP"
16+
exit 1
17+
else
18+
echo "Found ${1}"
19+
fi
20+
}
1121
1222
# check that the PGO CLI version is recorded
1323
VER=$(cat ./kuttl-support-cluster/pgo-cli-version)
@@ -19,28 +29,19 @@ commands:
1929
}
2030
2131
# check that the cluster-names file exists and is not empty
22-
if [[ ! -s ./kuttl-support-cluster/cluster-names ]]
23-
then
24-
echo "Expected cluster-names file to not be empty"
25-
eval "$CLEANUP"
26-
exit 1
27-
fi
32+
check_file "cluster-names"
2833
2934
# check that the system-time file exists and is not empty
30-
if [[ ! -s ./kuttl-support-cluster/system-time ]]
31-
then
32-
echo "Expected system-time file to not be empty"
33-
eval "$CLEANUP"
34-
exit 1
35-
fi
35+
check_file "system-time"
3636
37-
# check that the context file exist and is not empty
38-
if [[ ! -s ./kuttl-support-cluster/current-context ]]
39-
then
40-
echo "Expected context file to not be empty"
41-
eval "$CLEANUP"
42-
exit 1
43-
fi
37+
# check that the context file exists and is not empty
38+
check_file "current-context"
39+
40+
# check that the patroni info file exists and is not empty
41+
check_file "patroni-info"
42+
43+
# check that the pgbackrest info file exists and is not empty
44+
check_file "pgbackrest-info"
4445
4546
# check for expected gzip compression level
4647
FILE_INFO=$(file ./crunchy_k8s_support_export_*.tar.gz)
@@ -76,15 +77,9 @@ commands:
7677
fi
7778
7879
# check that the events file exist and is not empty
79-
EVENTS="./kuttl-support-cluster/events"
80-
81-
if [[ ! -s $EVENTS ]]
82-
then
83-
echo "Expected Events file to not be empty"
84-
eval "$CLEANUP"
85-
exit 1
86-
fi
80+
check_file "events"
8781
82+
EVENTS="./kuttl-support-cluster/events"
8883
# check that the events file contains the expected string
8984
if ! grep -Fq "Created container postgres-startup" $EVENTS
9085
then

0 commit comments

Comments
 (0)