IsInstanceRunning returns a boolean indicating if the given instance is running and any error encountered
( ctx context.Context, pod corev1.Pod, )
| 136 | |
| 137 | // IsInstanceRunning returns a boolean indicating if the given instance is running and any error encountered |
| 138 | func IsInstanceRunning( |
| 139 | ctx context.Context, |
| 140 | pod corev1.Pod, |
| 141 | ) (bool, error) { |
| 142 | contextLogger := log.FromContext(ctx).WithName("plugin.IsInstanceRunning") |
| 143 | timeout := time.Second * 10 |
| 144 | clientInterface := kubernetes.NewForConfigOrDie(plugin.Config) |
| 145 | stdout, stderr, err := utils.ExecCommand( |
| 146 | ctx, |
| 147 | clientInterface, |
| 148 | plugin.Config, |
| 149 | pod, |
| 150 | specs.PostgresContainerName, |
| 151 | &timeout, |
| 152 | "pg_ctl", "status") |
| 153 | if err == nil { |
| 154 | return true, nil |
| 155 | } |
| 156 | |
| 157 | var codeExitError exec.CodeExitError |
| 158 | if errors.As(err, &codeExitError) { |
| 159 | switch pgCtlStatusExitCode(codeExitError.Code) { |
| 160 | case pgCtlStatusStopped: |
| 161 | return false, nil |
| 162 | case pgCtlStatusNoAccessibleDirectory: |
| 163 | return false, fmt.Errorf("could not check instance status: no accessible data directory") |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | contextLogger.Debug("encountered an error while getting instance status", |
| 168 | "stdout", stdout, |
| 169 | "stderr", stderr, |
| 170 | "err", err, |
| 171 | ) |
| 172 | |
| 173 | return false, err |
| 174 | } |
nothing calls this directly
no test coverage detected