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

Function GetInstancePods

internal/plugin/resources/instance.go:56–75  ·  view source on GitHub ↗

GetInstancePods gets all the pods belonging to a given cluster returns an array with all the instances, the primary instance and any error encountered.

(ctx context.Context, clusterName string)

Source from the content-addressed store, hash-verified

54// GetInstancePods gets all the pods belonging to a given cluster
55// returns an array with all the instances, the primary instance and any error encountered.
56func GetInstancePods(ctx context.Context, clusterName string) ([]corev1.Pod, corev1.Pod, error) {
57 var pods corev1.PodList
58 if err := plugin.Client.List(ctx, &pods, client.InNamespace(plugin.Namespace)); err != nil {
59 return nil, corev1.Pod{}, err
60 }
61
62 var managedPods []corev1.Pod
63 var primaryPod corev1.Pod
64 for idx := range pods.Items {
65 for _, owner := range pods.Items[idx].OwnerReferences {
66 if owner.Kind == apiv1.ClusterKind && owner.Name == clusterName {
67 managedPods = append(managedPods, pods.Items[idx])
68 if specs.IsPodPrimary(pods.Items[idx]) {
69 primaryPod = pods.Items[idx]
70 }
71 }
72 }
73 }
74 return managedPods, primaryPod, nil
75}
76
77// ExtractInstancesStatus extracts the instance status from the given pod list
78func ExtractInstancesStatus(

Callers 1

extractPostgresqlStatusFunction · 0.92

Calls 2

IsPodPrimaryFunction · 0.92
ListMethod · 0.45

Tested by

no test coverage detected