ceph: Add CRD for Object Store User
Add the ability to create and manage object store users with CRDs Signed-off-by: Ben Zieglmeier <benjamin.zieglmeier@target.com>
This commit is contained in:
1 parent
0a8e1096ff
commit
6d04bbf430
26 files changed
+901
-47
No files matched your search
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright 2018 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 clients
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/rgw"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
)
|
||||
|
||||
// ObjectUserOperation is wrapper for k8s rook object user operations
|
||||
type ObjectUserOperation struct {
|
||||
k8sh *utils.K8sHelper
|
||||
manifests installer.CephManifests
|
||||
}
|
||||
|
||||
// CreateObjectUserOperation creates new rook object user client
|
||||
func CreateObjectUserOperation(k8sh *utils.K8sHelper, manifests installer.CephManifests) *ObjectUserOperation {
|
||||
return &ObjectUserOperation{k8sh, manifests}
|
||||
}
|
||||
|
||||
// ObjectUserGet Function to get the details of an object user from radosgw
|
||||
func (o *ObjectUserOperation) GetUser(namespace string, store string, userid string) (*rgw.ObjectUser, error) {
|
||||
context := o.k8sh.MakeContext()
|
||||
rgwcontext := rgw.NewContext(context, store, namespace)
|
||||
userinfo, _, err := rgw.GetUser(rgwcontext, userid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get user info: %+v", err)
|
||||
}
|
||||
return userinfo, nil
|
||||
}
|
||||
|
||||
// UserSecretExists Function to check that user secret was created
|
||||
func (o *ObjectUserOperation) UserSecretExists(namespace string, store string, userid string) bool {
|
||||
_, err := o.k8sh.GetResource("-n", namespace, "secrets", "-l", "rook_object_store="+store, "-l", "user="+userid)
|
||||
if err == nil {
|
||||
logger.Infof("Object User Secret Exists")
|
||||
return true
|
||||
}
|
||||
logger.Infof("Unable to find user secret")
|
||||
return false
|
||||
}
|
||||
|
||||
// ObjectUserCreate Function to create a object store user in rook
|
||||
func (o *ObjectUserOperation) Create(namespace string, userid string, displayName string, store string) error {
|
||||
|
||||
logger.Infof("creating the object store user via CRD")
|
||||
if _, err := o.k8sh.ResourceOperation("create", o.manifests.GetObjectStoreUser(namespace, userid, displayName, store)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *ObjectUserOperation) Delete(namespace string, userid string) error {
|
||||
|
||||
logger.Infof("Deleting the object store user via CRD")
|
||||
if _, err := o.k8sh.DeleteResource("-n", namespace, "ObjectStoreUser", userid); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -30,11 +30,12 @@ var (
|
||||
|
||||
//TestClient is a wrapper for test client, containing interfaces for all rook operations
|
||||
type TestClient struct {
|
||||
BlockClient *BlockOperation
|
||||
FSClient *FilesystemOperation
|
||||
ObjectClient *ObjectOperation
|
||||
PoolClient *PoolOperation
|
||||
k8sh *utils.K8sHelper
|
||||
BlockClient *BlockOperation
|
||||
FSClient *FilesystemOperation
|
||||
ObjectClient *ObjectOperation
|
||||
ObjectUserClient *ObjectUserOperation
|
||||
PoolClient *PoolOperation
|
||||
k8sh *utils.K8sHelper
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -48,6 +49,7 @@ func CreateTestClient(k8sHelper *utils.K8sHelper, manifests installer.CephManife
|
||||
CreateBlockOperation(k8sHelper, manifests),
|
||||
CreateFilesystemOperation(k8sHelper, manifests),
|
||||
CreateObjectOperation(k8sHelper, manifests),
|
||||
CreateObjectUserOperation(k8sHelper, manifests),
|
||||
CreatePoolOperation(k8sHelper, manifests),
|
||||
k8sHelper,
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ func (h *CephInstaller) UninstallRookFromMultipleNS(helmInstalled bool, systemNa
|
||||
}
|
||||
|
||||
logger.Infof("removing the operator from namespace %s", systemNamespace)
|
||||
_, err = h.k8shelper.DeleteResource("crd", "clusters.ceph.rook.io", "pools.ceph.rook.io", "objectstores.ceph.rook.io", "filesystems.ceph.rook.io", "volumes.rook.io")
|
||||
_, err = h.k8shelper.DeleteResource("crd", "clusters.ceph.rook.io", "pools.ceph.rook.io", "objectstores.ceph.rook.io", "objectstoreusers.ceph.rook.io", "filesystems.ceph.rook.io", "volumes.rook.io")
|
||||
checkError(h.T(), err, "cannot delete CRDs")
|
||||
|
||||
if helmInstalled {
|
||||
|
||||
@@ -38,6 +38,7 @@ type CephManifests interface {
|
||||
GetBlockPoolStorageClass(namespace string, poolName string, storageClassName string, reclaimPolicy string) string
|
||||
GetFilesystem(namepace, name string, activeCount int) string
|
||||
GetObjectStore(namespace, name string, replicaCount, port int) string
|
||||
GetObjectStoreUser(namespace, name string, displayName string, store string) string
|
||||
}
|
||||
|
||||
type ClusterSettings struct {
|
||||
@@ -110,6 +111,22 @@ spec:
|
||||
---
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: objectstoreusers.ceph.rook.io
|
||||
spec:
|
||||
group: ceph.rook.io
|
||||
names:
|
||||
kind: ObjectStoreUser
|
||||
listKind: ObjectStoreUserList
|
||||
plural: objectstoreusers
|
||||
singular: objectstoreuser
|
||||
shortNames:
|
||||
- rcou
|
||||
scope: Namespaced
|
||||
version: v1beta1
|
||||
---
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: pools.ceph.rook.io
|
||||
spec:
|
||||
@@ -619,3 +636,14 @@ spec:
|
||||
allNodes: false
|
||||
`
|
||||
}
|
||||
|
||||
func (m *CephManifestsMaster) GetObjectStoreUser(namespace, name string, displayName string, store string) string {
|
||||
return `apiVersion: ceph.rook.io/v1beta1
|
||||
kind: ObjectStoreUser
|
||||
metadata:
|
||||
name: ` + name + `
|
||||
namespace: ` + namespace + `
|
||||
spec:
|
||||
displayName: ` + displayName + `
|
||||
store: ` + store
|
||||
}
|
||||
@@ -574,3 +574,7 @@ spec:
|
||||
allNodes: false
|
||||
`
|
||||
}
|
||||
|
||||
func (m *CephManifestsV0_8) GetObjectStoreUser(namespace, name string, displayName string, store string) string {
|
||||
return ""
|
||||
}
|
||||
Reference in new issue
Block a user