MCPcopy Index your code
hub / github.com/cloudnative-pg/cloudnative-pg / IsInstanceRunning

Function IsInstanceRunning

internal/plugin/resources/instance.go:138–174  ·  view source on GitHub ↗

IsInstanceRunning returns a boolean indicating if the given instance is running and any error encountered

(
	ctx context.Context,
	pod corev1.Pod,
)

Source from the content-addressed store, hash-verified

136
137// IsInstanceRunning returns a boolean indicating if the given instance is running and any error encountered
138func 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}

Callers

nothing calls this directly

Calls 4

ExecCommandFunction · 0.92
pgCtlStatusExitCodeTypeAlias · 0.85
WithNameMethod · 0.80
DebugMethod · 0.80

Tested by

no test coverage detected