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

Function GetPod

tests/utils/operator/operator.go:140–157  ·  view source on GitHub ↗

GetPod returns the operator pod if there is a single one running, error otherwise

(ctx context.Context, crudClient client.Client)

Source from the content-addressed store, hash-verified

138
139// GetPod returns the operator pod if there is a single one running, error otherwise
140func GetPod(ctx context.Context, crudClient client.Client) (corev1.Pod, error) {
141 podList := &corev1.PodList{}
142
143 // This will work for newer versions of the operator, which are using
144 // our custom label
145 if err := objects.List(
146 ctx, crudClient,
147 podList, client.MatchingLabels{"app.kubernetes.io/name": "cloudnative-pg"}); err != nil {
148 return corev1.Pod{}, err
149 }
150 activePods := utils.FilterActivePods(podList.Items)
151 if len(activePods) != 1 {
152 err := fmt.Errorf("number of running operator different than 1: %v pods running", len(activePods))
153 return corev1.Pod{}, err
154 }
155
156 return activePods[0], nil
157}
158
159// NamespaceName returns the namespace the operator Deployment is running in
160func NamespaceName(ctx context.Context, crudClient client.Client) (string, error) {

Callers 8

suite_test.goFile · 0.92
upgrade_test.goFile · 0.92
ReloadDeploymentFunction · 0.85
GetPodNameFunction · 0.85

Calls 2

ListFunction · 0.92
FilterActivePodsFunction · 0.92

Tested by

no test coverage detected