WebhookCfgsInit initializes the webhook that denies everything until webhook server is started successfully
(client crclient.Client, ctx context.Context, namespace string)
| 29 | |
| 30 | // WebhookCfgsInit initializes the webhook that denies everything until webhook server is started successfully |
| 31 | func WebhookCfgsInit(client crclient.Client, ctx context.Context, namespace string) error { |
| 32 | configuration := workspace.BuildMutateWebhookCfg(namespace) |
| 33 | |
| 34 | err := client.Create(ctx, configuration, &crclient.CreateOptions{}) |
| 35 | if err != nil { |
| 36 | if apierrors.IsAlreadyExists(err) { |
| 37 | log.Info(fmt.Sprintf("Mutating webhooks configuration %s already exists", configuration.Name)) |
| 38 | return checkExistingConfigForConflict(client, ctx, namespace) |
| 39 | } else { |
| 40 | return err |
| 41 | } |
| 42 | } |
| 43 | log.Info(fmt.Sprintf("Created webhooks configuration %s", configuration.Name)) |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | func checkExistingConfigForConflict(client crclient.Client, ctx context.Context, serviceNamespace string) error { |
| 48 | existingCfg := &admv1.MutatingWebhookConfiguration{} |
no test coverage detected