Skip to content

Commit

Permalink
Update webhook to be mutating webhook to imporove flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Venkatesh committed Aug 24, 2020
1 parent 92f3a68 commit fc9a93d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/servicedefaults_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ServiceDefaultsValidator struct {
decoder *admission.Decoder
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-consul-hashicorp-com-v1alpha1-servicedefaults,mutating=false,failurePolicy=fail,groups=consul.hashicorp.com,resources=servicedefaults,versions=v1alpha1,name=vservicedefaults.kb.io
// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-servicedefaults,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=servicedefaults,versions=v1alpha1,name=mservicedefaults.consul.io

func (v *ServiceDefaultsValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
svcDefaults := &ServiceDefaults{}
Expand Down
8 changes: 4 additions & 4 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
kind: MutatingWebhookConfiguration
metadata:
creationTimestamp: null
name: validating-webhook-configuration
name: mutating-webhook-configuration
webhooks:
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
path: /validate-consul-hashicorp-com-v1alpha1-servicedefaults
path: /mutate-v1alpha1-servicedefaults
failurePolicy: Fail
name: vservicedefaults.kb.io
name: mservicedefaults.consul.io
rules:
- apiGroups:
- consul.hashicorp.com
Expand Down
2 changes: 1 addition & 1 deletion subcommand/controller/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *Command) Run(args []string) int {
// todo: this is super hacky. Setting global variable so the webhook validation can use the clients.
// Instead we should implement our own validating webhooks so we can pass in the clients.
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
mgr.GetWebhookServer().Register("/validate-consul-hashicorp-com-v1alpha1-servicedefaults", &webhook.Admission{Handler: &v1alpha1.ServiceDefaultsValidator{
mgr.GetWebhookServer().Register("/mutate-v1alpha1-servicedefaults", &webhook.Admission{Handler: &v1alpha1.ServiceDefaultsValidator{
Client: mgr.GetClient(),
ConsulClient: consulClient,
}})
Expand Down

0 comments on commit fc9a93d

Please sign in to comment.