Progress toward issue #2003. Includes design from design doc PR #1578 Use init containers to create configuration for Ceph mgrs. There is only one init container in this design. The init container calls the Rook binary to create Ceph config files which are then shared with the mds daemon main container. Once this init is run, the main mds daemon is run. Leaving room to use the Ceph-versioned image in the future, call `ceph-mds --foreground ...` to run the Ceph mds. The refactor to using an init container also necessitated refactoring the mdses replicaset implementation to a deployment-per-pod implementation due to a chicken-egg problem. With a single container (in the before times) the Rook binary was able to call the ceph-mds daemon with an id generated from the pod name. Since the pod name is not known before runtime, and the id is one of the few params that must be specified to Ceph daemons on run, it is necessary to know the id beforehand; thus the move to a deployment architecture following the likes of the mon and mgr daemons. Signed-off-by: Blaine Gardner <blaine.gardner@suse.com>
155 lines
5.0 KiB
Go
155 lines
5.0 KiB
Go
/*
|
|
Copyright 2016 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 file
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
|
|
cephv1beta1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1beta1"
|
|
"github.com/rook/rook/pkg/clusterd"
|
|
cephtest "github.com/rook/rook/pkg/daemon/ceph/test"
|
|
testop "github.com/rook/rook/pkg/operator/test"
|
|
exectest "github.com/rook/rook/pkg/util/exec/test"
|
|
"github.com/stretchr/testify/assert"
|
|
"k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func TestValidateSpec(t *testing.T) {
|
|
context := &clusterd.Context{Executor: &exectest.MockExecutor{}}
|
|
fs := cephv1beta1.Filesystem{}
|
|
|
|
// missing name
|
|
assert.NotNil(t, validateFilesystem(context, fs))
|
|
fs.Name = "myfs"
|
|
|
|
// missing namespace
|
|
assert.NotNil(t, validateFilesystem(context, fs))
|
|
fs.Namespace = "myns"
|
|
|
|
// missing data pools
|
|
assert.NotNil(t, validateFilesystem(context, fs))
|
|
p := cephv1beta1.PoolSpec{Replicated: cephv1beta1.ReplicatedSpec{Size: 1}}
|
|
fs.Spec.DataPools = append(fs.Spec.DataPools, p)
|
|
|
|
// missing metadata pool
|
|
assert.NotNil(t, validateFilesystem(context, fs))
|
|
fs.Spec.MetadataPool = p
|
|
|
|
// missing mds count
|
|
assert.NotNil(t, validateFilesystem(context, fs))
|
|
fs.Spec.MetadataServer.ActiveCount = 1
|
|
|
|
// valid!
|
|
assert.Nil(t, validateFilesystem(context, fs))
|
|
}
|
|
|
|
func TestCreateFilesystem(t *testing.T) {
|
|
configDir, _ := ioutil.TempDir("", "")
|
|
// Output to check multiple file system creation
|
|
fses := `[{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":1,"data_pool_ids":[2],"data_pools":["myfs-data0"]}]`
|
|
|
|
executor := &exectest.MockExecutor{
|
|
MockExecuteCommandWithOutputFile: func(debug bool, actionName string, command string, outFileArg string, args ...string) (string, error) {
|
|
return "{\"key\":\"mysecurekey\"}", nil
|
|
},
|
|
MockExecuteCommandWithOutput: func(debug bool, actionName string, command string, args ...string) (string, error) {
|
|
if strings.Contains(command, "ceph-authtool") {
|
|
cephtest.CreateConfigDir(path.Join(configDir, "ns"))
|
|
}
|
|
|
|
return "", nil
|
|
},
|
|
}
|
|
defer os.RemoveAll(configDir)
|
|
context := &clusterd.Context{
|
|
Executor: executor,
|
|
ConfigDir: configDir,
|
|
Clientset: testop.New(3)}
|
|
fs := cephv1beta1.Filesystem{
|
|
ObjectMeta: metav1.ObjectMeta{Name: "myfs", Namespace: "ns"},
|
|
Spec: cephv1beta1.FilesystemSpec{
|
|
MetadataPool: cephv1beta1.PoolSpec{Replicated: cephv1beta1.ReplicatedSpec{Size: 1}},
|
|
DataPools: []cephv1beta1.PoolSpec{{Replicated: cephv1beta1.ReplicatedSpec{Size: 1}}},
|
|
MetadataServer: cephv1beta1.MetadataServerSpec{
|
|
ActiveCount: 1,
|
|
Resources: v1.ResourceRequirements{
|
|
Limits: v1.ResourceList{
|
|
v1.ResourceCPU: *resource.NewQuantity(100.0, resource.BinarySI),
|
|
},
|
|
Requests: v1.ResourceList{
|
|
v1.ResourceMemory: *resource.NewQuantity(1337.0, resource.BinarySI),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
// start a basic cluster
|
|
err := createFilesystem(context, fs, "v0.1", false, []metav1.OwnerReference{})
|
|
assert.Nil(t, err)
|
|
validateStart(t, context, fs)
|
|
|
|
// starting again should be a no-op
|
|
err = createFilesystem(context, fs, "v0.1", false, []metav1.OwnerReference{})
|
|
assert.Nil(t, err)
|
|
validateStart(t, context, fs)
|
|
|
|
// Test multiple filesystem creation
|
|
executor = &exectest.MockExecutor{
|
|
MockExecuteCommandWithOutputFile: func(debug bool, actionName string, command string, outFileArg string, args ...string) (string, error) {
|
|
if contains(args, "ls") {
|
|
return fses, nil
|
|
}
|
|
return "{\"key\":\"mysecurekey\"}", errors.New("multiple fs")
|
|
},
|
|
}
|
|
context = &clusterd.Context{
|
|
Executor: executor,
|
|
ConfigDir: configDir,
|
|
Clientset: testop.New(3)}
|
|
|
|
//Create another filesystem which should fail
|
|
err = createFilesystem(context, fs, "v0.1", false, []metav1.OwnerReference{})
|
|
assert.Equal(t, "failed to create file system myfs: Cannot create multiple filesystems. Enable ROOK_ALLOW_MULTIPLE_FILESYSTEMS env variable to create more than one", err.Error())
|
|
}
|
|
|
|
func contains(arr []string, str string) bool {
|
|
for _, a := range arr {
|
|
if a == str {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func validateStart(t *testing.T, context *clusterd.Context, fs cephv1beta1.Filesystem) {
|
|
r, err := context.Clientset.ExtensionsV1beta1().Deployments(fs.Namespace).Get("rook-ceph-mds-myfs-a", metav1.GetOptions{})
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "rook-ceph-mds-myfs-a", r.Name)
|
|
|
|
r, err = context.Clientset.ExtensionsV1beta1().Deployments(fs.Namespace).Get("rook-ceph-mds-myfs-b", metav1.GetOptions{})
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "rook-ceph-mds-myfs-b", r.Name)
|
|
}
|