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

Function GetPrimary

tests/utils/clusterutils/cluster.go:160–188  ·  view source on GitHub ↗

GetPrimary gets the primary pod of a cluster

(
	ctx context.Context,
	crudClient client.Client,
	namespace, clusterName string,
)

Source from the content-addressed store, hash-verified

158
159// GetPrimary gets the primary pod of a cluster
160func GetPrimary(
161 ctx context.Context,
162 crudClient client.Client,
163 namespace, clusterName string,
164) (*corev1.Pod, error) {
165 podList := &corev1.PodList{}
166
167 err := objects.List(ctx, crudClient, podList, client.InNamespace(namespace),
168 client.MatchingLabels{
169 utils.ClusterLabelName: clusterName,
170 utils.ClusterInstanceRoleLabelName: specs.ClusterRoleLabelPrimary,
171 },
172 )
173 if err != nil {
174 return &corev1.Pod{}, err
175 }
176 if len(podList.Items) > 0 {
177 // if there are multiple, get the one without deletion timestamp
178 for _, pod := range podList.Items {
179 if pod.DeletionTimestamp == nil {
180 return &pod, nil
181 }
182 }
183 err = fmt.Errorf("all pod with primary role has deletion timestamp")
184 return &(podList.Items[0]), err
185 }
186 err = fmt.Errorf("no primary found")
187 return &corev1.Pod{}, err
188}
189
190// GetReplicas gets a slice containing all the replica pods of a cluster
191func GetReplicas(

Calls 1

ListFunction · 0.92