Skip to content

Commit

Permalink
merge types, clean up webhook configs
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Jul 6, 2023
1 parent 6ce5b70 commit d573012
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 149 deletions.
62 changes: 2 additions & 60 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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{},
}
Expand Down Expand Up @@ -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 {

Check failure on line 163 in cmd/webhook/main.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

func `copyAndOverrideWebhookQueueName` is unused (unused)
cpWopts := *webhook.GetOptions(ctx)
if cpWopts.ControllerOptions != nil {
Expand All @@ -242,9 +186,7 @@ func main() {
sharedmain.WebhookMainWithContext(ctx, "webhook",
certificates.NewController,
newDefaultingAdmissionController,
newDefaultingDomainMappingAdmissionController,
newValidationAdmissionController,
newValidatingDomainMappingAdmissionController,
newConfigValidationController,
)
}
2 changes: 2 additions & 0 deletions config/core/webhooks/defaulting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ webhooks:
- revisions
- routes
- services
- domainmappings
- domainmappings/status
44 changes: 0 additions & 44 deletions config/core/webhooks/domainmapping-defaulting.yaml

This file was deleted.

45 changes: 0 additions & 45 deletions config/core/webhooks/domainmapping-validation.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions config/core/webhooks/resource-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ webhooks:
- revisions
- routes
- services
- domainmappings
- domainmappings/status

0 comments on commit d573012

Please sign in to comment.