Skip to content

Commit

Permalink
update configmap volume mode 0755 & add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls committed Mar 22, 2022
1 parent 0914e31 commit c254c0a
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 13 deletions.
2 changes: 1 addition & 1 deletion charts/juicefs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ spec:
- name: script
configMap:
name: {{ template "juicefs.fullname" . }}-script
defaultMode: 0777
defaultMode: 0755
---
apiVersion: v1
kind: ConfigMap
Expand Down
2 changes: 1 addition & 1 deletion charts/juicefs/templates/worker/statefuleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ spec:
- name: script
configMap:
name: {{ template "juicefs.fullname" . }}-script
defaultMode: 0777
defaultMode: 0755
2 changes: 1 addition & 1 deletion pkg/ddc/juicefs/cacheinfo_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetCacheInfoFromConfigmap(client client.Client, name string, namespace stri
configMapName := fmt.Sprintf("%s-juicefs-values", name)
configMap, err := kubeclient.GetConfigmapByName(client, configMapName, namespace)
if err != nil {
return nil, errors.Wrap(err, "GetConfigMapByName when GetCacheInfoFromConfigmap")
return nil, errors.Wrap(err, "GetConfigMapByName error when GetCacheInfoFromConfigmap")
}

cacheinfo, err = parseCacheInfoFromConfigMap(configMap)
Expand Down
10 changes: 10 additions & 0 deletions pkg/ddc/juicefs/cacheinfo_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ func Test_parseCacheInfoFromConfigMap(t *testing.T) {
wantCacheInfo: map[string]string{"cachedir": "/tmp/jfs-cache", "mountpath": "/runtime-mnt/juicefs/fluid/test-dataset/juicefs-fuse"},
wantErr: false,
},
{
name: "parseCacheInfoFromConfigMap-err",
args: args{configMap: &v1.ConfigMap{
Data: map[string]string{
"data": `test`,
},
}},
wantCacheInfo: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
6 changes: 0 additions & 6 deletions pkg/ddc/juicefs/data_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"fmt"
"github.com/fluid-cloudnative/fluid/pkg/ddc/juicefs/operations"
"io/ioutil"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -174,11 +173,6 @@ func (e *JuiceFSEngine) CheckRuntimeReady() (ready bool) {
if err != nil || len(pods) == 0 {
return false
}
for _, pod := range pods {
if !podutil.IsPodReady(&pod) {
return false
}
}
return true
}

Expand Down
245 changes: 241 additions & 4 deletions pkg/ddc/juicefs/data_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func TestJuiceFSEngine_CreateDataLoadJob(t *testing.T) {
mockExecCheckReleaseCommon := func(name string, namespace string) (exist bool, err error) {
return false, nil
}
//mockExecCheckReleaseErr := func(name string, namespace string) (exist bool, err error) {
// return false, errors.New("fail to check release")
//}
mockExecCheckReleaseErr := func(name string, namespace string) (exist bool, err error) {
return false, errors.New("fail to check release")
}
mockExecInstallReleaseCommon := func(name string, namespace string, valueFile string, chartName string) error {
return nil
}
Expand Down Expand Up @@ -160,7 +160,17 @@ func TestJuiceFSEngine_CreateDataLoadJob(t *testing.T) {
Recorder: record.NewFakeRecorder(1),
}

err := gohook.Hook(helm.CheckRelease, mockExecCheckReleaseCommon, nil)
err := gohook.Hook(helm.CheckRelease, mockExecCheckReleaseErr, nil)
if err != nil {
t.Fatal(err.Error())
}
err = engine.CreateDataLoadJob(ctx, targetDataLoad)
if err == nil {
t.Errorf("fail to catch the error: %v", err)
}
wrappedUnhookCheckRelease()

err = gohook.Hook(helm.CheckRelease, mockExecCheckReleaseCommon, nil)
if err != nil {
t.Fatal(err.Error())
}
Expand Down Expand Up @@ -308,6 +318,133 @@ func TestJuiceFSEngine_GenerateDataLoadValueFileWithRuntimeHDD(t *testing.T) {
}
}

func TestJuiceFSEngine_GenerateDataLoadValueFileWithRuntime(t *testing.T) {
configMap := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataset-juicefs-values",
Namespace: "fluid",
},
Data: map[string]string{
"data": ``,
},
}

datasetInputs := []datav1alpha1.Dataset{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataset",
Namespace: "fluid",
},
Spec: datav1alpha1.DatasetSpec{},
},
}

statefulsetInputs := []appsv1.StatefulSet{
{
ObjectMeta: metav1.ObjectMeta{
Name: "juicefs-worker",
Namespace: "fluid",
},
Spec: appsv1.StatefulSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"a": "b"},
},
},
},
}
podListInputs := []v1.PodList{{
Items: []v1.Pod{{
ObjectMeta: metav1.ObjectMeta{
Namespace: "fluid",
Labels: map[string]string{"a": "b"},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
Conditions: []v1.PodCondition{{
Type: v1.PodReady,
Status: v1.ConditionTrue,
}},
},
}},
}}
testObjs := []runtime.Object{}
testObjs = append(testObjs, configMap)
for _, datasetInput := range datasetInputs {
testObjs = append(testObjs, datasetInput.DeepCopy())
}
for _, statefulsetInput := range statefulsetInputs {
testObjs = append(testObjs, statefulsetInput.DeepCopy())
}
for _, podInput := range podListInputs {
testObjs = append(testObjs, podInput.DeepCopy())
}
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)

context := cruntime.ReconcileRequestContext{
Client: client,
}

dataLoadNoTarget := datav1alpha1.DataLoad{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataload",
Namespace: "fluid",
},
Spec: datav1alpha1.DataLoadSpec{
Dataset: datav1alpha1.TargetDataset{
Name: "test-dataset",
Namespace: "fluid",
},
Target: []datav1alpha1.TargetPath{{
Path: "/dir",
Replicas: 1,
}},
},
}
dataLoadWithTarget := datav1alpha1.DataLoad{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataload",
Namespace: "fluid",
},
Spec: datav1alpha1.DataLoadSpec{
Dataset: datav1alpha1.TargetDataset{
Name: "test-dataset",
Namespace: "fluid",
},
Target: []datav1alpha1.TargetPath{
{
Path: "/test",
},
},
},
}

var testCases = []struct {
dataLoad datav1alpha1.DataLoad
expectFileName string
}{
{
dataLoad: dataLoadNoTarget,
expectFileName: filepath.Join(os.TempDir(), "fluid-test-dataload-loader-values.yaml"),
},
{
dataLoad: dataLoadWithTarget,
expectFileName: filepath.Join(os.TempDir(), "fluid-test-dataload-loader-values.yaml"),
},
}

for _, test := range testCases {
engine := JuiceFSEngine{
name: "juicefs",
namespace: "fluid",
Client: client,
Log: log.NullLogger{},
}
if fileName, err := engine.generateDataLoadValueFile(context, test.dataLoad); err != nil || !strings.Contains(fileName, test.expectFileName) {
t.Errorf("fail to generate the dataload value file: %v", err)
}
}
}

func TestJuiceFSEngine_CheckExistenceOfPath(t *testing.T) {
configMap := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -422,3 +559,103 @@ func TestJuiceFSEngine_CheckExistenceOfPath(t *testing.T) {
}
wrappedUnhook()
}

func TestJuiceFSEngine_CheckRuntimeReady(t *testing.T) {
type fields struct {
name string
namespace string
}
tests := []struct {
name string
fields fields
sts appsv1.StatefulSet
podList v1.PodList
wantReady bool
}{
{
name: "test",
fields: fields{
name: "juicefs-test",
namespace: "fluid",
},
sts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "juicefs-test-worker",
Namespace: "fluid",
},
Spec: appsv1.StatefulSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"a": "b"},
},
},
},
podList: v1.PodList{
Items: []v1.Pod{{
ObjectMeta: metav1.ObjectMeta{
Namespace: "fluid",
Labels: map[string]string{"a": "b"},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
Conditions: []v1.PodCondition{{
Type: v1.PodReady,
Status: v1.ConditionTrue,
}},
},
}},
},
wantReady: true,
},
{
name: "test-err",
fields: fields{
name: "juicefs",
namespace: "fluid",
},
sts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "juicefs-worker",
Namespace: "fluid",
},
Spec: appsv1.StatefulSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"a": "b"},
},
},
},
podList: v1.PodList{
Items: []v1.Pod{{
ObjectMeta: metav1.ObjectMeta{
Namespace: "fluid",
Labels: map[string]string{"a": "b"},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
Conditions: []v1.PodCondition{{
Type: v1.PodReady,
Status: v1.ConditionFalse,
}},
},
}},
},
wantReady: false,
},
}
for _, tt := range tests {
testObjs := []runtime.Object{}
t.Run(tt.name, func(t *testing.T) {
testObjs = append(testObjs, tt.sts.DeepCopy())
testObjs = append(testObjs, tt.podList.DeepCopy())
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
e := &JuiceFSEngine{
name: tt.fields.name,
namespace: tt.fields.namespace,
Client: client,
Log: log.NullLogger{},
}
if gotReady := e.CheckRuntimeReady(); gotReady != tt.wantReady {
t.Errorf("CheckRuntimeReady() = %v, want %v", gotReady, tt.wantReady)
}
})
}
}

0 comments on commit c254c0a

Please sign in to comment.