Skip to content

Commit

Permalink
Workaround controller-runtime webhook upsert bug (#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
pebrc committed Jul 23, 2019
1 parent 4e1fd7f commit bc0113e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions operators/pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
package webhook

import (
"context"

"github.com/elastic/cloud-on-k8s/operators/pkg/apis/elasticsearch/v1alpha1"
"github.com/elastic/cloud-on-k8s/operators/pkg/webhook/elasticsearch"
"github.com/elastic/cloud-on-k8s/operators/pkg/webhook/license"
admission "k8s.io/api/admissionregistration/v1beta1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -48,6 +51,17 @@ func RegisterValidations(mgr manager.Manager, params Parameters) error {
Build()

disabled := !params.AutoInstall
if params.AutoInstall {
// nasty side effect in register function
webhookSvc := corev1.Service{
ObjectMeta: v1.ObjectMeta{
Name: params.Bootstrap.Service.Name,
Namespace: params.Bootstrap.Service.Namespace,
},
}
// best effort deletion attempt to handle incompatible services from previous versions
_ = mgr.GetClient().Delete(context.Background(), &webhookSvc)
}
svr, err := webhook.NewServer(admissionServerName, mgr, webhook.ServerOptions{
Port: serverPort,
CertDir: "/tmp/cert",
Expand Down

0 comments on commit bc0113e

Please sign in to comment.