Adopt custom defaulter and validator interface for webhooks intead of deprecated default (#3152)
* Move webhooks to webhooks package Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * change interface Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Change interface methods Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * comment debug logs for now Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * rename files Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Fix webhook warnings Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Update makefile Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * lint fixes Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> --------- Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var canaryconfiglog = loggerfactory.GetLogger().Named("canaryconfig-resource")
|
||||
|
||||
func (r *CanaryConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-canaryconfig,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=canaryconfigs,verbs=create;update,versions=v1,name=mcanaryconfig.fission.io,admissionReviewVersions=v1
|
||||
// Refer Makefile -> generate-webhooks to generate config for manifests
|
||||
|
||||
var _ webhook.Defaulter = &CanaryConfig{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *CanaryConfig) Default() {
|
||||
canaryconfiglog.Debug("default", zap.String("name", r.Name))
|
||||
}
|
||||
|
||||
// user can change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
// Validation webhooks can be added by adding tag: kubebuilder:webhook:path=/validate-fission-io-v1-canaryconfig,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=canaryconfigs,verbs=create;update,versions=v1,name=vcanaryconfig.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &CanaryConfig{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *CanaryConfig) ValidateCreate() (admission.Warnings, error) {
|
||||
canaryconfiglog.Debug("validate create", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *CanaryConfig) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
canaryconfiglog.Debug("validate update", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *CanaryConfig) ValidateDelete() (admission.Warnings, error) {
|
||||
canaryconfiglog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var environmentlog = loggerfactory.GetLogger().Named("environment-resource")
|
||||
|
||||
func (r *Environment) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-environment,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=environments,verbs=create;update,versions=v1,name=menvironment.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &Environment{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *Environment) Default() {
|
||||
environmentlog.Debug("default", zap.String("name", r.Name))
|
||||
}
|
||||
|
||||
// user: change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-environment,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=environments,verbs=create,versions=v1,name=venvironment.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &Environment{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Environment) ValidateCreate() (admission.Warnings, error) {
|
||||
environmentlog.Debug("validate create", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("Environment", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Environment) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
environmentlog.Debug("validate update", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Environment) ValidateDelete() (admission.Warnings, error) {
|
||||
environmentlog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var functionlog = loggerfactory.GetLogger().Named("function-resource")
|
||||
|
||||
func (r *Function) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-function,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=functions,verbs=create;update,versions=v1,name=mfunction.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &Function{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *Function) Default() {
|
||||
}
|
||||
|
||||
// user change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-function,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=functions,verbs=create;update,versions=v1,name=vfunction.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &Function{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Function) ValidateCreate() (admission.Warnings, error) {
|
||||
functionlog.Debug("validate create", zap.String("name", r.Name))
|
||||
|
||||
for _, cnfMap := range r.Spec.ConfigMaps {
|
||||
if cnfMap.Namespace != r.ObjectMeta.Namespace {
|
||||
err := fmt.Errorf("ConfigMap's [%s] and function's Namespace [%s] are different. ConfigMap needs to be present in the same namespace as function", cnfMap.Namespace, r.ObjectMeta.Namespace)
|
||||
return nil, AggregateValidationErrors("Function", err)
|
||||
}
|
||||
}
|
||||
for _, secret := range r.Spec.Secrets {
|
||||
if secret.Namespace != r.ObjectMeta.Namespace {
|
||||
err := fmt.Errorf("secret [%s] and function's Namespace [%s] are different. Secret needs to be present in the same namespace as function", secret.Namespace, r.ObjectMeta.Namespace)
|
||||
return nil, AggregateValidationErrors("Function", err)
|
||||
}
|
||||
}
|
||||
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
return nil, AggregateValidationErrors("Function", err)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Function) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
functionlog.Debug("validate update", zap.String("name", r.Name))
|
||||
|
||||
for _, cnfMap := range r.Spec.ConfigMaps {
|
||||
if cnfMap.Namespace != r.ObjectMeta.Namespace {
|
||||
err := fmt.Errorf("ConfigMap's [%s] and function's Namespace [%s] are different. ConfigMap needs to be present in the same namespace as function", cnfMap.Namespace, r.ObjectMeta.Namespace)
|
||||
return nil, AggregateValidationErrors("Function", err)
|
||||
}
|
||||
}
|
||||
for _, secret := range r.Spec.Secrets {
|
||||
if secret.Namespace != r.ObjectMeta.Namespace {
|
||||
err := fmt.Errorf("secret [%s] and function's Namespace [%s] are different. Secret needs to be present in the same namespace as function", secret.Namespace, r.ObjectMeta.Namespace)
|
||||
return nil, AggregateValidationErrors("Function", err)
|
||||
}
|
||||
}
|
||||
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
return nil, AggregateValidationErrors("Function", err)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Function) ValidateDelete() (admission.Warnings, error) {
|
||||
functionlog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var httptriggerlog = loggerfactory.GetLogger().Named("httptrigger-resource")
|
||||
|
||||
func (r *HTTPTrigger) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-httptrigger,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=httptriggers,verbs=create;update,versions=v1,name=mhttptrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &HTTPTrigger{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *HTTPTrigger) Default() {
|
||||
httptriggerlog.Debug("default", zap.String("name", r.Name))
|
||||
}
|
||||
|
||||
// user change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-httptrigger,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=httptriggers,verbs=create;update,versions=v1,name=vhttptrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &HTTPTrigger{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (t *HTTPTrigger) ValidateCreate() (admission.Warnings, error) {
|
||||
httptriggerlog.Debug("validate create", zap.String("name", t.Name))
|
||||
err := t.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("HTTPTrigger", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *HTTPTrigger) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
httptriggerlog.Debug("validate update", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("HTTPTrigger", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *HTTPTrigger) ValidateDelete() (admission.Warnings, error) {
|
||||
httptriggerlog.Debug("validate delete", zap.String("name", r.Name))
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var kuberneteswatchtriggerlog = loggerfactory.GetLogger().Named("kuberneteswatchtrigger-resource")
|
||||
|
||||
func (r *KubernetesWatchTrigger) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-kuberneteswatchtrigger,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=kuberneteswatchtriggers,verbs=create;update,versions=v1,name=mkuberneteswatchtrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &KubernetesWatchTrigger{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *KubernetesWatchTrigger) Default() {
|
||||
kuberneteswatchtriggerlog.Debug("default", zap.String("name", r.Name))
|
||||
}
|
||||
|
||||
// user: change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-kuberneteswatchtrigger,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=kuberneteswatchtriggers,verbs=create,versions=v1,name=vkuberneteswatchtrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &KubernetesWatchTrigger{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *KubernetesWatchTrigger) ValidateCreate() (admission.Warnings, error) {
|
||||
kuberneteswatchtriggerlog.Debug("validate create", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("Watch", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *KubernetesWatchTrigger) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
// WATCH UPDATE NOT IMPLEMENTED
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *KubernetesWatchTrigger) ValidateDelete() (admission.Warnings, error) {
|
||||
kuberneteswatchtriggerlog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var messagequeuetriggerlog = loggerfactory.GetLogger().Named("messagequeuetrigger-resource")
|
||||
|
||||
func (r *MessageQueueTrigger) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-messagequeuetrigger,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=messagequeuetriggers,verbs=create;update,versions=v1,name=mmessagequeuetrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &MessageQueueTrigger{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *MessageQueueTrigger) Default() {
|
||||
messagequeuetriggerlog.Debug("default", zap.String("name", r.Name))
|
||||
}
|
||||
|
||||
// user change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-messagequeuetrigger,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=messagequeuetriggers,verbs=create;update,versions=v1,name=vmessagequeuetrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &MessageQueueTrigger{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *MessageQueueTrigger) ValidateCreate() (admission.Warnings, error) {
|
||||
messagequeuetriggerlog.Debug("validate create", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("MessageQueueTrigger", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *MessageQueueTrigger) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
messagequeuetriggerlog.Debug("validate update", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("MessageQueueTrigger", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *MessageQueueTrigger) ValidateDelete() (admission.Warnings, error) {
|
||||
messagequeuetriggerlog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var packagelog = loggerfactory.GetLogger().Named("package-resource")
|
||||
|
||||
func (r *Package) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
//+kubebuilder:webhook:path=/mutate-fission-io-v1-package,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=packages,verbs=create;update,versions=v1,name=mpackage.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &Package{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *Package) Default() {
|
||||
packagelog.Debug("default", zap.String("name", r.Name))
|
||||
if r.Status.BuildStatus == "" {
|
||||
if !r.Spec.Deployment.IsEmpty() {
|
||||
// deployment package exists
|
||||
r.Status.BuildStatus = BuildStatusNone
|
||||
} else if !r.Spec.Source.IsEmpty() {
|
||||
// source package with no deployment is a pending build
|
||||
r.Status.BuildStatus = BuildStatusPending
|
||||
} else {
|
||||
r.Status.BuildStatus = BuildStatusFailed // empty package
|
||||
r.Status.BuildLog = "Both source and deployment are empty"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// user change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-package,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=packages,verbs=create;update,versions=v1,name=vpackage.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &Package{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Package) ValidateCreate() (admission.Warnings, error) {
|
||||
packagelog.Debug("validate create", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("Package", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Ensure size limits
|
||||
if len(r.Spec.Source.Literal) > int(ArchiveLiteralSizeLimit) {
|
||||
err := ferror.MakeError(ferror.ErrorInvalidArgument,
|
||||
fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(ArchiveLiteralSizeLimit))))
|
||||
return nil, err
|
||||
}
|
||||
if len(r.Spec.Deployment.Literal) > int(ArchiveLiteralSizeLimit) {
|
||||
err := ferror.MakeError(ferror.ErrorInvalidArgument,
|
||||
fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(ArchiveLiteralSizeLimit))))
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Package) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
packagelog.Debug("validate update", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("Package", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *Package) ValidateDelete() (admission.Warnings, error) {
|
||||
packagelog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
Copyright 2022.
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
)
|
||||
|
||||
// log is for logging in this package.
|
||||
var timetriggerlog = loggerfactory.GetLogger().Named("timetrigger-resource")
|
||||
|
||||
func (r *TimeTrigger) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewWebhookManagedBy(mgr).
|
||||
For(r).
|
||||
Complete()
|
||||
}
|
||||
|
||||
// Admission webhooks can be added by adding tag: kubebuilder:webhook:path=/mutate-fission-io-v1-timetrigger,mutating=true,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=timetriggers,verbs=create;update,versions=v1,name=mtimetrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Defaulter = &TimeTrigger{}
|
||||
|
||||
// Default implements webhook.Defaulter so a webhook will be registered for the type
|
||||
func (r *TimeTrigger) Default() {
|
||||
timetriggerlog.Debug("default", zap.String("name", r.Name))
|
||||
}
|
||||
|
||||
// user change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||
//+kubebuilder:webhook:path=/validate-fission-io-v1-timetrigger,mutating=false,failurePolicy=fail,sideEffects=None,groups=fission.io,resources=timetriggers,verbs=create;update,versions=v1,name=vtimetrigger.fission.io,admissionReviewVersions=v1
|
||||
|
||||
var _ webhook.Validator = &TimeTrigger{}
|
||||
|
||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *TimeTrigger) ValidateCreate() (admission.Warnings, error) {
|
||||
timetriggerlog.Debug("validate create", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("TimeTrigger", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = IsValidCronSpec(r.Spec.Cron)
|
||||
if err != nil {
|
||||
err = ferror.MakeError(ferror.ErrorInvalidArgument, "TimeTrigger cron spec is not valid")
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *TimeTrigger) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
|
||||
timetriggerlog.Debug("validate update", zap.String("name", r.Name))
|
||||
err := r.Validate()
|
||||
if err != nil {
|
||||
err = AggregateValidationErrors("TimeTrigger", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = IsValidCronSpec(r.Spec.Cron)
|
||||
if err != nil {
|
||||
err = ferror.MakeError(ferror.ErrorInvalidArgument, "TimeTrigger cron spec is not valid")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
|
||||
func (r *TimeTrigger) ValidateDelete() (admission.Warnings, error) {
|
||||
timetriggerlog.Debug("validate delete", zap.String("name", r.Name))
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user