cmd

package
v4.1.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Package cmd provides the command line functions of the crunchy CLI

Index

Constants

View Source
const CAPMAX = 50
View Source
const TreeBranch = "\t"
View Source
const TreeTrunk = "\t"

Variables

View Source
var (
	BenchmarkClients      int
	BenchmarkJobs         int
	BenchmarkScale        int
	BenchmarkTransactions int
	BenchmarkDatabase     string
	BenchmarkInitOpts     string
	BenchmarkOpts         string
	BenchmarkPolicy       string
	BenchmarkUser         string
)
View Source
var APIServerURL string
View Source
var AllFlag bool
View Source
var AllNamespaces bool
View Source
var ArchiveFlag, AutofailFlag, PgpoolFlag, PgbouncerFlag, MetricsFlag, BadgerFlag bool
View Source
var AutofailReplaceReplica string
View Source
var BackrestFlag, BackrestRestoreFrom string
View Source
var BackrestStorageType string
View Source
var BackupOpts string
View Source
var BackupPath, BackupPVC string
View Source
var BackupType string
View Source
var CCPImage string
View Source
var CCPImageTag string
View Source
var ClusterReplicaCount int
View Source
var ConfigMapName string

unused but coming soon to a theatre near you

View Source
var ContainerResources string
View Source
var CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a Postgres Operator resource",
	Long: `CREATE allows you to create a new Operator resource. For example: 
    pgo create cluster
    pgo create pgbouncer
    pgo create pgpool
    pgo create pgouser
    pgo create pgorole
    pgo create policy
    pgo create namespace
    pgo create user`,
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("create called")
		if len(args) == 0 {
			fmt.Println(`Error: You must specify the type of resource to create.  Valid resource types include:
    * cluster
    * pgbouncer
    * pgpool
    * pgouser
    * pgorole
    * policy
    * namespace
    * user`)
		} else {
			switch args[0] {
			case "cluster", "pgbouncer", "pgpool", "pgouser", "pgorole", "policy", "user", "namespace":
				break
			default:
				fmt.Println(`Error: You must specify the type of resource to create.  Valid resource types include:
    * cluster
    * pgbouncer
    * pgpool
    * pgouser
    * pgorole
    * policy
    * namespace
    * user`)
			}
		}
	},
}
View Source
var CustomConfig string
View Source
var DebugFlag bool
View Source
var DeleteBackups bool
View Source
var DeleteData bool

flags used by more than 1 command

View Source
var DeleteLabel bool
View Source
var DeleteUser string

DeleteUser delete user flag

View Source
var DryRun bool
View Source
var ExpireUser bool
View Source
var Expired string

Expired expired flag

View Source
var GREEN func(a ...interface{}) string
View Source
var LabelCmdLabel string
View Source
var LabelMap map[string]string
View Source
var Labelselector string
View Source
var LoadConfig string
View Source
var ManagedUser bool
View Source
var Namespace string
View Source
var NoPrompt bool
View Source
var NodeLabel string
View Source
var OutputFormat string
View Source
var PGBackRestType string
View Source
var PGOEventAddress string
View Source
var PGONamespace string
View Source
var PGO_CA_CERT, PGO_CLIENT_CERT, PGO_CLIENT_KEY string
View Source
var PGO_DISABLE_TLS bool
View Source
var PITRTarget, RestoreBackupPath string
View Source
var PVCName string
View Source
var PVCRoot string
View Source
var Password string
View Source
var PasswordAgeDays int

PasswordAgeDays password age flag

View Source
var PasswordLength int

PasswordLength password length flag

View Source
var Permissions string
View Source
var PgBouncerPassword string
View Source
var PgBouncerUser string
View Source
var PgbouncerSecret string
View Source
var PgoroleChangePermissions bool
View Source
var PgouserChangePassword bool
View Source
var PgouserPassword, PgouserRoles, PgouserNamespaces string
View Source
var PgpoolSecret string
View Source
var PoliciesFlag, PolicyFile, PolicyURL string
View Source
var Query bool
View Source
var RED func(a ...interface{}) string
View Source
var ReplicaCount int
View Source
var ReplicaStorageConfig, StorageConfig string
View Source
var RestoreToPVC string
View Source
var RestoreType string
View Source
var RootCmd = &cobra.Command{
	Use:   "pgo",
	Short: "The pgo command line interface.",
	Long:  `The pgo command line interface lets you create and manage PostgreSQL clusters.`,
}

RootCmd represents the base command when called without any subcommands

View Source
var Schedule string
View Source
var ScheduleDatabase string
View Source
var ScheduleName string
View Source
var ScheduleOptions string
View Source
var SchedulePolicy string
View Source
var ScheduleSecret string
View Source
var ScheduleType string
View Source
var Secret string
View Source
var SecretFrom string
View Source
var Selector string
View Source
var Series int
View Source
var ServiceType string
View Source
var SessionCredentials msgs.BasicAuthCredentials

SessionCredentials stores the PGO user, PGO password and the PGO APIServer URL

View Source
var ShowBackupCmd = &cobra.Command{
	Use:   "backup",
	Short: "Show backup information",
	Long: `Show backup information. For example:

	pgo show backup mycluser`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		if len(args) == 0 {
			fmt.Println("Error: cluster name(s) required for this command.")
		} else {

			if showBackupType == "" || showBackupType == config.LABEL_BACKUP_TYPE_BASEBACKUP {
				showBackup(args, Namespace)
			} else if showBackupType == config.LABEL_BACKUP_TYPE_BACKREST {
				showBackrest(args, Namespace)
			} else if showBackupType == config.LABEL_BACKUP_TYPE_PGDUMP {
				showpgDump(args, Namespace)
			} else {
				fmt.Println("Error: Valid backup-type values are pgbasebackup, pgbackrest and pgdump. The default if not supplied is pgbasebackup.")
			}
		}
	},
}

showBackupCmd represents the show backup command

View Source
var ShowBenchmarkCmd = &cobra.Command{
	Use:   "benchmark",
	Short: "Show benchmark information",
	Long: `Show benchmark results for clusters. For example:

	pgo show benchmark mycluster
	pgo show benchmark --selector=pg-cluster=mycluster`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}

		if len(args) == 0 && Selector == "" {
			fmt.Println("Error: cluster name or selector are required to show benchmark results.")
			return
		}
		showBenchmark(args, Namespace)
	},
}

ShowBenchmarkCmd represents the show benchmark command

View Source
var ShowClusterCmd = &cobra.Command{
	Use:   "cluster",
	Short: "Show cluster information",
	Long: `Show a PostgreSQL cluster. For example:

	pgo show cluster --all
	pgo show cluster mycluster`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		if Selector == "" && len(args) == 0 && !AllFlag {
			fmt.Println("Error: Cluster name(s), --selector, or --all required for this command.")
		} else {
			showCluster(args, Namespace)
		}
	},
}

ShowClusterCmd represents the show cluster command

View Source
var ShowCmd = &cobra.Command{
	Use:   "show",
	Short: "Show the description of a cluster",
	Long: `Show allows you to show the details of a policy, backup, pvc, or cluster. For example:

	pgo show backup mycluster
	pgo show backup mycluster --backup-type=pgbackrest
	pgo show benchmark mycluster
	pgo show cluster mycluster
	pgo show config
	pgo show pgouser someuser
	pgo show policy policy1
	pgo show pvc mycluster
	pgo show namespace
	pgo show workflow 25927091-b343-4017-be4b-71575f0b3eb5
	pgo show user --selector=name=mycluster`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			fmt.Println(`Error: You must specify the type of resource to show.
Valid resource types include:
	* backup
	* benchmark
	* cluster
	* config
	* pgouser
	* policy
	* pvc
	* namespace
	* workflow
	* user
	`)
		} else {
			switch args[0] {
			case "backup", "benchmark", "cluster", "config", "pgouser",
				"policy", "pvc", "schedule", "namespace", "workflow",
				"user":
				break
			default:
				fmt.Println(`Error: You must specify the type of resource to show.
Valid resource types include:
	* backup
	* benchmark
	* cluster
	* config
	* pgouser
	* policy
	* pvc
	* namespace
	* workflow
	* user`)
			}
		}

	},
}
View Source
var ShowConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "Show configuration information",
	Long: `Show configuration information for the Operator. For example:

	pgo show config`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		showConfig(args, Namespace)
	},
}
View Source
var ShowNamespaceCmd = &cobra.Command{
	Use:   "namespace",
	Short: "Show namespace information",
	Long: `Show namespace information for the Operator. For example:

	pgo show namespace`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		showNamespace(args)
	},
}
View Source
var ShowPVC bool
View Source
var ShowPVCCmd = &cobra.Command{
	Use:   "pvc",
	Short: "Show PVC information",
	Long: `Show PVC information. For example:

	pgo show pvc mycluster
	pgo show pvc --all
	pgo show pvc mycluster-backup
	pgo show pvc mycluster-xlog
	pgo show pvc a2-backup --pvc-root=a2-backups/2019-01-12-17-09-42`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 && !AllFlag {
			fmt.Println("Error: PVC name(s) or --all required for this command.")
		} else {
			if Namespace == "" {
				Namespace = PGONamespace
			}
			showPVC(args, Namespace)
		}
	},
}
View Source
var ShowPgoroleCmd = &cobra.Command{
	Use:   "pgorole",
	Short: "Show pgorole information",
	Long: `Show pgorole information . For example:

	pgo show pgorole somerole`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		showPgorole(args, Namespace)
	},
}
View Source
var ShowPgouserCmd = &cobra.Command{
	Use:   "pgouser",
	Short: "Show pgouser information",
	Long: `Show pgouser information for an Operator user. For example:

	pgo show pgouser someuser`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		showPgouser(args, Namespace)
	},
}
View Source
var ShowPolicyCmd = &cobra.Command{
	Use:   "policy",
	Short: "Show policy information",
	Long: `Show policy information. For example:

	pgo show policy --all
	pgo show policy policy1`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 && !AllFlag {
			fmt.Println("Error: Policy name(s) or --all required for this command.")
		} else {
			if Namespace == "" {
				Namespace = PGONamespace
			}
			showPolicy(args, Namespace)
		}
	},
}
View Source
var ShowScheduleCmd = &cobra.Command{
	Use:   "schedule",
	Short: "Show schedule information",
	Long: `Show cron-like schedules.  For example:

	pgo show schedule mycluster
	pgo show schedule --selector=pg-cluster=mycluster
	pgo show schedule --schedule-name=mycluster-pgbackrest-full`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		if len(args) == 0 && Selector == "" && ScheduleName == "" {
			fmt.Println("Error: cluster name, schedule name or selector is required to show a schedule.")
			return
		}
		showSchedule(args, Namespace)
	},
}

ShowScheduleCmd represents the show schedule command

View Source
var ShowUserCmd = &cobra.Command{
	Use:   "user",
	Short: "Show user information",
	Long: `Show users on a cluster. For example:

	pgo show user --all
	pgo show user mycluster
	pgo show user --selector=name=nycluster`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		if Selector == "" && AllFlag == false && len(args) == 0 {
			fmt.Println("Error: --selector, --all, or cluster name()s required for this command")
		} else {
			showUser(args, Namespace)
		}
	},
}

ShowUserCmd represents the show user command

View Source
var ShowWorkflowCmd = &cobra.Command{
	Use:   "workflow",
	Short: "Show workflow information",
	Long: `Show workflow information for a given workflow. For example:

	pgo show workflow 25927091-b343-4017-be4b-71575f0b3eb5`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}
		showWorkflow(args, Namespace)
	},
}
View Source
var Summary bool
View Source
var Target string
View Source
var UpdateClusterCmd = &cobra.Command{
	Use:   "cluster",
	Short: "Update a PostgreSQL cluster",
	Long: `Update a PostgreSQL cluster. For example:

    pgo update cluster mycluster --autofail=false
    pgo update cluster mycluster myothercluster --autofail=false
    pgo update cluster --selector=name=mycluster --autofail=false
    pgo update cluster --all --autofail=true`,
	Run: func(cmd *cobra.Command, args []string) {
		if Namespace == "" {
			Namespace = PGONamespace
		}

		if len(args) == 0 && Selector == "" && !AllFlag {
			fmt.Println("Error: A cluster name(s) or selector or --all is required for this command.")
		} else {
			if util.AskForConfirmation(NoPrompt, "") {
				updateCluster(args, Namespace)
			} else {
				fmt.Println("Aborting...")
			}
		}
	},
}

UpdateClusterCmd ...

View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update a pgouser, pgorole, or cluster",
	Long: `The update command allows you to update a pgouser, pgorole, or cluster. For example:

	pgo update pgouser someuser --pgouser-password=somenewpassword
	pgo update pgouser someuser --pgouser-roles="role1,role2"
	pgo update pgouser someuser --pgouser-namespaces="pgouser2"
	pgo update user mycluster --username=testuser --selector=name=mycluster --password=somepassword
	pgo update pgorole somerole --pgorole-permission="Cat"
	pgo update namespace mynamespace 
	pgo update cluster --selector=name=mycluster --autofail=false
	pgo update cluster --all --autofail=true`,
	Run: func(cmd *cobra.Command, args []string) {

		if len(args) == 0 {
			fmt.Println(`Error: You must specify the type of resource to update.  Valid resource types include:
	* pgouser
	* pgorole
	* user
	* namespace
	* cluster`)
		} else {
			switch args[0] {
			case "user", "cluster", "pgouser", "pgorole", "namespace":
				break
			default:
				fmt.Println(`Error: You must specify the type of resource to update.  Valid resource types include:
	* cluster
	* pgorole
	* user
	* namespace
	* pgouser`)
			}
		}

	},
}

UpdateCmd represents the update command

View Source
var UpdateNamespaceCmd = &cobra.Command{
	Use:   "namespace",
	Short: "Update a namespace, applying Operator RBAC",
	Long: `UPDATE allows you to update a Namespace. For example:
		pgo update namespace mynamespace`,
	Run: func(cmd *cobra.Command, args []string) {

		if len(args) == 0 {
			fmt.Println("Error: You must specify the name of a Namespace.")
		} else {
			updateNamespace(args)
		}
	},
}
View Source
var UpdatePgoroleCmd = &cobra.Command{
	Use:   "pgorole",
	Short: "Update a pgorole",
	Long: `UPDATE allows you to update a pgo role. For example:
		pgo update pgorole somerole  --permissions="Cat,Ls`,
	Run: func(cmd *cobra.Command, args []string) {

		if Namespace == "" {
			Namespace = PGONamespace
		}

		if len(args) == 0 {
			fmt.Println("Error: You must specify the name of a pgorole.")
		} else {
			updatePgorole(args, Namespace)
		}
	},
}
View Source
var UpdatePgouserCmd = &cobra.Command{
	Use:   "pgouser",
	Short: "Update a pgouser",
	Long: `UPDATE allows you to update a pgo user. For example:
		pgo update pgouser myuser --pgouser-roles=somerole
		pgo update pgouser myuser --pgouser-password=somepassword --pgouser-roles=somerole
		pgo update pgouser myuser --pgouser-password=somepassword --no-prompt`,
	Run: func(cmd *cobra.Command, args []string) {

		if Namespace == "" {
			Namespace = PGONamespace
		}

		if len(args) == 0 {
			fmt.Println("Error: You must specify the name of a pgouser.")
		} else {
			updatePgouser(args, Namespace)
		}
	},
}
View Source
var UpdateUserCmd = &cobra.Command{
	Use:   "user",
	Short: "Update a postgres user",
	Long: `UPDATE allows you to update a pgo user. For example:
		//change a password, set valid days for 40 days from now
		pgo update user mycluster --username=someuser --password=foo --valid-days=40
		//expire password for a user
		pgo update user mycluster --username=someuser --expire-user
		//Update all passwords older than the number of days specified
		pgo update user mycluster --expired=45 --password-length=8`,
	Run: func(cmd *cobra.Command, args []string) {

		validDaysUpdate := cmd.Flag("valid-days").Changed

		if Namespace == "" {
			Namespace = PGONamespace
		}

		if !AllFlag && Selector == "" && len(args) == 0 {
			fmt.Println("Error: You must specify a --selector, --all  or a list of clusters.")
		} else {
			updateUser(args, Namespace, validDaysUpdate)
		}
	},
}
View Source
var UserLabels string
View Source
var Username string

Username is a postgres username

View Source
var ValidDays string

ValidDays valid days flag

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func GetTLSCredentials

func GetTLSCredentials() *http.Transport

GetTLSCredentials instantiate gathers the necessary client connection TLS settings for use by the PGO client. If TLS is disabled, this will not be called.

func SetHTTPClient

func SetHTTPClient(httpTransport *http.Transport)

SetHTTPClient instantiates the PGO HTTP client for use with the Operator's apiserver. It sets a timeout based on the httpTimeout constant, and configures the client for either unauthenticated or TLS connections, as configured.

func SetSessionUserCredentials

func SetSessionUserCredentials()

SetSessionUserCredentials gathers the pgouser and password information and stores them for use by the PGO client

func StatusCheck

func StatusCheck(resp *http.Response)

StatusCheck ...

Types

type TailHandler

type TailHandler struct {
	// contains filtered or unexported fields
}

func (*TailHandler) HandleMessage

func (th *TailHandler) HandleMessage(m *nsq.Message) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL