GetPod returns the operator pod if there is a single one running, error otherwise
(ctx context.Context, crudClient client.Client)
| 138 | |
| 139 | // GetPod returns the operator pod if there is a single one running, error otherwise |
| 140 | func 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 |
| 160 | func NamespaceName(ctx context.Context, crudClient client.Client) (string, error) { |
no test coverage detected