NewCmd creates the new "join" command
()
| 38 | |
| 39 | // NewCmd creates the new "join" command |
| 40 | func NewCmd() *cobra.Command { |
| 41 | var pgData string |
| 42 | var pgWal string |
| 43 | var parentNode string |
| 44 | var podName string |
| 45 | var clusterName string |
| 46 | var namespace string |
| 47 | |
| 48 | cmd := &cobra.Command{ |
| 49 | Use: "join [options]", |
| 50 | PreRunE: func(cmd *cobra.Command, _ []string) error { |
| 51 | return management.WaitForGetCluster(cmd.Context(), ctrl.ObjectKey{ |
| 52 | Name: clusterName, |
| 53 | Namespace: namespace, |
| 54 | }) |
| 55 | }, |
| 56 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 57 | ctx := cmd.Context() |
| 58 | // The fields in the instance are needed to correctly |
| 59 | // download the secret containing the TLS |
| 60 | // certificates |
| 61 | instance := postgres.NewInstance(). |
| 62 | WithNamespace(namespace). |
| 63 | WithPodName(podName). |
| 64 | WithClusterName(clusterName) |
| 65 | |
| 66 | info := postgres.InitInfo{ |
| 67 | PgData: pgData, |
| 68 | PgWal: pgWal, |
| 69 | ParentNode: parentNode, |
| 70 | PodName: podName, |
| 71 | } |
| 72 | |
| 73 | return joinSubCommand(ctx, instance, info) |
| 74 | }, |
| 75 | PostRunE: func(cmd *cobra.Command, _ []string) error { |
| 76 | if err := istio.TryInvokeQuitEndpoint(cmd.Context()); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | |
| 80 | return linkerd.TryInvokeShutdownEndpoint(cmd.Context()) |
| 81 | }, |
| 82 | } |
| 83 | |
| 84 | cmd.Flags().StringVar(&pgData, "pg-data", os.Getenv("PGDATA"), "The PGDATA to be created") |
| 85 | cmd.Flags().StringVar(&pgWal, "pg-wal", "", "the PGWAL to be created") |
| 86 | cmd.Flags().StringVar(&parentNode, "parent-node", "", "The origin node") |
| 87 | cmd.Flags().StringVar(&podName, "pod-name", os.Getenv("POD_NAME"), "The name of this pod, to "+ |
| 88 | "be checked against the cluster state") |
| 89 | cmd.Flags().StringVar(&namespace, "namespace", os.Getenv("NAMESPACE"), "The namespace of "+ |
| 90 | "the cluster and of the Pod in k8s") |
| 91 | cmd.Flags().StringVar(&clusterName, "cluster-name", os.Getenv("CLUSTER_NAME"), "The name of "+ |
| 92 | "the current cluster in k8s, used to download TLS certificates") |
| 93 | |
| 94 | return cmd |
| 95 | } |
| 96 | |
| 97 | func joinSubCommand(ctx context.Context, instance *postgres.Instance, info postgres.InitInfo) error { |
no test coverage detected