NewCmd creates the "instance run" subcommand
()
| 76 | |
| 77 | // NewCmd creates the "instance run" subcommand |
| 78 | func NewCmd() *cobra.Command { |
| 79 | var pgData string |
| 80 | var podName string |
| 81 | var clusterName string |
| 82 | var namespace string |
| 83 | var pprofHTTPServer bool |
| 84 | var statusPortTLS bool |
| 85 | var metricsPortTLS bool |
| 86 | |
| 87 | cmd := &cobra.Command{ |
| 88 | Use: "run [flags]", |
| 89 | PreRunE: func(cmd *cobra.Command, _ []string) error { |
| 90 | return management.WaitForGetCluster(cmd.Context(), client.ObjectKey{ |
| 91 | Name: clusterName, |
| 92 | Namespace: namespace, |
| 93 | }) |
| 94 | }, |
| 95 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 96 | ctx := log.IntoContext( |
| 97 | cmd.Context(), |
| 98 | log.GetLogger().WithValues("logger", "instance-manager"), |
| 99 | ) |
| 100 | |
| 101 | checkCurrentOSRelease(ctx) |
| 102 | |
| 103 | instance := postgres.NewInstance(). |
| 104 | WithPodName(podName). |
| 105 | WithClusterName(clusterName). |
| 106 | WithNamespace(namespace) |
| 107 | |
| 108 | instance.PgData = pgData |
| 109 | instance.StatusPortTLS = statusPortTLS |
| 110 | instance.MetricsPortTLS = metricsPortTLS |
| 111 | |
| 112 | // Since version 0.19.0 of controller-runtime, it is not allowed to create multiple controllers with the |
| 113 | // same name. As this part of the code is run inside a retry block, we need to allow SkipNameValidation |
| 114 | // only on retries, because a previous run may have already created a controller |
| 115 | // Reference https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.19.0 |
| 116 | var skipNameValidation bool |
| 117 | err := retry.OnError(retry.DefaultRetry, isRunSubCommandRetryable, func() error { |
| 118 | defer func() { skipNameValidation = true }() |
| 119 | return runSubCommand(ctx, instance, pprofHTTPServer, skipNameValidation) |
| 120 | }) |
| 121 | |
| 122 | if errors.Is(err, postgres.ErrNoFreeWALSpace) { |
| 123 | os.Exit(apiv1.MissingWALDiskSpaceExitCode) |
| 124 | } |
| 125 | |
| 126 | return err |
| 127 | }, |
| 128 | PostRunE: func(cmd *cobra.Command, _ []string) error { |
| 129 | if err := istio.TryInvokeQuitEndpoint(cmd.Context()); err != nil { |
| 130 | return err |
| 131 | } |
| 132 | |
| 133 | return linkerd.TryInvokeShutdownEndpoint(cmd.Context()) |
| 134 | }, |
| 135 | } |
no test coverage detected