GetDeployment returns the operator Deployment if there is a single one running, error otherwise
(ctx context.Context, crudClient client.Client)
| 100 | |
| 101 | // GetDeployment returns the operator Deployment if there is a single one running, error otherwise |
| 102 | func GetDeployment(ctx context.Context, crudClient client.Client) (appsv1.Deployment, error) { |
| 103 | deploymentList := &appsv1.DeploymentList{} |
| 104 | if err := objects.List(ctx, crudClient, deploymentList, |
| 105 | client.MatchingLabels{"app.kubernetes.io/name": "cloudnative-pg"}, |
| 106 | ); err != nil { |
| 107 | return appsv1.Deployment{}, err |
| 108 | } |
| 109 | // We check if we have one or more deployments |
| 110 | switch { |
| 111 | case len(deploymentList.Items) > 1: |
| 112 | err := fmt.Errorf("number of operator deployments != 1") |
| 113 | return appsv1.Deployment{}, err |
| 114 | case len(deploymentList.Items) == 1: |
| 115 | return deploymentList.Items[0], nil |
| 116 | } |
| 117 | |
| 118 | if err := objects.List( |
| 119 | ctx, |
| 120 | crudClient, |
| 121 | deploymentList, |
| 122 | client.HasLabels{"operators.coreos.com/cloudnative-pg.openshift-operators"}, |
| 123 | ); err != nil { |
| 124 | return appsv1.Deployment{}, err |
| 125 | } |
| 126 | |
| 127 | // We check if we have one or more deployments |
| 128 | switch { |
| 129 | case len(deploymentList.Items) > 1: |
| 130 | err := fmt.Errorf("number of operator deployments != 1") |
| 131 | return appsv1.Deployment{}, err |
| 132 | case len(deploymentList.Items) == 1: |
| 133 | return deploymentList.Items[0], nil |
| 134 | } |
| 135 | |
| 136 | return deploymentList.Items[0], nil |
| 137 | } |
| 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) { |
no test coverage detected