From 6fbc2ffb9a537d631e14a643d28d40e7b6312499 Mon Sep 17 00:00:00 2001 From: Peter Brachwitz Date: Tue, 23 Jul 2019 22:40:31 +0200 Subject: [PATCH] Workaround controller-runtime webhook upsert bug (#1337) (#1350) --- operators/pkg/webhook/server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/operators/pkg/webhook/server.go b/operators/pkg/webhook/server.go index 941f9e4e67..629b41385c 100644 --- a/operators/pkg/webhook/server.go +++ b/operators/pkg/webhook/server.go @@ -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" @@ -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",