# Webhook configuration

> Settings for the StormForge admission webhook

---

Site [llms.txt](/llms.txt)

---

This topic covers the configuration parameters available for the StormForge webhook.

The webhook runs as its own Deployment and serves these functions:

- **[Pod mutation](#pod-mutation):** sets recommended container resources on Pods when they're created, for workloads that use a webhook-based [apply method][apply-method].
- **Validation:** checks [ClusterOptimizationConfiguration and OptimizationConfiguration](/docs/configure/optimization-configurations/) resources when you create or update them.
- **[CRD conversion](#crd-conversion):** converts ClusterOptimizationConfiguration and OptimizationConfiguration resources between `optimize.stormforge.io/v1` and `v2`.

## Applying these settings

These are Helm values for the `stormforge` chart. Add them to a YAML values file (for example, `values.yaml`) and pass it to your Helm command.

At install time:

```shell
helm install stormforge oci://registry.stormforge.io/library/stormforge \
  --namespace stormforge-system \
  -f values.yaml
```

To apply changes after installation:

```shell
helm upgrade stormforge oci://registry.stormforge.io/library/stormforge \
  --namespace stormforge-system \
  --reset-then-reuse-values \
  -f values.yaml
```

---


**Webhook parameters:**

- [Enable or disable the webhook](#webhook-enabled)
- [Pod mutation](#pod-mutation)
- [Namespace allow and deny lists](#namespace-lists)
- [Failure policy](#failure-policy)
- [TLS configuration](#tls)
- [Use your own TLS certificate](#tls-own-certificate)
- [CRD conversion](#crd-conversion)
- [Deprecated parameter names](#deprecated)

---

## Enable or disable the webhook {#webhook-enabled}

Controls whether StormForge runs the webhook Deployment.

| Parameter          | Default value |
| ------------------ | ------------- |
| `webhook.enabled`  | `true`        |

### Description {#webhook-enabled-description}

When the chart installs the StormForge CRDs (`crds.enabled=true`, the default), the webhook is required: installing or upgrading fails if `webhook.enabled` is `false`. The ClusterOptimizationConfiguration and OptimizationConfiguration CRDs rely on the webhook to convert resources between `v1` and `v2`. To stop the webhook from changing Pods while keeping it running, disable [pod mutation](#pod-mutation) instead.

### Valid values {#webhook-enabled-valid-values}

- `true` (default)
- `false`: only when you set `crds.enabled=false` and don't use ClusterOptimizationConfiguration or OptimizationConfiguration resources

---

## Pod mutation {#pod-mutation}

Controls whether the webhook sets recommended container resources on Pods when they're created.

| Parameter                                         | Default value |
| ------------------------------------------------- | ------------- |
| `webhook.handlers.podContainerResources.enabled`  | `true`        |

### Description {#pod-mutation-description}

Pod mutation applies recommendations for workloads that use a webhook-based apply method (`WebhookImmediateRollout`, `WebhookHybridRollout`, `WebhookDeferredRollout`). It requires `webhook.enabled=true` and the Applier (`applier.enabled=true`).

When pod mutation is disabled, or a [namespace list](#namespace-lists) excludes a namespace, recommendations are still generated but aren't applied to workloads that use a webhook-based method. The recommended values in the UI and CLI can then differ from the values on the Pods. Patch-based methods aren't affected.

You can set `live.stormforge.io/apply.method` on individual [namespaces] or [workloads] to use a webhook-based method. For annotation syntax details, see [Apply method][apply-method] in the Apply Settings topic.

[Continuous reconciliation][cont-rec-applier], if enabled, doesn't run for workloads using a webhook-based apply method. Webhook methods set resources when Pods are created, instead of patching workloads continuously.

### Valid values {#pod-mutation-valid-values}

- `true` (default)
- `false`

---

## Namespace allow and deny lists {#namespace-lists}

Limit which namespaces pod mutation applies to.

| Parameter                                                 | Default value |
| --------------------------------------------------------- | ------------- |
| `webhook.handlers.podContainerResources.allowNamespaces`  | `[]`          |
| `webhook.handlers.podContainerResources.denyNamespaces`   | `[]`          |

### Description {#namespace-lists-description}

- To limit pod mutation to specific namespaces, list them in `allowNamespaces`.
- To exclude specific namespaces from mutation, list them in `denyNamespaces`.

Don't set both lists. If you do, installing or upgrading fails.

For workloads in an excluded namespace, see [Pod mutation](#pod-mutation-description).

### Valid values {#namespace-lists-valid-values}

An array of exact namespace names.

### Examples {#namespace-lists-examples}

```yaml
webhook:
  handlers:
    podContainerResources:
      denyNamespaces:
      - kube-system
```

or

```yaml
webhook:
  handlers:
    podContainerResources:
      allowNamespaces:
      - monitoring
      - frontend
```

---

## Failure policy {#failure-policy}

Controls what happens to Pod admission if the webhook is unavailable or returns an error.

| Parameter                                              | Default value |
| ------------------------------------------------------ | ------------- |
| `webhook.handlers.podContainerResources.failurePolicy` | `Ignore`      |

### Description {#failure-policy-description}

`Ignore` (default): If the webhook fails, the admission request proceeds. Pods are created normally, but recommendations aren't applied to them.

`Fail`: If the webhook fails, the admission request is rejected. Use with caution: a webhook outage blocks Pod creation in namespaces covered by pod mutation.

### Valid values {#failure-policy-valid-values}

- `Ignore` (default)
- `Fail`

---

## TLS configuration {#tls}

The API server calls the webhook over TLS, so it needs the CA that signed the webhook's serving certificate. StormForge supports two ways to provide that certificate:

- **Integrated certificates** (default, recommended): StormForge issues and rotates the certificate. Nothing to configure.
- **Your own certificate:** you manage the certificate, through cert-manager or your own CA. See [Use your own TLS certificate](#tls-own-certificate).

With integrated certificates, the webhook Deployment runs a built-in cert-controller. It issues a self-signed CA and serving certificate, rotates them, and updates the CA in the webhook configurations and the CRD conversion settings.

If you install the CRDs outside the chart (`crds.enabled=false`), use your own certificate. The integrated cert-controller only keeps the CA current in CRDs the chart installs. See [CRD conversion](#crd-conversion).

---

## Use your own TLS certificate {#tls-own-certificate}

This section applies only if you manage the webhook certificate yourself. With integrated certificates, skip to [CRD conversion](#crd-conversion).

Choose one option:

- [cert-manager](#tls-cert-manager): cert-manager issues the certificate and keeps the CA current.
- [Certificate from your own CA](#tls-own-ca): you supply the certificate and its CA, for example, from a corporate CA or Vault.

| Parameter                 | Default value |
| ------------------------- | ------------- |
| `webhook.tlsSecretName`   | `""`          |
| `webhook.caBundle`        | `""`          |
| `crds.annotations`        | `{}`          |

### Certificate requirements {#tls-certificate}

Both options set `webhook.tlsSecretName`. This disables the integrated cert-controller and serves that Secret's certificate instead.

The certificate must be issued for the webhook Service's DNS name. For a release named `stormforge` in the `stormforge-system` namespace, that's `stormforge-webhook.stormforge-system.svc`. The name changes with the release name, `nameOverride`, or `fullnameOverride`. Installing or upgrading with `webhook.tlsSecretName` set prints the full list of names the certificate must cover.

If the certificate doesn't match, the API server rejects the connection. With the default [failure policy](#failure-policy) of `Ignore`, Pods are then created without recommended resources, and no error is shown.

The API server also needs the CA that signed the certificate. With cert-manager, its `cert-manager.io/inject-ca-from` annotation supplies it. With your own CA, `webhook.caBundle` supplies it. If the chart finds neither for the pod mutation webhook, the validation webhook, or the CRDs it installs, installing or upgrading fails.

### cert-manager {#tls-cert-manager}

Use this option when cert-manager already runs in your cluster. cert-manager issues the certificate, and its CA injector writes the CA into every webhook configuration and CRD that needs it.

1. Create a cert-manager Certificate in the StormForge namespace. Replace `ISSUER_NAME` with the name of your ClusterIssuer. For a namespaced Issuer, also set `kind: Issuer`.

    ```yaml
    apiVersion: cert-manager.io/v1
    kind: Certificate
    metadata:
      name: stormforge-webhook
      namespace: stormforge-system
    spec:
      secretName: stormforge-webhook-tls
      dnsNames:
      - stormforge-webhook.stormforge-system.svc
      issuerRef:
        name: ISSUER_NAME
        kind: ClusterIssuer
    ```

1. Set `webhook.tlsSecretName` to the Certificate's `secretName`, and add the `cert-manager.io/inject-ca-from` annotation, set to `NAMESPACE/CERTIFICATE_NAME`, to the pod mutation and validation webhooks and the CRDs. Leave `webhook.caBundle` empty.

    ```yaml
    webhook:
      tlsSecretName: stormforge-webhook-tls
      handlers:
        podContainerResources:
          webhookAnnotations:
            cert-manager.io/inject-ca-from: stormforge-system/stormforge-webhook
        optimizationConfiguration:
          webhookAnnotations:
            cert-manager.io/inject-ca-from: stormforge-system/stormforge-webhook
    crds:
      annotations:
        cert-manager.io/inject-ca-from: stormforge-system/stormforge-webhook
    ```

cert-manager renews the certificate and updates the CA without further action.

### Certificate from your own CA {#tls-own-ca}

Use this option when your organization's CA, Vault, or security team issues the certificate, and cert-manager isn't available.

1. Create a `kubernetes.io/tls` Secret containing `tls.crt` and `tls.key` in the StormForge namespace.
1. Set `webhook.tlsSecretName` to the Secret's name, and `webhook.caBundle` to the base64-encoded PEM of the CA that signed `tls.crt`. To encode it, run `base64 < ca.crt | tr -d '\n'`.

    ```yaml
    webhook:
      tlsSecretName: stormforge-webhook-tls
      caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t...
    ```

To renew the serving certificate, update the Secret. The webhook loads the new certificate without a restart. If the CA changes, set the new `webhook.caBundle` and run `helm upgrade`.

`webhook.caBundle` only takes effect when `webhook.tlsSecretName` is also set. Otherwise, the integrated cert-controller replaces it with its own CA.

---

## CRD conversion {#crd-conversion}

The ClusterOptimizationConfiguration and OptimizationConfiguration CRDs serve `optimize.stormforge.io/v1` (deprecated) and `v2`, and store resources as `v2`. When a client uses `v1`, for example, by applying existing `v1` manifests, the API server calls the webhook to convert it. The webhook must stay enabled regardless of how you install the CRDs. To move your manifests to `v2`, see [Migrate from the v1 API](/docs/configure/optimization-configurations/#migrate-from-the-v1-api).

| Parameter        | Default value |
| ---------------- | ------------- |
| `crds.enabled`   | `true`        |

### Description {#crd-conversion-description}

By default, the chart installs the CRDs and configures their conversion settings, including the CA the API server uses to trust the webhook.

If you install the CRDs outside the chart, for example, through GitOps, set `crds.enabled=false`. You then maintain each CRD's conversion settings. The integrated cert-controller only updates CRDs the chart installs, so use [cert-manager](#tls-cert-manager) or a [certificate from your own CA](#tls-own-ca), and put those TLS values in a values file.

1. Render the CRDs from the chart with the same release name, namespace, and values you install with, including any `nameOverride` or `fullnameOverride`. The conversion settings reference the webhook Service by name, so these must match.

    - Replace `CREDENTIAL_FILE` with the name of the file that contains your access credential.
    - Replace `CLUSTER_NAME` with the name of the cluster (lowercase, no underscore) you're installing on.
    - Replace `TLS_VALUES_FILE` with the name of the file that contains your TLS values.

    ```shell
    helm template stormforge oci://registry.stormforge.io/library/stormforge \
      --namespace stormforge-system \
      --values CREDENTIAL_FILE \
      --values TLS_VALUES_FILE \
      --set clusterName=CLUSTER_NAME \
      --set crds.enabled=true \
      --show-only templates/crds/optimize.stormforge.io_clusteroptimizationconfigurations.yaml \
      --show-only templates/crds/optimize.stormforge.io_optimizationconfigurations.yaml
    ```

    With cert-manager, the rendered CRDs carry the `cert-manager.io/inject-ca-from` annotation and cert-manager fills in the CA. With your own CA, they already contain it.

1. Apply the rendered CRDs with your usual tooling.
1. Install the chart with `crds.enabled=false` and the same TLS values file.

If your own CA changes, render and apply the CRDs again with the new `webhook.caBundle`.

### Valid values {#crd-conversion-valid-values}

- `true` (default)
- `false`

---

## Deprecated parameter names {#deprecated}

These parameters moved under `webhook.handlers.podContainerResources` and are deprecated. The old names still work and take precedence if both are set.

| Deprecated                     | Replacement                                                  |
| ------------------------------ | ------------------------------------------------------------ |
| `webhook.failurePolicy`        | `webhook.handlers.podContainerResources.failurePolicy`       |
| `webhook.allowNamespaces`      | `webhook.handlers.podContainerResources.allowNamespaces`     |
| `webhook.denyNamespaces`       | `webhook.handlers.podContainerResources.denyNamespaces`      |
| `webhook.webhookAnnotations`   | `webhook.handlers.podContainerResources.webhookAnnotations`  |

## Related topics

- [Applier configuration](/docs/installation/applier-config/)
- [Apply settings](/docs/configure/settings/apply-settings/)
- [Configure optimization using CRDs](/docs/configure/optimization-configurations/)

[apply-method]: /docs/configure/settings/apply-settings/#apply-method
[namespaces]: /docs/configure/annotate-namespaces/
[workloads]: /docs/configure/annotate-workloads/
[cont-rec-applier]: /docs/installation/applier-config/#continuous-rec
