Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit c913f4e

Browse files
committed
Create webhook without rules by patch
1 parent cc462da commit c913f4e

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

config/webhook/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ resources:
44

55
configurations:
66
- kustomizeconfig.yaml
7+
8+
patchesStrategicMerge:
9+
- webhook_patch.yaml

config/webhook/manifests.yaml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,6 @@ webhooks:
7171
resources:
7272
- hierarchyconfigurations
7373
sideEffects: None
74-
- admissionReviewVersions:
75-
- v1
76-
clientConfig:
77-
service:
78-
name: webhook-service
79-
namespace: system
80-
path: /validate-objects
81-
failurePolicy: Fail
82-
name: objects.hnc.x-k8s.io
83-
rules:
84-
- apiGroups:
85-
- rbac.authorization.k8s.io
86-
apiVersions:
87-
- '*'
88-
operations:
89-
- CREATE
90-
- UPDATE
91-
- DELETE
92-
resources:
93-
- roles
94-
- rolebindings
95-
sideEffects: None
9674
- admissionReviewVersions:
9775
- v1
9876
clientConfig:

config/webhook/webhook_patch.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
apiVersion: admissionregistration.k8s.io/v1
3+
kind: ValidatingWebhookConfiguration
4+
metadata:
5+
name: validating-webhook-configuration
6+
webhooks:
7+
- admissionReviewVersions:
8+
- v1
9+
clientConfig:
10+
service:
11+
name: webhook-service
12+
namespace: system
13+
path: /validate-objects
14+
failurePolicy: Fail
15+
name: objects.hnc.x-k8s.io
16+
# Intentionally no rules, as these are maintained by the HNCConfiguration reconciler
17+
sideEffects: None
18+
timeoutSeconds: 2
19+
# We only apply this object validator on non-excluded namespaces, which have
20+
# the "included-namespace" label set by the HC reconciler, so that when HNC
21+
# (webhook service specifically) is down, operations in the excluded
22+
# namespaces won't be affected. Validators on HNC CRs are not filtered because
23+
# they are supposed to prevent abuse of HNC CRs in excluded namespaces.
24+
# Namespace validator is not filtered to prevent abuse of the included-namespace
25+
# label on excluded namespaces. Unfortunately, this means that when HNC is
26+
# down, we will block updates on all namespaces, even "excluded" ones, but
27+
# anyone who can update namespaces like `kube-system` should likely be able to
28+
# delete the VWHConfiguration to make the updates.
29+
namespaceSelector:
30+
matchLabels:
31+
hnc.x-k8s.io/included-namespace: "true"

internal/objects/validator.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ const (
3232
ServingPath = "/validate-objects"
3333
)
3434

35-
// Note: the validating webhook FAILS CLOSE. This means that if the webhook goes
36-
// down, all further changes are forbidden. The initial webhook configuration contains
37-
// just enforced types, and will be dynamically updated when reconciling the HNC configuration.
38-
//
39-
// +kubebuilder:webhook:admissionReviewVersions=v1,path=/validate-objects,mutating=false,failurePolicy=fail,groups="rbac.authorization.k8s.io",resources=roles;rolebindings,sideEffects=None,verbs=create;update;delete,versions="*",name=objects.hnc.x-k8s.io
40-
4135
type Validator struct {
4236
Log logr.Logger
4337
Forest *forest.Forest

0 commit comments

Comments
 (0)