Skip to content

Commit 0c7a778

Browse files
authored
Add logs and describe for pgo (#96)
* Add logs and describe for pgo * Release notes Issues: [PGO-1175]
1 parent 56a0c82 commit 0c7a778

File tree

10 files changed

+116
-13
lines changed

10 files changed

+116
-13
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ The `pgo` CLI supports all actively maintained versions of PGO v5+.
6464

6565
For more about PGO, please see the
6666
[PGO Documentation](https://access.crunchydata.com/documentation/postgres-operator/).
67+
68+
## Testing the Client
69+
70+
The PGO client has several KUTTL tests that run through some common scenarios.
71+
In order to run these tests, we need a PGO operator or the equivalent running, i.e., `make deploy-dev`.
72+
73+
Note: the `support export` test requires a PGO operator running in the `postgres-operator` namespace.

docs/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defaultContentLanguageInSubdir= false
1515
enableMissingTranslationPlaceholders = false
1616

1717
[params]
18-
clientVersion = "0.4.1"
18+
clientVersion = "0.4.2"
1919

2020
# crunchy-hugo-theme params
2121
editURL = "https://github.com/CrunchyData/postgres-operator/edit/master/docs/content/"

docs/content/reference/pgo_support_export.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PostgresCluster.
2222
jobs.batch [list]
2323
limitranges [list]
2424
namespaces [get]
25+
networkpolicies.networking.k8s.io [list]
2526
nodes [list]
2627
persistentvolumeclaims [list]
2728
poddisruptionbudgets.policy [list]
@@ -61,6 +62,11 @@ kubectl pgo support export daisy --output . --pg-logs-count 2
6162
# This is only required when monitoring is not deployed in the PostgresCluster's namespace.
6263
kubectl pgo support export daisy --monitoring-namespace another-namespace --output .
6364
65+
# Operator namespace override
66+
# This is only required when the Operator is not deployed in the PostgresCluster's namespace.
67+
# This is used for getting the logs and specs for the operator pod(s).
68+
kubectl pgo support export daisy --operator-namespace another-namespace --output .
69+
6470
```
6571
### Example output
6672
```
@@ -91,11 +97,13 @@ Collecting services...
9197
Collecting endpoints...
9298
Collecting serviceaccounts...
9399
Collecting ingresses...
100+
Collecting networkpolicies...
94101
Collecting limitranges...
95102
Collecting events...
96103
Collecting Postgres logs...
97104
Collecting PostgresCluster pod logs...
98105
Collecting monitoring pod logs...
106+
Collecting operator pod logs...
99107
Collecting Patroni info...
100108
Collecting pgBackRest info...
101109
Collecting processes...
@@ -114,6 +122,7 @@ Collecting PGO CLI logs...
114122
```
115123
-h, --help help for export
116124
--monitoring-namespace string Monitoring namespace override
125+
--operator-namespace string Operator namespace override
117126
-o, --output string Path to save export tarball
118127
-l, --pg-logs-count int Number of pg_log files to save (default 2)
119128
```

docs/content/reference/pgo_version.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pgo version
3131
```
3232
### Example output
3333
```
34-
Client Version: v0.4.1
34+
Client Version: v0.4.2
3535
Operator Version: v5.5.0
3636
```
3737

docs/content/releases/0.4.1.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "0.4.1"
33
draft: false
4-
weight: 996
4+
weight: 995
55
---
66

77
[Crunchy Postgres for Kubernetes]: https://www.crunchydata.com/products/crunchy-postgresql-for-kubernetes
@@ -16,4 +16,5 @@ For more information about using the CLI and the various commands available, ple
1616
Additionally, please see the [CPK documentation](https://access.crunchydata.com/documentation/postgres-operator/latest) for information about [getting started](https://access.crunchydata.com/documentation/postgres-operator/latest/quickstart/) with Crunchy Postgres for Kubernetes.
1717

1818
## Bug
19+
1920
- The `support export` command would fail fatally if the user didn't have permissions to list postgresclusters at the cluster-scope. This release fixes that so our postgrescluster list fails gracefully (like our other atttempts to gather Kubernetes resources).

docs/content/releases/0.4.2.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "0.4.2"
3+
draft: false
4+
weight: 994
5+
---
6+
7+
[Crunchy Postgres for Kubernetes]: https://www.crunchydata.com/products/crunchy-postgresql-for-kubernetes
8+
[`pgo` CLI documentation]: https://access.crunchydata.com/documentation/postgres-operator-client/latest
9+
10+
Crunchy Data announces the release of `pgo`, Postgres Operator Client from Crunchy Data 0.4.2.
11+
12+
Built as a `kubectl` plugin, the `pgo` CLI facilitates the creation and management of PostgreSQL clusters created using [Crunchy Postgres for Kubernetes][].
13+
14+
For more information about using the CLI and the various commands available, please see the [`pgo` CLI documentation][].
15+
16+
Additionally, please see the [CPK documentation](https://access.crunchydata.com/documentation/postgres-operator/latest) for information about [getting started](https://access.crunchydata.com/documentation/postgres-operator/latest/quickstart/) with Crunchy Postgres for Kubernetes.
17+
18+
## Changes
19+
20+
- The `support export` command now captures logs from and descriptions for the PGO pod.

internal/cmd/client_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
package cmd
1616

1717
// store the current PGO CLI version
18-
const clientVersion = "v0.4.1"
18+
const clientVersion = "v0.4.2"

internal/cmd/export.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ import (
3838
apierrors "k8s.io/apimachinery/pkg/api/errors"
3939
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4040
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
41+
"k8s.io/apimachinery/pkg/labels"
4142
"k8s.io/apimachinery/pkg/runtime/schema"
43+
"k8s.io/apimachinery/pkg/selection"
4244
"k8s.io/apimachinery/pkg/util/duration"
4345
"k8s.io/cli-runtime/pkg/printers"
4446
"k8s.io/client-go/discovery"
@@ -126,6 +128,22 @@ var clusterNamespacedResources = []schema.GroupVersionResource{{
126128
Resource: "serviceaccounts",
127129
}}
128130

131+
// Resources specifically for the operator;
132+
// currently only pods, but leaving as is to allow expansion as requested.
133+
var operatorNamespacedResources = []schema.GroupVersionResource{{
134+
Group: appsv1.SchemeGroupVersion.Group,
135+
Version: appsv1.SchemeGroupVersion.Version,
136+
Resource: "deployments",
137+
}, {
138+
Group: appsv1.SchemeGroupVersion.Group,
139+
Version: appsv1.SchemeGroupVersion.Version,
140+
Resource: "replicasets",
141+
}, {
142+
Group: corev1.SchemeGroupVersion.Group,
143+
Version: corev1.SchemeGroupVersion.Version,
144+
Resource: "pods",
145+
}}
146+
129147
// These "removed" GVRs are for making our CLI backwards compatible with older PGO versions.
130148
var removedNamespacedResources = []schema.GroupVersionResource{{
131149
Group: batchv1beta1.SchemeGroupVersion.Group,
@@ -142,6 +160,10 @@ var otherNamespacedResources = []schema.GroupVersionResource{{
142160
Group: networkingv1.SchemeGroupVersion.Group,
143161
Version: networkingv1.SchemeGroupVersion.Version,
144162
Resource: "ingresses",
163+
}, {
164+
Group: networkingv1.SchemeGroupVersion.Group,
165+
Version: networkingv1.SchemeGroupVersion.Version,
166+
Resource: "networkpolicies",
145167
}, {
146168
Group: corev1.SchemeGroupVersion.Group,
147169
Version: corev1.SchemeGroupVersion.Version,
@@ -168,6 +190,7 @@ PostgresCluster.
168190
jobs.batch [list]
169191
limitranges [list]
170192
namespaces [get]
193+
networkpolicies.networking.k8s.io [list]
171194
nodes [list]
172195
persistentvolumeclaims [list]
173196
poddisruptionbudgets.policy [list]
@@ -215,6 +238,9 @@ PostgresCluster.
215238
var monitoringNamespace string
216239
cmd.Flags().StringVarP(&monitoringNamespace, "monitoring-namespace", "", "", "Monitoring namespace override")
217240

241+
var operatorNamespace string
242+
cmd.Flags().StringVarP(&operatorNamespace, "operator-namespace", "", "", "Operator namespace override")
243+
218244
cmd.Args = cobra.ExactArgs(1)
219245

220246
cmd.Example = internal.FormatExample(`# Short Flags
@@ -227,6 +253,11 @@ kubectl pgo support export daisy --output . --pg-logs-count 2
227253
# This is only required when monitoring is not deployed in the PostgresCluster's namespace.
228254
kubectl pgo support export daisy --monitoring-namespace another-namespace --output .
229255
256+
# Operator namespace override
257+
# This is only required when the Operator is not deployed in the PostgresCluster's namespace.
258+
# This is used for getting the logs and specs for the operator pod(s).
259+
kubectl pgo support export daisy --operator-namespace another-namespace --output .
260+
230261
### Example output
231262
┌────────────────────────────────────────────────────────────────
232263
| PGO CLI Support Export Tool
@@ -255,11 +286,13 @@ Collecting services...
255286
Collecting endpoints...
256287
Collecting serviceaccounts...
257288
Collecting ingresses...
289+
Collecting networkpolicies...
258290
Collecting limitranges...
259291
Collecting events...
260292
Collecting Postgres logs...
261293
Collecting PostgresCluster pod logs...
262294
Collecting monitoring pod logs...
295+
Collecting operator pod logs...
263296
Collecting Patroni info...
264297
Collecting pgBackRest info...
265298
Collecting processes...
@@ -287,6 +320,7 @@ Collecting PGO CLI logs...
287320
writeDebug(cmd, fmt.Sprintf("Flag - Output Directory: %s\n", outputDir))
288321
writeDebug(cmd, fmt.Sprintf("Flag - Num Logs: %d\n", numLogs))
289322
writeDebug(cmd, fmt.Sprintf("Flag - Monitoring Namespace: %s\n", monitoringNamespace))
323+
writeDebug(cmd, fmt.Sprintf("Flag - Operator Namespace: %s\n", operatorNamespace))
290324

291325
namespace, err := config.Namespace()
292326
if err != nil {
@@ -433,6 +467,29 @@ Collecting PGO CLI logs...
433467
err = gatherPodLogs(ctx, clientset, monitoringNamespace, util.LabelMonitoring, "monitoring", tw, cmd)
434468
}
435469

470+
// get operator Pod logs and descriptions
471+
if operatorNamespace == "" {
472+
operatorNamespace = namespace
473+
}
474+
// Operator and Operator upgrade pods should have
475+
// "postgres-operator.crunchydata.com/control-plane" label
476+
// but with different values
477+
if err == nil {
478+
req, _ := labels.NewRequirement(util.LabelOperator,
479+
selection.Exists, []string{},
480+
)
481+
nsListOpts := metav1.ListOptions{
482+
LabelSelector: req.String(),
483+
}
484+
err = gatherNamespacedAPIResources(ctx, dynamicClient,
485+
operatorNamespace, "operator", operatorNamespacedResources,
486+
nsListOpts, tw, cmd)
487+
}
488+
if err == nil {
489+
writeInfo(cmd, "Collecting operator pod logs...")
490+
err = gatherPodLogs(ctx, clientset, operatorNamespace, util.LabelOperator, "operator", tw, cmd)
491+
}
492+
436493
// Exec resources
437494
if err == nil {
438495
err = gatherPatroniInfo(ctx, clientset, restConfig, namespace, clusterName, tw, cmd)

internal/util/naming.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const (
3131

3232
// LabelMonitoring is used to identify monitoring Pods
3333
LabelMonitoring = "app.kubernetes.io/name=postgres-operator-monitoring"
34+
35+
// LabelOperator is used to identify operator Pods
36+
LabelOperator = "postgres-operator.crunchydata.com/control-plane"
3437
)
3538

3639
const (

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
5-
- script: kubectl-pgo --namespace $NAMESPACE support export kuttl-support-cluster -o .
5+
- script: kubectl-pgo --namespace $NAMESPACE --operator-namespace postgres-operator support export kuttl-support-cluster -o .
66
- script: tar -xzf ./crunchy_k8s_support_export_*.tar.gz
77
- script: |
88
CLEANUP="rm -r ./kuttl-support-cluster ./crunchy_k8s_support_export_*.tar.gz"
99
check_file() {
10-
if [ ! -s ./kuttl-support-cluster/"${1}" ]
10+
if [ ! -s ./"${1}" ]
1111
then
1212
echo "Expected ${1} file to not be empty"
1313
eval "$CLEANUP"
@@ -29,23 +29,29 @@ commands:
2929
}
3030
3131
# check that the cluster-names file exists and is not empty
32-
check_file "cluster-names"
32+
check_file "kuttl-support-cluster/cluster-names"
3333
3434
# check that the system-time file exists and is not empty
35-
check_file "system-time"
35+
check_file "kuttl-support-cluster/system-time"
3636
3737
# check that the context file exists and is not empty
38-
check_file "current-context"
38+
check_file "kuttl-support-cluster/current-context"
3939
4040
# check that the patroni info file exists and is not empty
41-
check_file "patroni-info"
41+
check_file "kuttl-support-cluster/patroni-info"
4242
4343
# check that the pgbackrest info file exists and is not empty
44-
check_file "pgbackrest-info"
44+
check_file "kuttl-support-cluster/pgbackrest-info"
4545
4646
# check that the plugin list file exists and is not empty
4747
# the file will at least include kubectl-pgo
48-
check_file "plugin-list"
48+
check_file "kuttl-support-cluster/plugin-list"
49+
50+
# check that the operator file exists and is not empty
51+
# the list file will not be empty for the requested Kubernetes types
52+
check_file "operator/deployments/list"
53+
check_file "operator/replicasets/list"
54+
check_file "operator/pods/list"
4955
5056
# check for expected gzip compression level
5157
FILE_INFO=$(file ./crunchy_k8s_support_export_*.tar.gz)
@@ -85,7 +91,7 @@ commands:
8591
fi
8692
8793
# check that the events file exist and is not empty
88-
check_file "events"
94+
check_file "kuttl-support-cluster/events"
8995
9096
EVENTS="./kuttl-support-cluster/events"
9197
# check that the events file contains the expected string

0 commit comments

Comments
 (0)