Skip to content

Commit

Permalink
Change rendering of RBAC (#26)
Browse files Browse the repository at this point in the history
* Fix rendering issue for rbac docs

Issue [sc-15452]
  • Loading branch information
benjaminjb authored Aug 17, 2022
1 parent f300fa2 commit 3e25d37
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 119 deletions.
8 changes: 4 additions & 4 deletions docs/content/reference/pgo_backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Backup cluster

Backup allows you to take a backup of a PostgreSQL cluster

RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]

```
pgo backup CLUSTER_NAME [flags]
Expand Down
8 changes: 4 additions & 4 deletions docs/content/reference/pgo_create_postgrescluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Create PostgresCluster with a given name

Create basic PostgresCluster with a given name.

RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [create]
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [create]

```
pgo create postgrescluster CLUSTER_NAME [flags]
Expand Down
8 changes: 4 additions & 4 deletions docs/content/reference/pgo_delete_postgrescluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Delete a PostgresCluster

Delete a PostgresCluster with a given name.

RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [delete]
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [delete]

```
pgo delete postgrescluster CLUSTER_NAME [flags]
Expand Down
8 changes: 4 additions & 4 deletions docs/content/reference/pgo_restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Restore cluster

Restore the data of a PostgreSQL cluster from a backup

RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]

```
pgo restore CLUSTER_NAME [flags]
Expand Down
8 changes: 4 additions & 4 deletions docs/content/reference/pgo_restore_disable.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Update a PostgresCluster spec to disable restores.

This is recommended after your restore is complete. Running "pgo restore" will enable restores again.

RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]

```
pgo restore disable CLUSTER_NAME [flags]
Expand Down
10 changes: 5 additions & 5 deletions docs/content/reference/pgo_show_backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Show backup information for a PostgresCluster

Show backup information for a PostgresCluster from 'pgbackrest info' command.

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

```
pgo show backup CLUSTER_NAME [flags]
Expand Down
49 changes: 23 additions & 26 deletions docs/content/reference/pgo_support_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,32 @@ Export a snapshot of a PostgresCluster

### Synopsis


The support export tool will collect information that is commonly necessary for troubleshooting a
PostgresCluster.

Collected Resources: [statefulsets deployments replicasets jobs cronjobs poddisruptionbudgets pods persistentvolumeclaims configmaps services endpoints serviceaccounts]

RBAC Requirements
Resources Verbs
--------- -----
configmaps [get list]
cronjobs.batch [get list]
deployments.apps [get list]
endpoints [get list]
events [get list]
jobs.batch [get list]
namespaces [get]
nodes [list]
persistentvolumeclaims [get list]
poddisruptionbudgets.policy [get list]
pods [get list]
pods/exec [create]
pods/log [get]
postgresclusters.postgres-operator.crunchydata.com [get]
replicasets.apps [get list]
serviceaccounts [get list]
services [get list]
statefulsets.apps [get list]

Note: This RBAC needs to be cluster-scoped to retrieve information on nodes.
#### RBAC Requirements
Resources Verbs
--------- -----
configmaps [get list]
cronjobs.batch [get list]
deployments.apps [get list]
endpoints [get list]
events [get list]
jobs.batch [get list]
namespaces [get]
nodes [list]
persistentvolumeclaims [get list]
poddisruptionbudgets.policy [get list]
pods [get list]
pods/exec [create]
pods/log [get]
postgresclusters.postgres-operator.crunchydata.com [get]
replicasets.apps [get list]
serviceaccounts [get list]
services [get list]
statefulsets.apps [get list]

Note: This RBAC needs to be cluster-scoped to retrieve information on nodes.

```
pgo support export CLUSTER_NAME [flags]
Expand Down
10 changes: 5 additions & 5 deletions docs/content/reference/pgo_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ PGO client and operator versions

Version displays the versions of the PGO client and the Crunchy Postgres Operator

RBAC Requirements
Resources Verbs
--------- -----
customresourcedefinitions.apiextensions.k8s.io [get]
#### RBAC Requirements
Resources Verbs
--------- -----
customresourcedefinitions.apiextensions.k8s.io [get]

Note: This RBAC needs to be cluster-scoped.
Note: This RBAC needs to be cluster-scoped.

```
pgo version [flags]
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func newBackupCommand(config *internal.Config) *cobra.Command {
Short: "Backup cluster",
Long: `Backup allows you to take a backup of a PostgreSQL cluster
RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]`,
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]`,
}

cmdBackup.Example = internal.FormatExample(`
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func newCreateClusterCommand(config *internal.Config) *cobra.Command {
Short: "Create PostgresCluster with a given name",
Long: `Create basic PostgresCluster with a given name.
RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [create]`,
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [create]`,
}

cmd.Args = cobra.ExactArgs(1)
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func newDeleteClusterCommand(config *internal.Config) *cobra.Command {
Short: "Delete a PostgresCluster",
Long: `Delete a PostgresCluster with a given name.
RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [delete]`,
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [delete]`,
}

cmd.Args = cobra.ExactArgs(1)
Expand Down
57 changes: 24 additions & 33 deletions internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,35 @@ var namespacedResources = []schema.GroupVersionResource{{

// newSupportCommand returns the support subcommand of the PGO plugin.
func newSupportExportCommand(config *internal.Config) *cobra.Command {

var collectedResources []string
for _, resource := range namespacedResources {
collectedResources = append(collectedResources, resource.Resource)
}

cmd := &cobra.Command{
Use: "export CLUSTER_NAME",
Short: "Export a snapshot of a PostgresCluster",
Long: fmt.Sprintf(`
The support export tool will collect information that is commonly necessary for troubleshooting a
Long: `The support export tool will collect information that is commonly necessary for troubleshooting a
PostgresCluster.
Collected Resources: %v
RBAC Requirements
Resources Verbs
--------- -----
configmaps [get list]
cronjobs.batch [get list]
deployments.apps [get list]
endpoints [get list]
events [get list]
jobs.batch [get list]
namespaces [get]
nodes [list]
persistentvolumeclaims [get list]
poddisruptionbudgets.policy [get list]
pods [get list]
pods/exec [create]
pods/log [get]
postgresclusters.postgres-operator.crunchydata.com [get]
replicasets.apps [get list]
serviceaccounts [get list]
services [get list]
statefulsets.apps [get list]
Note: This RBAC needs to be cluster-scoped to retrieve information on nodes.`, collectedResources),
#### RBAC Requirements
Resources Verbs
--------- -----
configmaps [get list]
cronjobs.batch [get list]
deployments.apps [get list]
endpoints [get list]
events [get list]
jobs.batch [get list]
namespaces [get]
nodes [list]
persistentvolumeclaims [get list]
poddisruptionbudgets.policy [get list]
pods [get list]
pods/exec [create]
pods/log [get]
postgresclusters.postgres-operator.crunchydata.com [get]
replicasets.apps [get list]
serviceaccounts [get list]
services [get list]
statefulsets.apps [get list]
Note: This RBAC needs to be cluster-scoped to retrieve information on nodes.`,
}

var outputDir string
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/pgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down Expand Up @@ -80,6 +81,12 @@ func NewPGOCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
SilenceErrors: true,
}

cobra.AddTemplateFunc("replaceAll", strings.ReplaceAll)

root.SetHelpTemplate(`{{with .Long}}{{ replaceAll . "#### RBAC Requirements" "RBAC Requirements:" | trimTrailingWhitespaces }}
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`)

// Add flags for kubeconfig, authentication, namespace, and timeout to
// every subcommand.
// - https://docs.k8s.io/concepts/configuration/organize-cluster-access-kubeconfig/
Expand Down
16 changes: 8 additions & 8 deletions internal/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func newRestoreCommand(config *internal.Config) *cobra.Command {
Short: "Restore cluster",
Long: `Restore the data of a PostgreSQL cluster from a backup
RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]`,
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]`,
}

cmd.Example = internal.FormatExample(`
Expand Down Expand Up @@ -82,10 +82,10 @@ func newRestoreDisableCommand(config *internal.Config) *cobra.Command {
This is recommended after your restore is complete. Running "pgo restore" will enable restores again.
RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]`,
#### RBAC Requirements
Resources Verbs
--------- -----
postgresclusters.postgres-operator.crunchydata.com [get patch]`,
}

disable := pgBackRestRestoreDisable{Config: config}
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func newShowBackupCommand(config *internal.Config) *cobra.Command {
Short: "Show backup information for a PostgresCluster",
Long: `Show backup information for a PostgresCluster from 'pgbackrest info' command.
RBAC Requirements
Resources Verbs
--------- -----
pods [list]
pods/exec [create]`,
#### RBAC Requirements
Resources Verbs
--------- -----
pods [list]
pods/exec [create]`,
}

cmdShowBackup.Example = internal.FormatExample(`
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func newVersionCommand(config *internal.Config) *cobra.Command {
Short: "PGO client and operator versions",
Long: `Version displays the versions of the PGO client and the Crunchy Postgres Operator
RBAC Requirements
Resources Verbs
--------- -----
customresourcedefinitions.apiextensions.k8s.io [get]
#### RBAC Requirements
Resources Verbs
--------- -----
customresourcedefinitions.apiextensions.k8s.io [get]
Note: This RBAC needs to be cluster-scoped.`,
Note: This RBAC needs to be cluster-scoped.`,
}

// No arguments for 'version'
Expand Down

0 comments on commit 3e25d37

Please sign in to comment.