feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
54
pkg/controller/config/webhook_factory.go
Normal file
54
pkg/controller/config/webhook_factory.go
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type ValidatorInterface interface {
|
||||
ValidateCreate(ctx context.Context, secret *v1.Secret) (admission.Warnings, error)
|
||||
ValidateUpdate(ctx context.Context, old, new *v1.Secret) (admission.Warnings, error)
|
||||
ValidateDelete(ctx context.Context, secret *v1.Secret) (admission.Warnings, error)
|
||||
ConfigType() v1.SecretType
|
||||
}
|
||||
|
||||
type DefaulterInterface interface {
|
||||
Default(ctx context.Context, secret *v1.Secret) error
|
||||
ConfigType() v1.SecretType
|
||||
}
|
||||
|
||||
func (w *WebhookFactory) RegisterValidator(validator ValidatorInterface) {
|
||||
w.validators[validator.ConfigType()] = validator
|
||||
}
|
||||
|
||||
func (w *WebhookFactory) RegisterDefaulter(defaulter DefaulterInterface) {
|
||||
w.defaulters[defaulter.ConfigType()] = defaulter
|
||||
}
|
||||
|
||||
func (w *WebhookFactory) GetValidator(secretType v1.SecretType) ValidatorInterface {
|
||||
return w.validators[secretType]
|
||||
}
|
||||
|
||||
func (w *WebhookFactory) GetDefaulter(secretType v1.SecretType) DefaulterInterface {
|
||||
return w.defaulters[secretType]
|
||||
}
|
||||
|
||||
type WebhookFactory struct {
|
||||
validators map[v1.SecretType]ValidatorInterface
|
||||
defaulters map[v1.SecretType]DefaulterInterface
|
||||
}
|
||||
|
||||
func NewWebhookFactory() *WebhookFactory {
|
||||
return &WebhookFactory{
|
||||
validators: make(map[v1.SecretType]ValidatorInterface),
|
||||
defaulters: make(map[v1.SecretType]DefaulterInterface),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user