2021-12-21 14:23:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
2024-04-04 08:49:32 +00:00
|
|
|
//nolint:gosec // secret for test
|
2021-02-22 11:13:40 +00:00
|
|
|
const (
|
2021-07-08 14:59:34 +00:00
|
|
|
// ceph user names.
|
2021-02-22 11:13:40 +00:00
|
|
|
keyringRBDProvisionerUsername = "cephcsi-rbd-provisioner"
|
|
|
|
keyringRBDNodePluginUsername = "cephcsi-rbd-node"
|
|
|
|
keyringRBDNamespaceProvisionerUsername = "cephcsi-rbd-ns-provisioner"
|
|
|
|
keyringRBDNamespaceNodePluginUsername = "cephcsi-rbd-ns-node"
|
|
|
|
keyringCephFSProvisionerUsername = "cephcsi-cephfs-provisioner"
|
|
|
|
keyringCephFSNodePluginUsername = "cephcsi-cephfs-node"
|
2021-07-08 14:59:34 +00:00
|
|
|
// secret names.
|
2021-02-22 11:13:40 +00:00
|
|
|
rbdNodePluginSecretName = "cephcsi-rbd-node"
|
|
|
|
rbdProvisionerSecretName = "cephcsi-rbd-provisioner"
|
|
|
|
rbdNamespaceNodePluginSecretName = "cephcsi-rbd-ns-node"
|
|
|
|
rbdNamespaceProvisionerSecretName = "cephcsi-rbd-ns-provisioner"
|
2021-10-15 06:44:10 +00:00
|
|
|
rbdMigrationNodePluginSecretName = "cephcsi-rbd-mig-node"
|
|
|
|
rbdMigrationProvisionerSecretName = "cephcsi-rbd-mig-provisioner"
|
2021-02-22 11:13:40 +00:00
|
|
|
cephFSNodePluginSecretName = "cephcsi-cephfs-node"
|
|
|
|
cephFSProvisionerSecretName = "cephcsi-cephfs-provisioner"
|
|
|
|
)
|
|
|
|
|
|
|
|
// refer https://github.com/ceph/ceph-csi/blob/devel/docs/capabilities.md#rbd
|
|
|
|
// for RBD caps.
|
|
|
|
func rbdNodePluginCaps(pool, rbdNamespace string) []string {
|
|
|
|
caps := []string{
|
|
|
|
"mon", "'profile rbd'",
|
|
|
|
"mgr", "'allow rw'",
|
|
|
|
}
|
|
|
|
if rbdNamespace == "" {
|
|
|
|
caps = append(caps, "osd", "'profile rbd'")
|
|
|
|
} else {
|
|
|
|
caps = append(caps, fmt.Sprintf("osd 'profile rbd pool=%s namespace=%s'", pool, rbdNamespace))
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
return caps
|
|
|
|
}
|
|
|
|
|
|
|
|
func rbdProvisionerCaps(pool, rbdNamespace string) []string {
|
|
|
|
caps := []string{
|
|
|
|
"mon", "'profile rbd'",
|
|
|
|
"mgr", "'allow rw'",
|
|
|
|
}
|
|
|
|
if rbdNamespace == "" {
|
|
|
|
caps = append(caps, "osd", "'profile rbd'")
|
|
|
|
} else {
|
|
|
|
caps = append(caps, fmt.Sprintf("osd 'profile rbd pool=%s namespace=%s'", pool, rbdNamespace))
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
return caps
|
|
|
|
}
|
|
|
|
|
|
|
|
// refer https://github.com/ceph/ceph-csi/blob/devel/docs/capabilities.md#rbd
|
|
|
|
// for cephFS caps.
|
|
|
|
func cephFSNodePluginCaps() []string {
|
|
|
|
caps := []string{
|
|
|
|
"mon", "'allow r'",
|
|
|
|
"mgr", "'allow rw'",
|
|
|
|
"osd", "'allow rw tag cephfs *=*'",
|
|
|
|
"mds", "'allow rw'",
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
return caps
|
|
|
|
}
|
|
|
|
|
|
|
|
func cephFSProvisionerCaps() []string {
|
|
|
|
caps := []string{
|
|
|
|
"mon", "'allow r'",
|
|
|
|
"mgr", "'allow rw'",
|
|
|
|
"osd", "'allow rw tag cephfs metadata=*'",
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
return caps
|
|
|
|
}
|
|
|
|
|
|
|
|
func createCephUser(f *framework.Framework, user string, caps []string) (string, error) {
|
|
|
|
cmd := fmt.Sprintf("ceph auth get-or-create-key client.%s %s", user, strings.Join(caps, " "))
|
|
|
|
stdOut, stdErr, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if stdErr != "" {
|
2021-11-22 06:49:34 +00:00
|
|
|
return "", fmt.Errorf("failed to create user %s: %v", cmd, stdErr)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
return strings.TrimSpace(stdOut), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteCephUser(f *framework.Framework, user string) error {
|
2024-04-04 08:49:32 +00:00
|
|
|
cmd := "ceph auth del client." + user
|
2021-02-22 11:13:40 +00:00
|
|
|
_, _, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-22 11:13:40 +00:00
|
|
|
return err
|
|
|
|
}
|