Skip to content

Commit

Permalink
Add allow sub-command output to 'pgo show' command
Browse files Browse the repository at this point in the history
This commit adds the default output from 'pgo show backup' and
'pgo show ha' to the 'pgo show' command.

Issue: PGO-13
  • Loading branch information
tjmoore4 committed Oct 30, 2023
1 parent 92a8ad8 commit 21406e1
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 94 deletions.
44 changes: 43 additions & 1 deletion docs/content/reference/pgo_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,49 @@ Show PostgresCluster details

### Synopsis

Show allows you to display particular details related to the PostgresCluster
Show allows you to display particular details related to the PostgresCluster.

### RBAC Requirements
Resources Verbs
--------- -----
pods [list]
pods/exec [create]

### Usage

```
pgo show [flags]
```

### Examples

```
# Show the backup and HA output of the 'hippo' postgrescluster
pgo show hippo
BACKUP
stanza: db
status: ok
cipher: none
db (current)
wal archive min/max (14): 000000010000000000000001/000000010000000000000003
full backup: 20231030-183841F
timestamp start/stop: 2023-10-30 18:38:41+00 / 2023-10-30 18:38:46+00
wal start/stop: 000000010000000000000002 / 000000010000000000000002
database size: 25.3MB, database backup size: 25.3MB
repo1: backup set size: 3.2MB, backup size: 3.2MB
HA
+ Cluster: hippo-ha (7295822780081832000) -----+--------+---------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------------+----------------------------+--------+---------+----+-----------+
| hippo-00-cwqq-0 | hippo-00-cwqq-0.hippo-pods | Leader | running | 1 | |
+-----------------+----------------------------+--------+---------+----+-----------+
```

### Options

Expand Down
82 changes: 78 additions & 4 deletions internal/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,91 @@ func newShowCommand(config *internal.Config) *cobra.Command {
cmdShow := &cobra.Command{
Use: "show",
Short: "Show PostgresCluster details",
Long: "Show allows you to display particular details related to the PostgresCluster",
Long: `Show allows you to display particular details related to the PostgresCluster.
### RBAC Requirements
Resources Verbs
--------- -----
pods [list]
pods/exec [create]
### Usage`,
}

cmdShow.Example = internal.FormatExample(`# Show the backup and HA output of the 'hippo' postgrescluster
pgo show hippo
BACKUP
stanza: db
status: ok
cipher: none
db (current)
wal archive min/max (14): 000000010000000000000001/000000010000000000000003
full backup: 20231030-183841F
timestamp start/stop: 2023-10-30 18:38:41+00 / 2023-10-30 18:38:46+00
wal start/stop: 000000010000000000000002 / 000000010000000000000002
database size: 25.3MB, database backup size: 25.3MB
repo1: backup set size: 3.2MB, backup size: 3.2MB
HA
+ Cluster: hippo-ha (7295822780081832000) -----+--------+---------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------------+----------------------------+--------+---------+----+-----------+
| hippo-00-cwqq-0 | hippo-00-cwqq-0.hippo-pods | Leader | running | 1 | |
+-----------------+----------------------------+--------+---------+----+-----------+
`)

cmdShow.AddCommand(
newShowBackupCommand(config),
newShowHACommand(config),
)

// No arguments for 'show', but there are arguments for the subcommands, e.g.
// 'show backup'
cmdShow.Args = cobra.NoArgs
// Limit the number of args, that is, only one cluster name
cmdShow.Args = cobra.ExactArgs(1)

// Define the 'show backup' command
cmdShow.RunE = func(cmd *cobra.Command, args []string) error {

// The only thing we need is the value after 'repo' which should be an
// integer. If anything else is provided, we let the pgbackrest command
// handle validation.

exec, err := getPrimaryExec(config, args)
if err != nil {
return err
}

// for 'show backup', use 'text' ouput and don't specify a repo

Check failure on line 95 in internal/cmd/show.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`ouput` is a misspelling of `output` (misspell)
stdoutBackup, stderrBackup, err := Executor(exec).pgBackRestInfo("text", "")
if err != nil {
return err
}

// Print the pgbackrest info output received.
cmd.Printf("BACKUP\n\n")
cmd.Printf(stdoutBackup)
if stderrBackup != "" {
cmd.Printf("\nError returned: %s\n", stderrBackup)
}

// use default list command output
stdoutHA, stderrHA, err := Executor(exec).patronictl("list", false)
if err != nil {
return err
}

// Print the patronictl list output received.
cmd.Println("\nHA\n")

Check failure on line 115 in internal/cmd/show.go

View workflow job for this annotation

GitHub Actions / go-test

(*github.com/spf13/cobra.Command).Println arg list ends with redundant newline

Check failure on line 115 in internal/cmd/show.go

View workflow job for this annotation

GitHub Actions / golangci-lint

printf: `(*github.com/spf13/cobra.Command).Println` arg list ends with redundant newline (govet)
cmd.Printf(stdoutHA)
if stderrHA != "" {
cmd.Printf("\nError returned: %s\n", stderrHA)
}

return nil
}

return cmdShow
}
Expand Down
25 changes: 0 additions & 25 deletions testing/kuttl/e2e/show-backup/00--cluster.yaml

This file was deleted.

49 changes: 0 additions & 49 deletions testing/kuttl/e2e/show-backup/00-assert.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
name: show-ha-cluster
name: show-cluster
spec:
postgresVersion: 15
instances:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
name: show-ha-cluster
name: show-cluster
status:
instances:
- name: instance1
Expand All @@ -23,7 +23,7 @@ apiVersion: batch/v1
kind: Job
metadata:
labels:
postgres-operator.crunchydata.com/cluster: show-ha-cluster
postgres-operator.crunchydata.com/cluster: show-cluster
postgres-operator.crunchydata.com/pgbackrest-backup: replica-create
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
status:
Expand All @@ -33,12 +33,12 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
postgres-operator.crunchydata.com/cluster: show-ha-cluster
postgres-operator.crunchydata.com/cluster: show-cluster
postgres-operator.crunchydata.com/data: pgbackrest
postgres-operator.crunchydata.com/pgbackrest: ""
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
postgres-operator.crunchydata.com/pgbackrest-volume: ""
name: show-ha-cluster-repo1
name: show-cluster-repo1
spec:
accessModes:
- ReadWriteOnce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
PRIMARY=$(
kubectl get pod --namespace "${NAMESPACE}" \
--output name --selector '
postgres-operator.crunchydata.com/cluster=show-backup-cluster,
postgres-operator.crunchydata.com/cluster=show-cluster,
postgres-operator.crunchydata.com/role=master'
)
Expand All @@ -15,7 +15,7 @@ commands:
)
CLI_INFO=$(
kubectl-pgo --namespace "${NAMESPACE}" show backup show-backup-cluster
kubectl-pgo --namespace "${NAMESPACE}" show backup show-cluster
)
status=$?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
PRIMARY=$(
kubectl get pod --namespace "${NAMESPACE}" \
--output name --selector '
postgres-operator.crunchydata.com/cluster=show-backup-cluster,
postgres-operator.crunchydata.com/cluster=show-cluster,
postgres-operator.crunchydata.com/role=master'
)
Expand All @@ -15,7 +15,7 @@ commands:
)
CLI_INFO=$(
kubectl-pgo --namespace "${NAMESPACE}" show backup show-backup-cluster \
kubectl-pgo --namespace "${NAMESPACE}" show backup show-cluster \
--repoName=repo1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
PRIMARY=$(
kubectl get pod --namespace "${NAMESPACE}" \
--output name --selector '
postgres-operator.crunchydata.com/cluster=show-backup-cluster,
postgres-operator.crunchydata.com/cluster=show-cluster,
postgres-operator.crunchydata.com/role=master'
)
Expand All @@ -15,7 +15,7 @@ commands:
)
CLI_INFO=$(
kubectl-pgo --namespace "${NAMESPACE}" show backup show-backup-cluster \
kubectl-pgo --namespace "${NAMESPACE}" show backup show-cluster \
--output=json
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
PRIMARY=$(
kubectl get pod --namespace "${NAMESPACE}" \
--output name --selector '
postgres-operator.crunchydata.com/cluster=show-ha-cluster,
postgres-operator.crunchydata.com/cluster=show-cluster,
postgres-operator.crunchydata.com/role=master'
)
Expand All @@ -15,7 +15,7 @@ commands:
)
CLI_INFO=$(
kubectl-pgo --namespace "${NAMESPACE}" show ha show-ha-cluster
kubectl-pgo --namespace "${NAMESPACE}" show ha show-cluster
)
status=$?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
PRIMARY=$(
kubectl get pod --namespace "${NAMESPACE}" \
--output name --selector '
postgres-operator.crunchydata.com/cluster=show-ha-cluster,
postgres-operator.crunchydata.com/cluster=show-cluster,
postgres-operator.crunchydata.com/role=master'
)
Expand All @@ -15,7 +15,7 @@ commands:
)
CLI_INFO=$(
kubectl-pgo --namespace "${NAMESPACE}" show ha show-ha-cluster --json
kubectl-pgo --namespace "${NAMESPACE}" show ha show-cluster --json
)
status=$?
Expand Down
Loading

0 comments on commit 21406e1

Please sign in to comment.