Skip to content

Comments

Scope StatefulSet mutating webhook to MOCO resources#882

Open
arosh wants to merge 2 commits intomainfrom
statefulset-mutating-webhook
Open

Scope StatefulSet mutating webhook to MOCO resources#882
arosh wants to merge 2 commits intomainfrom
statefulset-mutating-webhook

Conversation

@arosh
Copy link
Member

@arosh arosh commented Feb 12, 2026

Summary

Add a Kustomize patch that applies an objectSelector to the StatefulSet mutating webhook, so only MOCO-created StatefulSets are targeted and non-MOCO users are unaffected.

Background

The StatefulSet mutating webhook currently applies cluster-wide. As mentioned at https://habr.com/ru/companies/flant/articles/969520/, if the MOCO webhook is unavailable, it can impact unrelated StatefulSet operations. We want to limit the webhook to MOCO-managed resources .

Changes

  • Add a strategic merge patch that sets objectSelector with app.kubernetes.io/created-by=moco on the StatefulSet mutating webhook.
  • Wire the patch into the webhook kustomization so the selector is applied during manifest build.

Notes

Currently, controller-gen's +kubebuilder:webhook marker does not support setting an objectSelector. That is why we add objectSelector as a Kustomize patch. See kubernetes-sigs/controller-tools#553

@arosh arosh marked this pull request as ready for review February 12, 2026 08:41
@arosh arosh requested a review from Copilot February 12, 2026 08:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Scopes the StatefulSet mutating webhook to MOCO-managed StatefulSets by applying an objectSelector, reducing blast radius when the webhook is unavailable.

Changes:

  • Add a strategic merge patch to set objectSelector.matchLabels on the StatefulSet mutating webhook.
  • Wire the patch into config/webhook/kustomization.yaml so it’s applied during manifest generation.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
config/webhook/patches/statefulset_webhook_objectselector.yaml Adds an objectSelector to limit which StatefulSets the mutating webhook applies to.
config/webhook/kustomization.yaml Applies the new patch during Kustomize builds of webhook manifests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +7
patchesStrategicMerge:
- patches/statefulset_webhook_objectselector.yaml
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patchesStrategicMerge is the legacy Kustomize mechanism and is discouraged in favor of patches with an explicit target (kind/name/field selectors), which tends to be clearer and more robust as configurations evolve. Consider switching to patches: with a target that selects kind: MutatingWebhookConfiguration and name: mutating-webhook-configuration.

Suggested change
patchesStrategicMerge:
- patches/statefulset_webhook_objectselector.yaml
patches:
- path: patches/statefulset_webhook_objectselector.yaml
target:
kind: MutatingWebhookConfiguration
name: mutating-webhook-configuration

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this project uses legacy patchesStrategicMerge. I have a plan to create a PR that apply kustomize edit fix after this PR.

@arosh arosh force-pushed the statefulset-mutating-webhook branch from 4c0897b to 2678da3 Compare February 13, 2026 07:20
Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
…ctory to avoid WebhookInstallOptions.Paths

Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
@arosh arosh force-pushed the statefulset-mutating-webhook branch from 2678da3 to 0935992 Compare February 16, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant