IsReady ensures that the operator will be ready.
( ctx context.Context, crudClient client.Client, checkWebhook bool, )
| 167 | |
| 168 | // IsReady ensures that the operator will be ready. |
| 169 | func IsReady( |
| 170 | ctx context.Context, |
| 171 | crudClient client.Client, |
| 172 | checkWebhook bool, |
| 173 | ) (bool, error) { |
| 174 | if ready, err := isDeploymentReady(ctx, crudClient); err != nil || !ready { |
| 175 | return ready, err |
| 176 | } |
| 177 | |
| 178 | // If the operator is not managing webhooks, we don't need to check. Exit early |
| 179 | if !checkWebhook { |
| 180 | return true, nil |
| 181 | } |
| 182 | |
| 183 | deploy, err := GetDeployment(ctx, crudClient) |
| 184 | if err != nil { |
| 185 | return false, err |
| 186 | } |
| 187 | namespace := deploy.GetNamespace() |
| 188 | |
| 189 | // Detect if we are running under OLM |
| 190 | var webhookManagedByOLM bool |
| 191 | for _, envVar := range deploy.Spec.Template.Spec.Containers[0].Env { |
| 192 | if envVar.Name == "WEBHOOK_CERT_DIR" { |
| 193 | webhookManagedByOLM = true |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // If the operator is managing certificates for webhooks, check that the setup is completed |
| 198 | if !webhookManagedByOLM { |
| 199 | err = checkWebhookSetup(ctx, crudClient, namespace) |
| 200 | if err != nil { |
| 201 | return false, err |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return isWebhookWorking(ctx, crudClient) |
| 206 | } |
| 207 | |
| 208 | // WaitForReady waits for the operator deployment to be ready. |
| 209 | // If checkWebhook is true, it will also check that the webhook is replying |
no test coverage detected