subvolumegroup: add webhook for subvolumegroup
As we are not suppose to update the filesystem name once the subvolumegroup is created. added webhook validation for subvolumegroup update. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
1 parent
6aea438288
commit
74c4397973
4 files changed
+97
-7
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright 2022 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 v1
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||
)
|
||||
|
||||
var _ webhook.Validator = &CephFilesystemSubVolumeGroup{}
|
||||
|
||||
func (c *CephFilesystemSubVolumeGroup) ValidateCreate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *CephFilesystemSubVolumeGroup) ValidateUpdate(old runtime.Object) error {
|
||||
logger.Infof("validate update %s/%s CephFilesystemSubVolumeGroup", c.Namespace, c.Name)
|
||||
sg := old.(*CephFilesystemSubVolumeGroup)
|
||||
if sg.Spec.FilesystemName != c.Spec.FilesystemName {
|
||||
return errors.New("invalid update: filesystem name cannot be changed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *CephFilesystemSubVolumeGroup) ValidateDelete() error {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2022 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 v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestCephFilesystemSubVolumeGroupValidateUpdate(t *testing.T) {
|
||||
rn := &CephFilesystemSubVolumeGroup{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "subvol-name",
|
||||
},
|
||||
Spec: CephFilesystemSubVolumeGroupSpec{
|
||||
FilesystemName: "filesystem-name",
|
||||
},
|
||||
}
|
||||
ur := rn.DeepCopy()
|
||||
// validate with same filesystem name
|
||||
err := ur.ValidateUpdate(rn)
|
||||
assert.NoError(t, err)
|
||||
// validate with different filesystem name
|
||||
ur.Spec.FilesystemName = "new-filesystem-name"
|
||||
err = ur.ValidateUpdate(rn)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
@@ -75,6 +75,7 @@ var (
|
||||
&cephv1.CephBlockPool{},
|
||||
&cephv1.CephObjectStore{},
|
||||
&cephv1.CephBlockPoolRadosNamespace{},
|
||||
&cephv1.CephFilesystemSubVolumeGroup{},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -33,13 +33,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
issuerName = "selfsigned-issuer"
|
||||
certificateName = "rook-admission-controller-cert"
|
||||
webhookConfigName = "rook-ceph-webhook"
|
||||
serviceCephClusterPath = "/validate-ceph-rook-io-v1-cephcluster"
|
||||
serviceCephBlockPoolPath = "/validate-ceph-rook-io-v1-cephblockpool"
|
||||
serviceCephObjectStorePath = "/validate-ceph-rook-io-v1-cephobjectstore"
|
||||
serviceCephBlockPoolRadosNamespacePath = "/validate-ceph-rook-io-v1-cephblockpoolradosnamespace"
|
||||
issuerName = "selfsigned-issuer"
|
||||
certificateName = "rook-admission-controller-cert"
|
||||
webhookConfigName = "rook-ceph-webhook"
|
||||
serviceCephClusterPath = "/validate-ceph-rook-io-v1-cephcluster"
|
||||
serviceCephBlockPoolPath = "/validate-ceph-rook-io-v1-cephblockpool"
|
||||
serviceCephObjectStorePath = "/validate-ceph-rook-io-v1-cephobjectstore"
|
||||
serviceCephBlockPoolRadosNamespacePath = "/validate-ceph-rook-io-v1-cephblockpoolradosnamespace"
|
||||
serviceCephFileSystemSubvolumeGroupPath = "/validate-ceph-rook-io-v1-cephfilesystemsubvolumegroup"
|
||||
)
|
||||
|
||||
func fetchorCreateIssuer(ctx context.Context, certMgrClient *cs.CertmanagerV1Client) (*api.Issuer, error) {
|
||||
@@ -162,6 +163,7 @@ func addValidatingWebhookConfig(ctx context.Context, clusterdContext *clusterd.C
|
||||
fmt.Sprintf("cephblockpool-wh-%s-%s.rook.io", admissionControllerAppName, namespace),
|
||||
fmt.Sprintf("cephobjectstore-wh-%s-%s.rook.io", admissionControllerAppName, namespace),
|
||||
fmt.Sprintf("cephblockpoolradosnamespace-wh-%s-%s.rook.io", admissionControllerAppName, namespace),
|
||||
fmt.Sprintf("cephfilesystemsubvolumegroup-wh-%s-%s.rook.io", admissionControllerAppName, namespace),
|
||||
}
|
||||
|
||||
resources := []string{
|
||||
@@ -169,6 +171,7 @@ func addValidatingWebhookConfig(ctx context.Context, clusterdContext *clusterd.C
|
||||
"cephblockpools",
|
||||
"cephobjectstores",
|
||||
"cephblockpoolradosnamespaces",
|
||||
"cephfilesystemsubvolumegroups",
|
||||
}
|
||||
|
||||
resourcesServicePath := []string{
|
||||
@@ -176,6 +179,7 @@ func addValidatingWebhookConfig(ctx context.Context, clusterdContext *clusterd.C
|
||||
serviceCephBlockPoolPath,
|
||||
serviceCephObjectStorePath,
|
||||
serviceCephBlockPoolRadosNamespacePath,
|
||||
serviceCephFileSystemSubvolumeGroupPath,
|
||||
}
|
||||
|
||||
logger.Infof("Creating webhook %s/%s.", namespace, webhookConfigName)
|
||||
|
||||
Reference in new issue
Block a user