Files
my-rook-config/pkg/operator/ceph/server.go
T
subhamkrai 40a99a20ff ceph: webhook check if one of port or securePort are non-zero
this commit adds new crd to admission webhooks to check
if one of the port or securePort are set to non-zero
value in objectstore crd.

If both are set to 0 in crd we'll see error like
```
Error from server (invalid create: either of port or securePort
fields should be not be zero): error when creating "object-test.yaml":
admission webhook
"cephobjectstore-wh-rook-ceph-admission-controller-rook-ceph.rook.io"
denied the request: invalid create: either of port or securePort fields
should be not be zero.
```

Signed-off-by: subhamkrai <srai@redhat.com>
2021-03-03 21:22:04 +05:30

69 lines
1.9 KiB
Go

/*
Copyright 2020 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package operator
import (
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)
var (
scheme = runtime.NewScheme()
resources = []webhook.Validator{&cephv1.CephCluster{}, &cephv1.CephBlockPool{}, &cephv1.CephObjectStore{}}
)
const (
// Default directory where TLS certs are stored
certDir = "/etc/webhook"
// Default port for server
port = 8079
)
// StartAdmissionController will start the server
func StartAdmissionController() error {
logger.Infof("starting the webhook for backend ceph")
err := cephv1.AddToScheme(scheme)
if err != nil {
return errors.Wrap(err, "failed to add to scheme")
}
opts := ctrl.Options{
Scheme: scheme,
Port: port,
CertDir: certDir,
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts)
if err != nil {
return errors.Wrap(err, "failed to create manager")
}
for _, resource := range resources {
err = ctrl.NewWebhookManagedBy(mgr).For(resource).Complete()
if err != nil {
return errors.Wrap(err, "failed to register webhooks")
}
}
logger.Info("starting webhook server")
err = mgr.Start(ctrl.SetupSignalHandler())
if err != nil {
return errors.Wrap(err, "failed to start server")
}
return nil
}