From 3e25d37138a4ce25b1fe214bf6a75ecde0138272 Mon Sep 17 00:00:00 2001 From: Benjamin Blattberg Date: Wed, 17 Aug 2022 10:15:00 -0500 Subject: [PATCH] Change rendering of RBAC (#26) * Fix rendering issue for rbac docs Issue [sc-15452] --- docs/content/reference/pgo_backup.md | 8 +-- .../reference/pgo_create_postgrescluster.md | 8 +-- .../reference/pgo_delete_postgrescluster.md | 8 +-- docs/content/reference/pgo_restore.md | 8 +-- docs/content/reference/pgo_restore_disable.md | 8 +-- docs/content/reference/pgo_show_backup.md | 10 ++-- docs/content/reference/pgo_support_export.md | 49 ++++++++-------- docs/content/reference/pgo_version.md | 10 ++-- internal/cmd/backup.go | 8 +-- internal/cmd/create.go | 8 +-- internal/cmd/delete.go | 8 +-- internal/cmd/export.go | 57 ++++++++----------- internal/cmd/pgo.go | 7 +++ internal/cmd/restore.go | 16 +++--- internal/cmd/show.go | 10 ++-- internal/cmd/version.go | 10 ++-- 16 files changed, 114 insertions(+), 119 deletions(-) diff --git a/docs/content/reference/pgo_backup.md b/docs/content/reference/pgo_backup.md index 32e25202..cf40dbf1 100644 --- a/docs/content/reference/pgo_backup.md +++ b/docs/content/reference/pgo_backup.md @@ -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] diff --git a/docs/content/reference/pgo_create_postgrescluster.md b/docs/content/reference/pgo_create_postgrescluster.md index 080eedb2..8406d8cf 100644 --- a/docs/content/reference/pgo_create_postgrescluster.md +++ b/docs/content/reference/pgo_create_postgrescluster.md @@ -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] diff --git a/docs/content/reference/pgo_delete_postgrescluster.md b/docs/content/reference/pgo_delete_postgrescluster.md index 44324a3e..c879f3a4 100644 --- a/docs/content/reference/pgo_delete_postgrescluster.md +++ b/docs/content/reference/pgo_delete_postgrescluster.md @@ -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] diff --git a/docs/content/reference/pgo_restore.md b/docs/content/reference/pgo_restore.md index 0eb1b70d..f10e3e59 100644 --- a/docs/content/reference/pgo_restore.md +++ b/docs/content/reference/pgo_restore.md @@ -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] diff --git a/docs/content/reference/pgo_restore_disable.md b/docs/content/reference/pgo_restore_disable.md index a5946a11..75f6bbab 100644 --- a/docs/content/reference/pgo_restore_disable.md +++ b/docs/content/reference/pgo_restore_disable.md @@ -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] diff --git a/docs/content/reference/pgo_show_backup.md b/docs/content/reference/pgo_show_backup.md index 8eb6c43c..86e80a95 100644 --- a/docs/content/reference/pgo_show_backup.md +++ b/docs/content/reference/pgo_show_backup.md @@ -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] diff --git a/docs/content/reference/pgo_support_export.md b/docs/content/reference/pgo_support_export.md index 09c9294e..7933aee0 100644 --- a/docs/content/reference/pgo_support_export.md +++ b/docs/content/reference/pgo_support_export.md @@ -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] diff --git a/docs/content/reference/pgo_version.md b/docs/content/reference/pgo_version.md index 45cf11d3..b610e94e 100644 --- a/docs/content/reference/pgo_version.md +++ b/docs/content/reference/pgo_version.md @@ -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] diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go index 47b6da73..c8cf6c68 100644 --- a/internal/cmd/backup.go +++ b/internal/cmd/backup.go @@ -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(` diff --git a/internal/cmd/create.go b/internal/cmd/create.go index 64ea2141..d52eeeba 100644 --- a/internal/cmd/create.go +++ b/internal/cmd/create.go @@ -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) diff --git a/internal/cmd/delete.go b/internal/cmd/delete.go index 4e2700a2..8edaa73a 100644 --- a/internal/cmd/delete.go +++ b/internal/cmd/delete.go @@ -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) diff --git a/internal/cmd/export.go b/internal/cmd/export.go index 03dd64f3..f7b062cb 100644 --- a/internal/cmd/export.go +++ b/internal/cmd/export.go @@ -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 diff --git a/internal/cmd/pgo.go b/internal/cmd/pgo.go index 768df332..549ce39e 100644 --- a/internal/cmd/pgo.go +++ b/internal/cmd/pgo.go @@ -18,6 +18,7 @@ import ( "io" "os" "path/filepath" + "strings" "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" @@ -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/ diff --git a/internal/cmd/restore.go b/internal/cmd/restore.go index 4df57c43..85626537 100644 --- a/internal/cmd/restore.go +++ b/internal/cmd/restore.go @@ -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(` @@ -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} diff --git a/internal/cmd/show.go b/internal/cmd/show.go index 5119aa0a..be141dd9 100644 --- a/internal/cmd/show.go +++ b/internal/cmd/show.go @@ -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(` diff --git a/internal/cmd/version.go b/internal/cmd/version.go index f0be2d21..1cdda93f 100644 --- a/internal/cmd/version.go +++ b/internal/cmd/version.go @@ -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'