mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
Updated code and docs to reflect correct terminology
- Updated instances of fsid with clusterid - Updated instances of credentials/subject with user/key Signed-off-by: ShyamsundarR <srangana@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e1c685ef39
commit
fc0cf957be
@ -27,7 +27,7 @@ import (
|
||||
// StoreReader interface enables plugging different stores, that contain the
|
||||
// keys and data. (e.g k8s secrets or local files)
|
||||
type StoreReader interface {
|
||||
DataForKey(fsid string, key string) (string, error)
|
||||
DataForKey(clusterID string, key string) (string, error)
|
||||
}
|
||||
|
||||
/* ConfigKeys contents and format,
|
||||
@ -55,23 +55,23 @@ type ConfigStore struct {
|
||||
}
|
||||
|
||||
// dataForKey returns data from the config store for the provided key
|
||||
func (dc *ConfigStore) dataForKey(fsid string, key string) (string, error) {
|
||||
func (dc *ConfigStore) dataForKey(clusterID string, key string) (string, error) {
|
||||
if dc.StoreReader != nil {
|
||||
return dc.StoreReader.DataForKey(fsid, key)
|
||||
return dc.StoreReader.DataForKey(clusterID, key)
|
||||
}
|
||||
|
||||
err := errors.New("config store location uninitialized")
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Mons returns a comma separated MON list from the cluster config represented by fsid
|
||||
func (dc *ConfigStore) Mons(fsid string) (string, error) {
|
||||
return dc.dataForKey(fsid, csMonitors)
|
||||
// Mons returns a comma separated MON list from the cluster config represented by clusterID
|
||||
func (dc *ConfigStore) Mons(clusterID string) (string, error) {
|
||||
return dc.dataForKey(clusterID, csMonitors)
|
||||
}
|
||||
|
||||
// Pools returns a list of pool names from the cluster config represented by fsid
|
||||
func (dc *ConfigStore) Pools(fsid string) ([]string, error) {
|
||||
content, err := dc.dataForKey(fsid, csPools)
|
||||
// Pools returns a list of pool names from the cluster config represented by clusterID
|
||||
func (dc *ConfigStore) Pools(clusterID string) ([]string, error) {
|
||||
content, err := dc.dataForKey(clusterID, csPools)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -79,42 +79,42 @@ func (dc *ConfigStore) Pools(fsid string) ([]string, error) {
|
||||
return strings.Split(content, ","), nil
|
||||
}
|
||||
|
||||
// AdminID returns the admin ID from the cluster config represented by fsid
|
||||
func (dc *ConfigStore) AdminID(fsid string) (string, error) {
|
||||
return dc.dataForKey(fsid, csAdminID)
|
||||
// AdminID returns the admin ID from the cluster config represented by clusterID
|
||||
func (dc *ConfigStore) AdminID(clusterID string) (string, error) {
|
||||
return dc.dataForKey(clusterID, csAdminID)
|
||||
}
|
||||
|
||||
// UserID returns the user ID from the cluster config represented by fsid
|
||||
func (dc *ConfigStore) UserID(fsid string) (string, error) {
|
||||
return dc.dataForKey(fsid, csUserID)
|
||||
// UserID returns the user ID from the cluster config represented by clusterID
|
||||
func (dc *ConfigStore) UserID(clusterID string) (string, error) {
|
||||
return dc.dataForKey(clusterID, csUserID)
|
||||
}
|
||||
|
||||
// CredentialForUser returns the credentials for the requested user ID
|
||||
// from the cluster config represented by fsid
|
||||
func (dc *ConfigStore) CredentialForUser(fsid, userID string) (data string, err error) {
|
||||
var credkey string
|
||||
user, err := dc.AdminID(fsid)
|
||||
// KeyForUser returns the key for the requested user ID from the cluster config
|
||||
// represented by clusterID
|
||||
func (dc *ConfigStore) KeyForUser(clusterID, userID string) (data string, err error) {
|
||||
var fetchKey string
|
||||
user, err := dc.AdminID(clusterID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if user == userID {
|
||||
credkey = csAdminKey
|
||||
fetchKey = csAdminKey
|
||||
} else {
|
||||
user, err = dc.UserID(fsid)
|
||||
user, err = dc.UserID(clusterID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if user != userID {
|
||||
err = fmt.Errorf("requested user (%s) not found in cluster configuration of (%s)", userID, fsid)
|
||||
err = fmt.Errorf("requested user (%s) not found in cluster configuration of (%s)", userID, clusterID)
|
||||
return
|
||||
}
|
||||
|
||||
credkey = csUserKey
|
||||
fetchKey = csUserKey
|
||||
}
|
||||
|
||||
return dc.dataForKey(fsid, credkey)
|
||||
return dc.dataForKey(clusterID, fetchKey)
|
||||
}
|
||||
|
||||
// NewConfigStore returns a config store based on value of configRoot. If
|
||||
|
@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// nolint: gocyclo
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
@ -26,6 +24,7 @@ import (
|
||||
)
|
||||
|
||||
var basePath = "./test_artifacts"
|
||||
var clusterID = "testclusterid"
|
||||
var cs *ConfigStore
|
||||
|
||||
func cleanupTestData() {
|
||||
@ -51,20 +50,20 @@ func TestConfigStore(t *testing.T) {
|
||||
t.Errorf("Test setup error %s", err)
|
||||
}
|
||||
|
||||
// TEST: Should fail as fsid directory is missing
|
||||
_, err = cs.Mons("testfsid")
|
||||
// TEST: Should fail as clusterid directory is missing
|
||||
_, err = cs.Mons(clusterID)
|
||||
if err == nil {
|
||||
t.Errorf("Failed: expected error due to missing parent directory")
|
||||
}
|
||||
|
||||
testDir = basePath + "/" + "ceph-cluster-testfsid"
|
||||
testDir = basePath + "/" + "ceph-cluster-" + clusterID
|
||||
err = os.MkdirAll(testDir, 0700)
|
||||
if err != nil {
|
||||
t.Errorf("Test setup error %s", err)
|
||||
}
|
||||
|
||||
// TEST: Should fail as mons file is missing
|
||||
_, err = cs.Mons("testfsid")
|
||||
_, err = cs.Mons(clusterID)
|
||||
if err == nil {
|
||||
t.Errorf("Failed: expected error due to missing mons file")
|
||||
}
|
||||
@ -76,7 +75,7 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Should fail as MONs is an empty string
|
||||
content, err = cs.Mons("testfsid")
|
||||
content, err = cs.Mons(clusterID)
|
||||
if err == nil {
|
||||
t.Errorf("Failed: want (%s), got (%s)", data, content)
|
||||
}
|
||||
@ -88,7 +87,7 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Fetching MONs should succeed
|
||||
content, err = cs.Mons("testfsid")
|
||||
content, err = cs.Mons(clusterID)
|
||||
if err != nil || content != data {
|
||||
t.Errorf("Failed: want (%s), got (%s), err (%s)", data, content, err)
|
||||
}
|
||||
@ -100,7 +99,7 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Fetching MONs should succeed
|
||||
listContent, err := cs.Pools("testfsid")
|
||||
listContent, err := cs.Pools(clusterID)
|
||||
if err != nil || strings.Join(listContent, ",") != data {
|
||||
t.Errorf("Failed: want (%s), got (%s), err (%s)", data, content, err)
|
||||
}
|
||||
@ -112,7 +111,7 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Fetching provuser should succeed
|
||||
content, err = cs.AdminID("testfsid")
|
||||
content, err = cs.AdminID(clusterID)
|
||||
if err != nil || content != data {
|
||||
t.Errorf("Failed: want (%s), got (%s), err (%s)", data, content, err)
|
||||
}
|
||||
@ -124,7 +123,7 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Fetching pubuser should succeed
|
||||
content, err = cs.UserID("testfsid")
|
||||
content, err = cs.UserID(clusterID)
|
||||
if err != nil || content != data {
|
||||
t.Errorf("Failed: want (%s), got (%s), err (%s)", data, content, err)
|
||||
}
|
||||
@ -136,7 +135,7 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Fetching provkey should succeed
|
||||
content, err = cs.CredentialForUser("testfsid", "provuser")
|
||||
content, err = cs.KeyForUser(clusterID, "provuser")
|
||||
if err != nil || content != data {
|
||||
t.Errorf("Failed: want (%s), got (%s), err (%s)", data, content, err)
|
||||
}
|
||||
@ -148,13 +147,13 @@ func TestConfigStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// TEST: Fetching pubkey should succeed
|
||||
content, err = cs.CredentialForUser("testfsid", "pubuser")
|
||||
content, err = cs.KeyForUser(clusterID, "pubuser")
|
||||
if err != nil || content != data {
|
||||
t.Errorf("Failed: want (%s), got (%s), err (%s)", data, content, err)
|
||||
}
|
||||
|
||||
// TEST: Fetching random user key should fail
|
||||
_, err = cs.CredentialForUser("testfsid", "random")
|
||||
_, err = cs.KeyForUser(clusterID, "random")
|
||||
if err == nil {
|
||||
t.Errorf("Failed: Expected to fail fetching random user key")
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ BasePath defines the directory under which FileConfig will attempt to open and
|
||||
read contents of various Ceph cluster configurations.
|
||||
|
||||
Each Ceph cluster configuration is stored under a directory named,
|
||||
BasePath/ceph-cluster-<fsid>, where <fsid> is the Ceph cluster fsid.
|
||||
BasePath/ceph-cluster-<clusterid>, where <clusterid> uniquely identifies and
|
||||
separates the each Ceph cluster configuration.
|
||||
|
||||
Under each Ceph cluster configuration directory, individual files named as per
|
||||
the ConfigKeys constants in the ConfigStore interface, store the required
|
||||
@ -42,12 +43,12 @@ type FileConfig struct {
|
||||
|
||||
// DataForKey reads the appropriate config file, named using key, and returns
|
||||
// the contents of the file to the caller
|
||||
func (fc *FileConfig) DataForKey(fsid string, key string) (data string, err error) {
|
||||
pathToKey := path.Join(fc.BasePath, "ceph-cluster-"+fsid, key)
|
||||
func (fc *FileConfig) DataForKey(clusterid string, key string) (data string, err error) {
|
||||
pathToKey := path.Join(fc.BasePath, "ceph-cluster-"+clusterid, key)
|
||||
// #nosec
|
||||
content, err := ioutil.ReadFile(pathToKey)
|
||||
if err != nil || string(content) == "" {
|
||||
err = fmt.Errorf("error fetching configuration for cluster ID (%s). (%s)", fsid, err)
|
||||
err = fmt.Errorf("error fetching configuration for cluster ID (%s). (%s)", clusterid, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,8 @@ K8sConfig is a ConfigStore interface implementation that reads configuration
|
||||
information from k8s secrets.
|
||||
|
||||
Each Ceph cluster configuration secret is expected to be named,
|
||||
ceph-cluster-<fsid>, where <fsid> is the Ceph cluster fsid.
|
||||
ceph-cluster-<clusterid>, where <clusterid> uniquely identifies and
|
||||
separates the each Ceph cluster configuration.
|
||||
|
||||
The secret is expected to contain keys, as defined by the ConfigKeys constants
|
||||
in the ConfigStore interface.
|
||||
@ -37,18 +38,18 @@ type K8sConfig struct {
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// DataForKey reads the appropriate k8s secret, named using fsid, and returns
|
||||
// the contents of key within the secret
|
||||
func (kc *K8sConfig) DataForKey(fsid string, key string) (data string, err error) {
|
||||
secret, err := kc.Client.CoreV1().Secrets(kc.Namespace).Get("ceph-cluster-"+fsid, metav1.GetOptions{})
|
||||
// DataForKey reads the appropriate k8s secret, named using clusterid, and
|
||||
// returns the contents of key within the secret
|
||||
func (kc *K8sConfig) DataForKey(clusterid string, key string) (data string, err error) {
|
||||
secret, err := kc.Client.CoreV1().Secrets(kc.Namespace).Get("ceph-cluster-"+clusterid, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error fetching configuration for cluster ID (%s). (%s)", fsid, err)
|
||||
err = fmt.Errorf("error fetching configuration for cluster ID (%s). (%s)", clusterid, err)
|
||||
return
|
||||
}
|
||||
|
||||
content, ok := secret.Data[key]
|
||||
if !ok {
|
||||
err = fmt.Errorf("missing data for key (%s) in cluster configuration of (%s)", key, fsid)
|
||||
err = fmt.Errorf("missing data for key (%s) in cluster configuration of (%s)", key, clusterid)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user