Skip to content

[feature]: Add extension points for customizing generated resources #1114

Closed

Description

@BalassaMarton

Is your feature request related to a problem? Please describe.

Several internal components hardcode the construction of Kubernetes resources, making it impossible for users to customize the shape of these resources without replacing entire subsystems:

  • CrdInstaller hardcodes V1CustomResourceDefinition generation via the transpiler
  • KubeOpsEventPublisherFactory.Create() hardcodes Corev1Event construction inline
  • WebhookServiceBase hardcodes V1MutatingWebhookConfiguration and V1ValidatingWebhookConfiguration construction

For example, a user who needs to add custom labels to webhook configurations, set a specific failurePolicy, or modify CRD metadata before installation has no extension point — they must fork or replace the entire hosting service.

Describe the solution you would like

Extract resource-building logic into public interfaces in KubeOps.Abstractions, with default implementations registered via TryAdd in DI. This follows the existing IEventPublisherFactory pattern and lets users register their own implementation before calling the operator builder to win. The default implementation for these abstractions should be public classes with virtual methods. The typical customization workflow would be to derive from the default implementation.

Three new interfaces:

  1. ICrdResourceFactory (KubeOps.Abstractions.Crds) — V1CustomResourceDefinition CreateCrd(Type entityType). The default implementation calls the static Transpile method, CrdGenerator takes ICrdResourceFactory via constructor injection and invokes it where it previously invoked Transpile.

  2. IEventResourceFactory (KubeOps.Abstractions.Events) — Corev1Event CreateEvent(IKubernetesObject<V1ObjectMeta> entity, string reason, string message, EventType type). Default implementation moves the Corev1Event construction out of KubeOpsEventPublisherFactory. The existing IEventPublisherFactory remains as the coarse-grained override; this is the fine-grained hook for just the resource shape without reimplementing the fetch/save lifecycle.

  3. IWebhookConfigurationFactory (KubeOps.Abstractions.Webhooks) — two methods: CreateMutatingConfiguration(...) and CreateValidatingConfiguration(...), accepting typed registration DTOs (MutatingWebhookRegistration / ValidatingWebhookRegistration carrying entity metadata, hook type name, base URI, CA bundle). The default implementation moves the LINQ pipelines out of WebhookServiceBase.RegisterMutators() / RegisterValidators(). Conversion webhook registration (RegisterConverters) is excluded since it patches existing CRDs rather than creating standalone configuration objects.

All defaults should be registered with TryAddSingleton / TryAddTransient so that user-registered implementations win.

Additional Context

This is a non-breaking change: default implementations preserve current behavior exactly, all existing tests should pass unchanged.
The pattern is already established in the codebase — IEventPublisherFactory is registered with TryAddTransient in OperatorBuilder and is fully replaceable. This proposal extends the same idiom to the remaining resource-generating components.
Actual use cases for this feature:

  • Deploying the same operator in different namespaces.
  • Adding custom metadata to the resources created.
  • Improving developer workflows, especially when switching between local cluster vs shared development cluster.

Activity

  1. added
    enhancement
    on May 11, 2026
  2. BalassaMarton commented on May 12, 2026

    @BalassaMarton
    ContributorAuthor

    I edited the ICrdResourceFactory interface so that it doesn't add System.Reflection.MetadataLoadContext to the dependencies of the Abstractions package. My PR is underway.

  3. added a commit that references this issue on May 21, 2026
    199e8ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions