Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pgo show ha command and add combined output to pgo show #77

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion docs/content/reference/pgo_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,53 @@ 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

```
### Example output
```
BACKUP
tjmoore4 marked this conversation as resolved.
Show resolved Hide resolved

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) -----+--------+---------+----+-----------+
tjmoore4 marked this conversation as resolved.
Show resolved Hide resolved
| Member | Host | Role | State | TL | Lag in MB |
+-----------------+----------------------------+--------+---------+----+-----------+
| hippo-00-cwqq-0 | hippo-00-cwqq-0.hippo-pods | Leader | running | 1 | |
+-----------------+----------------------------+--------+---------+----+-----------+

```

### Options

Expand Down Expand Up @@ -41,4 +87,5 @@ Show allows you to display particular details related to the PostgresCluster

* [pgo](/reference/) - pgo is a kubectl plugin for PGO, the open source Postgres Operator
* [pgo show backup](/reference/pgo_show_backup/) - Show backup information for a PostgresCluster
* [pgo show ha](/reference/pgo_show_ha/) - Show 'patronictl list' for a PostgresCluster.

76 changes: 76 additions & 0 deletions docs/content/reference/pgo_show_ha.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: pgo show ha
---
## pgo show ha

Show 'patronictl list' for a PostgresCluster.

### Synopsis

Show 'patronictl list' for a PostgresCluster.

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

### Usage

```
pgo show ha CLUSTER_NAME [flags]
```

### Examples

```
# Show 'patronictl list' for the 'hippo' postgrescluster
pgo show ha hippo

# Show 'patronictl list' JSON output for the 'hippo' postgrescluster
pgo show ha hippo --output json

```
### Example output
```
+ 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

```
-h, --help help for ha
-o, --output string output format. types supported: pretty,tsv,json,yaml (default "pretty")
```

### Options inherited from parent commands

```
--as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace.
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--as-uid string UID to impersonate for the operation.
--cache-dir string Default cache directory (default "$HOME/.kube/cache")
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--client-key string Path to a client key file for TLS
--cluster string The name of the kubeconfig cluster to use
--context string The name of the kubeconfig context to use
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
```

### SEE ALSO

* [pgo show](/reference/pgo_show/) - Show PostgresCluster details

5 changes: 4 additions & 1 deletion internal/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ func (exec Executor) catFile(filePath string) (string, string, error) {
}

// patronictl takes a patronictl subcommand and returns the output of that command
func (exec Executor) patronictl(cmd string) (string, string, error) {
func (exec Executor) patronictl(cmd, output string) (string, string, error) {
tjmoore4 marked this conversation as resolved.
Show resolved Hide resolved
var stdout, stderr bytes.Buffer

command := "patronictl " + cmd
if output != "" {
command += " --format " + output
}
err := exec(nil, &stdout, &stderr, "bash", "-ceu", "--", command)

return stdout.String(), stderr.String(), err
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestPatronictl(t *testing.T) {
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).patronictl("sub-command")
_, _, err := Executor(exec).patronictl("sub-command", "")
assert.ErrorContains(t, err, "pass-through")

})
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func gatherPatroniInfo(ctx context.Context,
var buf bytes.Buffer

buf.Write([]byte("patronictl list\n"))
stdout, stderr, err := Executor(exec).patronictl("list")
stdout, stderr, err := Executor(exec).patronictl("list", "")
if err != nil {
if apierrors.IsForbidden(err) {
writeInfo(cmd, err.Error())
Expand All @@ -1056,7 +1056,7 @@ func gatherPatroniInfo(ctx context.Context,
}

buf.Write([]byte("patronictl history\n"))
stdout, stderr, err = Executor(exec).patronictl("history")
stdout, stderr, err = Executor(exec).patronictl("history", "")
if err != nil {
if apierrors.IsForbidden(err) {
writeInfo(cmd, err.Error())
Expand Down
Loading