Skip to content

Commit 49c661c

Browse files
committed
disable the service webhook for classic clusters
* Accomplished by adding a ClassicEnabled configuration option to each webhook Signed-off-by: Michael Shen <[email protected]>
1 parent fb355b0 commit 49c661c

File tree

23 files changed

+50
-36
lines changed

23 files changed

+50
-36
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ type Webhook interface {
8282
// SyncSetLabelSelector returns the label selector to use in the SyncSet.
8383
// Return utils.DefaultLabelSelector() to stick with the default
8484
SyncSetLabelSelector() metav1.LabelSelector
85-
// HypershiftEnabled will return boolean value for hypershift enabled configurations
85+
// ClassicEnabled will return true if the webhook should be deployed to OSD/ROSA Classic clusters
86+
ClassicEnabled() bool
87+
// HypershiftEnabled will return true if the webhook should be deployed to ROSA HCP clusters
8688
HypershiftEnabled() bool
8789
}
8890
```
@@ -117,7 +119,7 @@ The [utils package](pkg/webhooks/utils/utils.go) provides a string slice content
117119

118120
### Mutating Webhooks
119121

120-
Despite its name, this repository has basic support for deploying mutating webhooks alongside validating ones due to their similarity. The differences between the two webhook types boil down to the types of decisions (`Response`s) they're allowed to return to the API server. Just like validating webhooks, mutating webhooks can decide that a request is `Allowed`, `Denied`, or `Errored` (see *[Building a Response](#building-a-response)* below). Unlike validating webhooks, however, mutating webhooks may instead decide that a request can be allowed only if some changes are made (i.e., `Patched`). `Patched` decisions contain a RFC 6902 ([JSONPatch](https://jsonpatch.com/)) string that describes the necessary mutations.
122+
Despite its name, this repository has basic support for deploying mutating webhooks alongside validating ones due to their similarity. The differences between the two webhook types boil down to the types of decisions (`Response`s) they're allowed to return to the API server. Just like validating webhooks, mutating webhooks can decide that a request is `Allowed`, `Denied`, or `Errored` (see *[Building a Response](#building-a-response)* below). Unlike validating webhooks, however, mutating webhooks may instead decide that a request can be allowed only if some changes are made (i.e., `Patched`). `Patched` decisions contain a RFC 6902 ([JSONPatch](https://jsonpatch.com/)) string that describes the necessary mutations.
121123

122124
For example, the [service-mutation webhook](pkg/webhooks/service/service.go) enforces an AWS managed policy requirement that ELBs are tagged with `red-hat-managed=true` by mutating all CREATE and UPDATE operations on LoadBalancer-type `Services` such that they contain the annotation `service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags: red-hat-managed=true`. For a CREATE operation on a `Service` that's missing the necessary annotation, the JSONPatch embedded within the `Patched` Response might look like:
123125

build/resources.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,10 @@ func main() {
806806
}
807807
seen[hook().GetURI()] = true
808808

809+
if !hook().ClassicEnabled() {
810+
continue
811+
}
812+
809813
// no rules...?
810814
if len(hook().Rules()) == 0 {
811815
continue

build/selectorsyncset.yaml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -721,37 +721,6 @@ objects:
721721
scope: Cluster
722722
sideEffects: None
723723
timeoutSeconds: 2
724-
- apiVersion: admissionregistration.k8s.io/v1
725-
kind: MutatingWebhookConfiguration
726-
metadata:
727-
annotations:
728-
service.beta.openshift.io/inject-cabundle: "true"
729-
creationTimestamp: null
730-
name: sre-service-mutation
731-
webhooks:
732-
- admissionReviewVersions:
733-
- v1
734-
clientConfig:
735-
service:
736-
name: validation-webhook
737-
namespace: openshift-validation-webhook
738-
path: /service-mutation
739-
failurePolicy: Ignore
740-
matchPolicy: Equivalent
741-
name: service-mutation.managed.openshift.io
742-
rules:
743-
- apiGroups:
744-
- ""
745-
apiVersions:
746-
- v1
747-
operations:
748-
- CREATE
749-
- UPDATE
750-
resources:
751-
- services
752-
scope: Namespaced
753-
sideEffects: None
754-
timeoutSeconds: 2
755724
- apiVersion: admissionregistration.k8s.io/v1
756725
kind: ValidatingWebhookConfiguration
757726
metadata:

pkg/config/namespaces.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/webhooks/clusterlogging/clusterlogging.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ func (s *ClusterloggingWebhook) SyncSetLabelSelector() metav1.LabelSelector {
281281
return customLabelSelector
282282
}
283283

284+
func (s *ClusterloggingWebhook) ClassicEnabled() bool { return true }
285+
284286
func (s *ClusterloggingWebhook) HypershiftEnabled() bool { return false }
285287

286288
// NewWebhook creates a new webhook

pkg/webhooks/clusterrolebinding/clusterrolebinding.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,6 @@ func (s *ClusterRoleBindingWebHook) SyncSetLabelSelector() metav1.LabelSelector
243243
return utils.DefaultLabelSelector()
244244
}
245245

246+
func (s *ClusterRoleBindingWebHook) ClassicEnabled() bool { return true }
247+
246248
func (s *ClusterRoleBindingWebHook) HypershiftEnabled() bool { return true }

pkg/webhooks/customresourcedefinitions/customresourcedefinitions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,6 @@ func (s *customresourcedefinitionsruleWebhook) SyncSetLabelSelector() metav1.Lab
193193
return utils.DefaultLabelSelector()
194194
}
195195

196+
func (s *customresourcedefinitionsruleWebhook) ClassicEnabled() bool { return true }
197+
196198
func (s *customresourcedefinitionsruleWebhook) HypershiftEnabled() bool { return false }

pkg/webhooks/hiveownership/hiveownership.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ func (s *HiveOwnershipWebhook) SyncSetLabelSelector() metav1.LabelSelector {
130130
return utils.DefaultLabelSelector()
131131
}
132132

133+
func (s *HiveOwnershipWebhook) ClassicEnabled() bool { return true }
134+
133135
func (s *HiveOwnershipWebhook) HypershiftEnabled() bool { return false }
134136

135137
// NewWebhook creates a new webhook

pkg/webhooks/imagecontentpolicies/imagecontentpolicies.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ func (w *ImageContentPoliciesWebhook) SyncSetLabelSelector() metav1.LabelSelecto
165165
return utils.DefaultLabelSelector()
166166
}
167167

168+
func (w *ImageContentPoliciesWebhook) ClassicEnabled() bool {
169+
return true
170+
}
171+
168172
func (w *ImageContentPoliciesWebhook) HypershiftEnabled() bool {
169173
return true
170174
}

pkg/webhooks/ingressconfig/ingressconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func (w *IngressConfigWebhook) SyncSetLabelSelector() metav1.LabelSelector {
122122
return utils.DefaultLabelSelector()
123123
}
124124

125+
func (w *IngressConfigWebhook) ClassicEnabled() bool { return true }
126+
125127
// HypershiftEnabled will return boolean value for hypershift enabled configurations
126128
func (w *IngressConfigWebhook) HypershiftEnabled() bool { return true }
127129

0 commit comments

Comments
 (0)