MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / CountReplicas

Function CountReplicas

tests/utils/postgres/postgres.go:57–80  ·  view source on GitHub ↗

CountReplicas counts the number of replicas attached to an instance

(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	pod *corev1.Pod,
	retryTimeout int,
)

Source from the content-addressed store, hash-verified

55
56// CountReplicas counts the number of replicas attached to an instance
57func CountReplicas(
58 ctx context.Context,
59 crudClient client.Client,
60 kubeInterface kubernetes.Interface,
61 restConfig *rest.Config,
62 pod *corev1.Pod,
63 retryTimeout int,
64) (int, error) {
65 query := "SELECT count(*) FROM pg_catalog.pg_stat_replication"
66 stdOut, _, err := exec.EventuallyExecQueryInInstancePod(
67 ctx, crudClient, kubeInterface, restConfig,
68 exec.PodLocator{
69 Namespace: pod.Namespace,
70 PodName: pod.Name,
71 }, AppDBName,
72 query,
73 retryTimeout,
74 objects.PollingTime,
75 )
76 if err != nil {
77 return 0, nil
78 }
79 return strconv.Atoi(strings.Trim(stdOut, "\n"))
80}
81
82// GetCurrentTimestamp getting current time stamp from postgres server
83func GetCurrentTimestamp(

Callers 2

failover_test.goFile · 0.92

Calls 1

Tested by 1