Skip to content

refactor(operator-web): drop the preview marker from conversion webhooks - #1358

Merged
kimpenhaus merged 1 commit into
mainfrom
refactor/stable-conversion-webhooks
Nov 28, 2026
Merged

kimpenhaus merged 1 commit into
mainfrom
refactor/stable-conversion-webhooks

Conversation

@kimpenhaus

Copy link
Copy Markdown
Collaborator

Summary

Since #639 (v8.0.0), the conversion webhook API (ConversionWebhook<TEntity>, IEntityConverter, the review types)
carried [RequiresPreviewFeatures]. It is a stability marker of KubeOps, not a .NET preview feature: #639 used it to
allow breaking changes outside major versions. The API has been in use unchanged for three years, and KubeOps follows
semantic versioning, so the marker only costs users an opt-in (EnablePreviewFeatures or [RequiresPreviewFeatures]
on their own webhooks, otherwise CA2252 fails the build).

  • Removed the attribute from src/KubeOps.Operator.Web/Webhooks/Conversion, the CA2252 suppressions in
    WebhookLoader and the CLI, and EnablePreviewFeatures from the CLI, the tests and the example.
  • Docs: removed the preview warnings from webhooks.mdx and the package README; one line in migration.mdx.

Not breaking: an existing opt-in in a user project keeps compiling.

Note: #1357 adds a conversion webhook with [RequiresPreviewFeatures] to the CLI test operator; whichever PR is
merged second, the attribute is removed there afterwards.

Checks

  • /code-review (medium): no bugs; Release build of the solution without warnings on net10.0 and net11.0.
  • /simplify: no leftover references in src, test, examples, docs, generator or templates.
  • /security-review: not applicable, only compile-time markers are removed.
  • dotnet format --verify-no-changes; unit tests pass: KubeOps.Operator.Web.Test (172), KubeOps.Cli.Test (100),
    KubeOps.Generator.Test (124), KubeOps.Abstractions.Test (330).

The conversion webhook API carried [RequiresPreviewFeatures] since its
introduction as a stability marker of KubeOps itself, not because of a
.NET preview feature. It has been in use unchanged for three years, and
breaking changes follow semantic versioning anyway. Users no longer
need EnablePreviewFeatures or [RequiresPreviewFeatures] for it.
@kimpenhaus
kimpenhaus enabled auto-merge (squash) November 28, 2026 23:45
@kimpenhaus
kimpenhaus merged commit 905d467 into main Nov 28, 2026
7 checks passed
@kimpenhaus
kimpenhaus deleted the refactor/stable-conversion-webhooks branch November 28, 2026 23:47
kimpenhaus added a commit that referenced this pull request Nov 28, 2026
## Summary

`kubeops generate operator` produced an unusable conversion webhook for
CRDs with a `[ConversionWebhook]`. Checked
against Kubernetes 1.36 (OrbStack) with
`examples/ConversionWebhookOperator`:

| Generated CRD | Result |
| --- | --- |
| before: `service: { name: service }` (no namespace) | the API server
rejects the CRD: `spec.conversion.webhookClientConfig.service.name:
Required value` (the namespace is missing) |
| only `name: operator` | `service "operator" not found`: kustomize
prefixes the service to `<name>-operator`, but does not rename a service
reference in a CRD |
| `name: <name>-operator`, `namespace: <name>-system` | conversion v1 ↔
v3 works |

Changes:

- **CRD** (`CrdGenerator`): the conversion webhook points at the
`operator` service in the operator namespace
(`--namespace` or `<name>-system`); kustomize replaces the namespace
with the one of the kustomization.
- **`kustomizeconfig.yaml`** (new `KustomizeConfigGenerator`): a
`nameReference` from `Service` to
`spec/conversion/webhook/clientConfig/service/name` of
`CustomResourceDefinition`, listed under `configurations` in
the `kustomization.yaml` (as kubebuilder does). Kustomize renames this
reference for validation and mutation
webhooks on its own, but not for CRDs. Only generated when a conversion
webhook exists; written with LF.
- **`KustomizationConfig.Configurations`** (KubeOps.Abstractions): new
nullable property, additive.
- **Webhook deployment**: no longer sets `hostPort: 5001`. It came in
with #976 (v9.11.9), where
`new(5001, name: "https")` (the `containerPort`) became `HostPort =
5001`; #1061 added `ContainerPort` but kept it.
With it, a rolling update cannot start the new pod on the node of the
old one (seen in OrbStack), and at most one
pod runs per node. The service reaches the pod through `targetPort:
https`. Anyone who reached the webhook through
  `<node-ip>:5001` loses that.
- The service name `operator` is a shared constant
(`WebhookDeploymentGenerator.ServiceName`) for the service, the
  webhook configurations and the CRD.

Tests: the CLI test operator had no conversion webhook, which is why
`Should_Generate_Installer_The_Api_Server_Accepts`
(server dry run) never saw such a CRD. It now has a `v2` version with a
conversion webhook (same CRD).
`Should_Point_Webhooks_At_The_Generated_Service` checks that the
rendered CRD points at the rendered service and
namespace, `Should_Wire_The_Generated_Deployment` that no port has a
`hostPort`.

Docs: `cli.mdx` says to apply the manifests with `kubectl apply -k`.

Rebased onto #1358: the test conversion webhook no longer needs
`[RequiresPreviewFeatures]`.

## Checks

- `/code-review` (medium): no blocking bug. Fixed: the test converter
sets `apiVersion`/`kind` (the test entities are
not partial); `kustomizeconfig.yaml` with LF; docs on applying CRD files
without kustomize; `hostPort` removal noted
here. Not part of this PR (pre-existing): a `[ConversionWebhook(group,
plural)]` with an own route is not reflected
  in the CRD path.
- `/simplify`: shared constant for the service name; one `CrdGenerator`
call instead of two.
- `/security-review`: no findings; dropping the `hostPort` no longer
binds the webhook port on the node.
- `dotnet build -c Release` without warnings, `dotnet format
--verify-no-changes`, `KubeOps.Cli.Test` unit tests (100)
  and integration tests (8 per TFM) against OrbStack pass.
- End-to-end test in OrbStack: see comment below.
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 15.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant