Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround controller-runtime webhook upsert bug #1337

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -51,6 +54,17 @@ func RegisterValidations(mgr manager.Manager, params Parameters) error {
}

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