Skip to content

Commit 6fbc2ff

Browse files
authored
Workaround controller-runtime webhook upsert bug (#1337) (#1350)
1 parent 4e1fd7f commit 6fbc2ff

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

operators/pkg/webhook/server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
package webhook
66

77
import (
8+
"context"
9+
810
"github.com/elastic/cloud-on-k8s/operators/pkg/apis/elasticsearch/v1alpha1"
911
"github.com/elastic/cloud-on-k8s/operators/pkg/webhook/elasticsearch"
1012
"github.com/elastic/cloud-on-k8s/operators/pkg/webhook/license"
1113
admission "k8s.io/api/admissionregistration/v1beta1"
1214
corev1 "k8s.io/api/core/v1"
15+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1316
"sigs.k8s.io/controller-runtime/pkg/manager"
1417
"sigs.k8s.io/controller-runtime/pkg/webhook"
1518

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

5053
disabled := !params.AutoInstall
54+
if params.AutoInstall {
55+
// nasty side effect in register function
56+
webhookSvc := corev1.Service{
57+
ObjectMeta: v1.ObjectMeta{
58+
Name: params.Bootstrap.Service.Name,
59+
Namespace: params.Bootstrap.Service.Namespace,
60+
},
61+
}
62+
// best effort deletion attempt to handle incompatible services from previous versions
63+
_ = mgr.GetClient().Delete(context.Background(), &webhookSvc)
64+
}
5165
svr, err := webhook.NewServer(admissionServerName, mgr, webhook.ServerOptions{
5266
Port: serverPort,
5367
CertDir: "/tmp/cert",

0 commit comments

Comments
 (0)