NewCmd creates the "pgbasebackup" subcommand
()
| 50 | |
| 51 | // NewCmd creates the "pgbasebackup" subcommand |
| 52 | func NewCmd() *cobra.Command { |
| 53 | var clusterName string |
| 54 | var namespace string |
| 55 | var pgData string |
| 56 | var pgWal string |
| 57 | |
| 58 | cmd := &cobra.Command{ |
| 59 | Use: "pgbasebackup", |
| 60 | PreRunE: func(cmd *cobra.Command, _ []string) error { |
| 61 | return management.WaitForGetCluster(cmd.Context(), ctrl.ObjectKey{ |
| 62 | Name: clusterName, |
| 63 | Namespace: namespace, |
| 64 | }) |
| 65 | }, |
| 66 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 67 | ctx := cmd.Context() |
| 68 | contextLogger := log.FromContext(ctx) |
| 69 | |
| 70 | client, err := management.NewControllerRuntimeClient() |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | env := CloneInfo{ |
| 76 | info: &postgres.InitInfo{ |
| 77 | ClusterName: clusterName, |
| 78 | Namespace: namespace, |
| 79 | PgData: pgData, |
| 80 | PgWal: pgWal, |
| 81 | }, |
| 82 | client: client, |
| 83 | } |
| 84 | |
| 85 | if err := env.info.EnsureTargetDirectoriesDoNotExist(ctx); err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | if err = env.bootstrapUsingPgbasebackup(ctx); err != nil { |
| 90 | contextLogger.Error(err, "Unable to bootstrap cluster") |
| 91 | } |
| 92 | return err |
| 93 | }, |
| 94 | PostRunE: func(cmd *cobra.Command, _ []string) error { |
| 95 | if err := istio.TryInvokeQuitEndpoint(cmd.Context()); err != nil { |
| 96 | return err |
| 97 | } |
| 98 | |
| 99 | return linkerd.TryInvokeShutdownEndpoint(cmd.Context()) |
| 100 | }, |
| 101 | } |
| 102 | |
| 103 | cmd.Flags().StringVar(&clusterName, "cluster-name", os.Getenv("CLUSTER_NAME"), "The name of the "+ |
| 104 | "current cluster in k8s, used to coordinate switchover and failover") |
| 105 | cmd.Flags().StringVar(&namespace, "namespace", os.Getenv("NAMESPACE"), "The namespace of "+ |
| 106 | "the cluster and of the Pod in k8s") |
| 107 | cmd.Flags().StringVar(&pgData, "pg-data", os.Getenv("PGDATA"), "The PGDATA to be created") |
| 108 | cmd.Flags().StringVar(&pgWal, "pg-wal", "", "the PGWAL to be created") |
| 109 |
no test coverage detected