Skip to content

Commit

Permalink
Split apart defaulting and validation webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor committed Nov 6, 2019
1 parent 2776fb0 commit a650b1a
Show file tree
Hide file tree
Showing 41 changed files with 602 additions and 2,035 deletions.
7 changes: 3 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ required = [

[[override]]
name = "knative.dev/pkg"
branch = "master"
#TODO(mattmoor): DO NOT SUBMIT
source = "github.com/mattmoor/pkg-1"
revision = "3f9bcd4d73fb89a1976eed9d7a5c6dd023435e3f"
# branch = "master"

[[constraint]]
name = "knative.dev/caching"
Expand Down
86 changes: 55 additions & 31 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"knative.dev/pkg/webhook/certificates"
"knative.dev/pkg/webhook/configmaps"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/defaulting"
"knative.dev/pkg/webhook/resourcesemantics/validation"

// resource validation types
autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1"
Expand All @@ -51,49 +53,70 @@ import (
domainconfig "knative.dev/serving/pkg/reconciler/route/config"
)

func NewResourceAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
v1alpha1.SchemeGroupVersion.WithKind("Revision"): &v1alpha1.Revision{},
v1alpha1.SchemeGroupVersion.WithKind("Configuration"): &v1alpha1.Configuration{},
v1alpha1.SchemeGroupVersion.WithKind("Route"): &v1alpha1.Route{},
v1alpha1.SchemeGroupVersion.WithKind("Service"): &v1alpha1.Service{},
v1beta1.SchemeGroupVersion.WithKind("Revision"): &v1beta1.Revision{},
v1beta1.SchemeGroupVersion.WithKind("Configuration"): &v1beta1.Configuration{},
v1beta1.SchemeGroupVersion.WithKind("Route"): &v1beta1.Route{},
v1beta1.SchemeGroupVersion.WithKind("Service"): &v1beta1.Service{},
v1.SchemeGroupVersion.WithKind("Revision"): &v1.Revision{},
v1.SchemeGroupVersion.WithKind("Configuration"): &v1.Configuration{},
v1.SchemeGroupVersion.WithKind("Route"): &v1.Route{},
v1.SchemeGroupVersion.WithKind("Service"): &v1.Service{},

autoscalingv1alpha1.SchemeGroupVersion.WithKind("PodAutoscaler"): &autoscalingv1alpha1.PodAutoscaler{},
autoscalingv1alpha1.SchemeGroupVersion.WithKind("Metric"): &autoscalingv1alpha1.Metric{},

net.SchemeGroupVersion.WithKind("Certificate"): &net.Certificate{},
net.SchemeGroupVersion.WithKind("Ingress"): &net.Ingress{},
net.SchemeGroupVersion.WithKind("ServerlessService"): &net.ServerlessService{},
}

func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
// Decorate contexts with the current state of the config.
store := defaultconfig.NewStore(logging.FromContext(ctx).Named("config-store"))
store.WatchConfigs(cmw)
ctxFunc := func(ctx context.Context) context.Context {
return v1.WithUpgradeViaDefaulting(store.ToContext(ctx))
}

return resourcesemantics.NewAdmissionController(ctx,
return defaulting.NewAdmissionController(ctx,

// Name of the resource webhook.
// TODO(mattmoor): This can be changed after 0.10, once the lifecycle of
// this object is not managed by OwnerReferences.
"webhook.serving.knative.dev",
"defaulting.webhook.serving.knative.dev",

// The path on which to serve the webhook.
"/",
"/defaulting",

// The resources to validate and default.
map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
v1alpha1.SchemeGroupVersion.WithKind("Revision"): &v1alpha1.Revision{},
v1alpha1.SchemeGroupVersion.WithKind("Configuration"): &v1alpha1.Configuration{},
v1alpha1.SchemeGroupVersion.WithKind("Route"): &v1alpha1.Route{},
v1alpha1.SchemeGroupVersion.WithKind("Service"): &v1alpha1.Service{},
v1beta1.SchemeGroupVersion.WithKind("Revision"): &v1beta1.Revision{},
v1beta1.SchemeGroupVersion.WithKind("Configuration"): &v1beta1.Configuration{},
v1beta1.SchemeGroupVersion.WithKind("Route"): &v1beta1.Route{},
v1beta1.SchemeGroupVersion.WithKind("Service"): &v1beta1.Service{},
v1.SchemeGroupVersion.WithKind("Revision"): &v1.Revision{},
v1.SchemeGroupVersion.WithKind("Configuration"): &v1.Configuration{},
v1.SchemeGroupVersion.WithKind("Route"): &v1.Route{},
v1.SchemeGroupVersion.WithKind("Service"): &v1.Service{},

autoscalingv1alpha1.SchemeGroupVersion.WithKind("PodAutoscaler"): &autoscalingv1alpha1.PodAutoscaler{},
autoscalingv1alpha1.SchemeGroupVersion.WithKind("Metric"): &autoscalingv1alpha1.Metric{},

net.SchemeGroupVersion.WithKind("Certificate"): &net.Certificate{},
net.SchemeGroupVersion.WithKind("Ingress"): &net.Ingress{},
net.SchemeGroupVersion.WithKind("ServerlessService"): &net.ServerlessService{},
types,

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
return v1.WithUpgradeViaDefaulting(store.ToContext(ctx))
},

// Whether to disallow unknown fields.
true,
)
}

func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return validation.NewAdmissionController(ctx,

// Name of the resource webhook.
"validation.webhook.serving.knative.dev",

// The path on which to serve the webhook.
"/",

// The resources to validate and default.
types,

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
ctxFunc,
func(ctx context.Context) context.Context {
return ctx
},

// Whether to disallow unknown fields.
true,
Expand Down Expand Up @@ -136,7 +159,8 @@ func main() {

sharedmain.MainWithContext(ctx, "webhook",
certificates.NewController,
NewResourceAdmissionController,
NewDefaultingAdmissionController,
NewValidationAdmissionController,
NewConfigValidationController,
)
}
20 changes: 18 additions & 2 deletions config/500-webhook-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
name: webhook.serving.knative.dev
name: defaulting.webhook.serving.knative.dev
labels:
serving.knative.dev/release: devel
webhooks:
Expand All @@ -26,7 +26,23 @@ webhooks:
name: webhook
namespace: knative-serving
failurePolicy: Fail
name: webhook.serving.knative.dev
name: defaulting.webhook.serving.knative.dev
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: validation.webhook.serving.knative.dev
labels:
serving.knative.dev/release: devel
webhooks:
- admissionReviewVersions:
- v1beta1
clientConfig:
service:
name: webhook
namespace: knative-serving
failurePolicy: Fail
name: validation.webhook.serving.knative.dev
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
Expand Down
56 changes: 0 additions & 56 deletions third_party/VENDOR-LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3938,20 +3938,6 @@ Import: knative.dev/serving/vendor/github.com/go-openapi/swag



===========================================================
Import: knative.dev/serving/vendor/github.com/gobuffalo/envy

The MIT License (MIT)
Copyright (c) 2018 Mark Bates

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



===========================================================
Import: knative.dev/serving/vendor/github.com/gogo/protobuf

Expand Down Expand Up @@ -6008,35 +5994,6 @@ limitations under the License.



===========================================================
Import: knative.dev/serving/vendor/github.com/joho/godotenv

Copyright (c) 2013 John Barton

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




===========================================================
Import: knative.dev/serving/vendor/github.com/json-iterator/go

Expand Down Expand Up @@ -6309,19 +6266,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI



===========================================================
Import: knative.dev/serving/vendor/github.com/markbates/inflect

Copyright (c) 2011 Chris Farmiloe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



===========================================================
Import: knative.dev/serving/vendor/github.com/mattbaird/jsonpatch

Expand Down
1 change: 0 additions & 1 deletion vendor/knative.dev/pkg/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions vendor/knative.dev/pkg/OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ aliases:
- vaikas-google
- vaikas

cloudevents-approvers:
- n3wscott
- vaikas-google
- vaikas

configmap-approvers:
- mattmoor
- mdemirhan
Expand Down
10 changes: 10 additions & 0 deletions vendor/knative.dev/pkg/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@ their own release branches, so to update the `knative/pkg` dependency we run:
dep ensure -update knative.dev/pkg
./hack/update-deps.sh
```

## Revert to Master

Post release, reverse the process. `Gopkg.toml` should look like:

```toml
[[override]]
name = "knative.dev/pkg"
branch = "master"
```
6 changes: 1 addition & 5 deletions vendor/knative.dev/pkg/apis/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ type Convertible interface {
// Immutable indicates that a particular type has fields that should
// not change after creation.
// DEPRECATED: Use WithinUpdate / GetBaseline from within Validatable instead.
type Immutable interface {
// CheckImmutableFields checks that the current instance's immutable
// fields haven't changed from the provided original.
CheckImmutableFields(ctx context.Context, original Immutable) *FieldError
}
type Immutable interface{}

// Listable indicates that a particular type can be returned via the returned
// list type by the API server.
Expand Down
Loading

0 comments on commit a650b1a

Please sign in to comment.