From d573012d1e85e526a5e4233472b7d477cf44b4e2 Mon Sep 17 00:00:00 2001 From: Stavros Kontopoulos Date: Fri, 7 Jul 2023 00:12:13 +0300 Subject: [PATCH] merge types, clean up webhook configs --- cmd/webhook/main.go | 62 +------------------ config/core/webhooks/defaulting.yaml | 2 + .../webhooks/domainmapping-defaulting.yaml | 44 ------------- .../webhooks/domainmapping-validation.yaml | 45 -------------- config/core/webhooks/resource-validation.yaml | 2 + 5 files changed, 6 insertions(+), 149 deletions(-) delete mode 100644 config/core/webhooks/domainmapping-defaulting.yaml delete mode 100644 config/core/webhooks/domainmapping-validation.yaml diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index b41af0d2ea80..95041751e84b 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -19,10 +19,6 @@ package main import ( "context" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - servingv1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1" - domainmappingconfig "knative.dev/serving/pkg/reconciler/domainmapping/config" - "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" @@ -37,6 +33,8 @@ import ( "knative.dev/pkg/webhook/resourcesemantics" "knative.dev/pkg/webhook/resourcesemantics/defaulting" "knative.dev/pkg/webhook/resourcesemantics/validation" + servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" + servingv1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1" // resource validation types net "knative.dev/networking/pkg/apis/networking/v1alpha1" @@ -67,9 +65,7 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ net.SchemeGroupVersion.WithKind("Certificate"): &net.Certificate{}, net.SchemeGroupVersion.WithKind("Ingress"): &net.Ingress{}, net.SchemeGroupVersion.WithKind("ServerlessService"): &net.ServerlessService{}, -} -var domainMappingTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ servingv1alpha1.SchemeGroupVersion.WithKind("DomainMapping"): &servingv1alpha1.DomainMapping{}, servingv1beta1.SchemeGroupVersion.WithKind("DomainMapping"): &servingv1beta1.DomainMapping{}, } @@ -164,58 +160,6 @@ func newConfigValidationController(ctx context.Context, cmw configmap.Watcher) * ) } -func newDefaultingDomainMappingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { - // Decorate contexts with the current state of the config. - store := domainmappingconfig.NewStore(ctx) - store.WatchConfigs(cmw) - ctx = copyAndOverrideWebhookQueueName(ctx, "DefaultingDMWebhook") - - return defaulting.NewAdmissionController(ctx, - - // Name of the resource webhook. - "webhook.domainmapping.serving.knative.dev", - - // The path on which to serve the webhook. - "/defaulting-dm", - - // The resources to default. - domainMappingTypes, - - // A function that infuses the context passed to Validate/SetDefaults with custom metadata. - store.ToContext, - - // Whether to disallow unknown fields. We set this to 'false' since - // our CRDs have schemas - false, - ) -} - -func newValidatingDomainMappingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { - // Decorate contexts with the current state of the config. - store := domainmappingconfig.NewStore(ctx) - store.WatchConfigs(cmw) - ctx = copyAndOverrideWebhookQueueName(ctx, "ValidatingDMWebhook") - - return validation.NewAdmissionController(ctx, - - // Name of the resource webhook. - "validation.webhook.domainmapping.serving.knative.dev", - - // The path on which to serve the webhook. - "/resource-validation-dm", - - // The resources to validate. - domainMappingTypes, - - // A function that infuses the context passed to Validate/SetDefaults with custom metadata. - store.ToContext, - - // Whether to disallow unknown fields. We set this to 'false' since - // our CRDs have schemas - false, - ) -} - func copyAndOverrideWebhookQueueName(ctx context.Context, queueName string) context.Context { cpWopts := *webhook.GetOptions(ctx) if cpWopts.ControllerOptions != nil { @@ -242,9 +186,7 @@ func main() { sharedmain.WebhookMainWithContext(ctx, "webhook", certificates.NewController, newDefaultingAdmissionController, - newDefaultingDomainMappingAdmissionController, newValidationAdmissionController, - newValidatingDomainMappingAdmissionController, newConfigValidationController, ) } diff --git a/config/core/webhooks/defaulting.yaml b/config/core/webhooks/defaulting.yaml index 449df2237182..388a973281f9 100644 --- a/config/core/webhooks/defaulting.yaml +++ b/config/core/webhooks/defaulting.yaml @@ -51,3 +51,5 @@ webhooks: - revisions - routes - services + - domainmappings + - domainmappings/status diff --git a/config/core/webhooks/domainmapping-defaulting.yaml b/config/core/webhooks/domainmapping-defaulting.yaml deleted file mode 100644 index 0d02f6cd9182..000000000000 --- a/config/core/webhooks/domainmapping-defaulting.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2020 The Knative Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: admissionregistration.k8s.io/v1 -kind: MutatingWebhookConfiguration -metadata: - name: webhook.domainmapping.serving.knative.dev - labels: - app.kubernetes.io/component: domain-mapping - app.kubernetes.io/name: knative-serving - app.kubernetes.io/version: devel -webhooks: -- admissionReviewVersions: ["v1", "v1beta1"] - clientConfig: - service: - name: webhook - namespace: knative-serving - failurePolicy: Fail - sideEffects: None - name: webhook.domainmapping.serving.knative.dev - timeoutSeconds: 10 - rules: - - apiGroups: - - serving.knative.dev - apiVersions: - - "*" - operations: - - CREATE - - UPDATE - scope: "*" - resources: - - domainmappings - - domainmappings/status diff --git a/config/core/webhooks/domainmapping-validation.yaml b/config/core/webhooks/domainmapping-validation.yaml deleted file mode 100644 index 0c24cbc2c95b..000000000000 --- a/config/core/webhooks/domainmapping-validation.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2020 The Knative Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: admissionregistration.k8s.io/v1 -kind: ValidatingWebhookConfiguration -metadata: - name: validation.webhook.domainmapping.serving.knative.dev - labels: - app.kubernetes.io/component: domain-mapping - app.kubernetes.io/name: knative-serving - app.kubernetes.io/version: devel -webhooks: -- admissionReviewVersions: ["v1", "v1beta1"] - clientConfig: - service: - name: webhook - namespace: knative-serving - failurePolicy: Fail - sideEffects: None - name: validation.webhook.domainmapping.serving.knative.dev - timeoutSeconds: 10 - rules: - - apiGroups: - - serving.knative.dev - apiVersions: - - "*" - operations: - - CREATE - - UPDATE - - DELETE - scope: "*" - resources: - - domainmappings - - domainmappings/status diff --git a/config/core/webhooks/resource-validation.yaml b/config/core/webhooks/resource-validation.yaml index 8bb0cd09b655..b496654202c8 100644 --- a/config/core/webhooks/resource-validation.yaml +++ b/config/core/webhooks/resource-validation.yaml @@ -52,3 +52,5 @@ webhooks: - revisions - routes - services + - domainmappings + - domainmappings/status