Skip to content

fix(cli): point the conversion webhook at the operator service - #1357

Merged
kimpenhaus merged 3 commits into
mainfrom
fix/cli-conversion-webhook
Nov 28, 2026
Merged

kimpenhaus merged 3 commits into
mainfrom
fix/cli-conversion-webhook

Conversation

@kimpenhaus

@kimpenhaus kimpenhaus commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

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 chore(deps): updated k8s KubernetesClient to v18.0.5 #976 (v9.11.9), where
    new(5001, name: "https") (the containerPort) became HostPort = 5001; fix: webhook name generation for resources without a group and missing container port in webhook deployment generation #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.

@kimpenhaus

Copy link
Copy Markdown
Collaborator Author

End-to-end test in OrbStack (Kubernetes v1.36.5)

examples/ConversionWebhookOperator (v1, v2, v3 with v3 as storage version), manifests from this branch, without
manual changes:

kubeops generate operator conv-test examples/ConversionWebhookOperator/ConversionWebhookOperator.csproj \
  --out ./final --docker-image conversion-webhook-operator --docker-image-tag test
kubectl apply -k ./final
  • kubectl apply -k creates all resources, including the CRD (before: rejected with service.name: Required value).
  • Conversion webhook in the CRD: {"name":"conv-test-operator","namespace":"conv-test-system","path":"/convert/conversionwebhook.dev/testentitys","port":443}.
  • Container ports: [{"containerPort":5001,"name":"https","protocol":"TCP"}], no hostPort.
  • A v1 entity {"name":"Max Mustermann"} reads as v2/v3 {"firstname":"Max","lastname":"Mustermann"}; a v2 entity reads
    as v1 {"name":"Erika Musterfrau"}.
  • kubectl rollout restart completes without intervention (before: the new pod stayed Pending because of the host
    port until the old one was deleted).

Not part of this PR: for about 5 seconds right after the rollout, a conversion failed with EOF. The generated
deployment has no readiness probe, so the new pod counts as ready before Kestrel listens while the old one
terminates. This belongs to the existing roadmap item for probes in the generated deployment.

@kimpenhaus
kimpenhaus marked this pull request as ready for review November 28, 2026 23:41
kimpenhaus added a commit that referenced this pull request Nov 28, 2026
…oks (#1358)

## 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 generated CRD pointed its conversion webhook at the service
"service" without a namespace, so the API server rejected the CRD.
It now points at the operator service in the operator namespace, and
the CLI generates a kustomizeconfig.yaml with a name reference, as
kustomize does not rename a service reference in a CRD on its own.

The webhook deployment no longer sets hostPort 5001, which kept a
rolling update from starting the new pod on the node of the old one.
@kimpenhaus
kimpenhaus force-pushed the fix/cli-conversion-webhook branch from 5fa0870 to ab4ed85 Compare November 28, 2026 23:51
@kimpenhaus
kimpenhaus enabled auto-merge (squash) November 28, 2026 23:52
@kimpenhaus
kimpenhaus merged commit ef0500c into main Nov 28, 2026
7 of 9 checks passed
@kimpenhaus
kimpenhaus deleted the fix/cli-conversion-webhook branch November 28, 2026 23:59
@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