(ctx context.Context, cfg *rest.Config)
| 33 | var log = logf.Log.WithName("webhook") |
| 34 | |
| 35 | func SetupWebhooks(ctx context.Context, cfg *rest.Config) error { |
| 36 | namespace, err := infrastructure.GetOperatorNamespace() |
| 37 | if err != nil { |
| 38 | namespace = os.Getenv(infrastructure.WatchNamespaceEnvVar) |
| 39 | } |
| 40 | |
| 41 | client, err := crclient.New(cfg, crclient.Options{}) |
| 42 | if err != nil { |
| 43 | return fmt.Errorf("failed to create new client: %w", err) |
| 44 | } |
| 45 | |
| 46 | // Set up the certs |
| 47 | log.Info("Setting up the init webhooks configurations") |
| 48 | err = WebhookCfgsInit(client, ctx, namespace) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | err = setUpWebhookServerRBAC(ctx, err, client, namespace) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | secretName, err := config.GetWebhooksSecretName() |
| 59 | if err != nil { |
| 60 | return fmt.Errorf("could not deploy webhooks server: %w", err) |
| 61 | } |
| 62 | if infrastructure.IsOpenShift() { |
| 63 | // Set up the certs for OpenShift |
| 64 | log.Info("Setting up the OpenShift webhook server secure service") |
| 65 | log.Info("Injecting serving cert using the Service CA operator") |
| 66 | err := webhook_openshift.SetupSecureService(client, ctx, secretName, namespace) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | } else { |
| 71 | log.Info("Setting up the Kubernetes webhook server secure service") |
| 72 | log.Info(fmt.Sprintf("Using certificate stored in secret '%s' to serve webhooks", secretName)) |
| 73 | err = webhook_k8s.SetupSecureService(client, ctx, namespace) |
| 74 | if err != nil { |
| 75 | return err |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Set up the deployment |
| 80 | log.Info("Creating the webhook server deployment") |
| 81 | err = CreateWebhookServerDeployment(client, ctx, secretName, namespace) |
| 82 | if err != nil { |
| 83 | return err |
| 84 | } |
| 85 | |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // setUpWebhookServerRBAC sets required service account, cluster role, and cluster role binding |
| 90 | // for creating a webhook server |
nothing calls this directly
no test coverage detected