Skip to content

Commit 8f578d4

Browse files
author
jiuyu
committed
Support to set single quota for multipath in tireStore.level
Signed-off-by: jiuyu <[email protected]>
1 parent f6191ea commit 8f578d4

File tree

10 files changed

+140
-157
lines changed

10 files changed

+140
-157
lines changed

pkg/ddc/jindo/master_internal_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,19 @@ func TestGenerateJindoValueFile(t *testing.T) {
183183
}
184184

185185
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
186-
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindo")
186+
result := resource.MustParse("20Gi")
187+
tiredStore := datav1alpha1.TieredStore{
188+
Levels: []datav1alpha1.Level{{
189+
MediumType: common.Memory,
190+
Quota: &result,
191+
High: "0.8",
192+
Low: "0.1",
193+
}},
194+
}
195+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime, base.WithTieredStore(tiredStore))
187196
if err != nil {
188197
t.Errorf("fail to create the runtimeInfo with error %v", err)
189198
}
190-
result := resource.MustParse("20Gi")
191199
engine := JindoEngine{
192200
name: "hbase",
193201
namespace: "fluid",
@@ -198,14 +206,7 @@ func TestGenerateJindoValueFile(t *testing.T) {
198206
Master: datav1alpha1.JindoCompTemplateSpec{
199207
Replicas: 2,
200208
},
201-
TieredStore: datav1alpha1.TieredStore{
202-
Levels: []datav1alpha1.Level{{
203-
MediumType: common.Memory,
204-
Quota: &result,
205-
High: "0.8",
206-
Low: "0.1",
207-
}},
208-
},
209+
TieredStore: tiredStore,
209210
},
210211
},
211212
runtimeInfo: runtimeInfo,

pkg/ddc/jindo/transform.go

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ import (
2424
"strings"
2525
"time"
2626

27-
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
27+
corev1 "k8s.io/api/core/v1"
2828

2929
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
3030
"github.com/fluid-cloudnative/fluid/pkg/common"
3131
"github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator"
3232
"github.com/fluid-cloudnative/fluid/pkg/utils"
3333
"github.com/fluid-cloudnative/fluid/pkg/utils/docker"
34+
jindoutils "github.com/fluid-cloudnative/fluid/pkg/utils/jindo"
35+
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
3436
"github.com/fluid-cloudnative/fluid/pkg/utils/transformer"
35-
corev1 "k8s.io/api/core/v1"
3637
)
3738

3839
func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jindo, err error) {
@@ -52,36 +53,15 @@ func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jind
5253
return
5354
}
5455

55-
var cachePaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot
56-
storagePath := runtime.Spec.TieredStore.Levels[0].Path
57-
originPath := strings.Split(storagePath, ",")
58-
for _, value := range originPath {
59-
cachePaths = append(cachePaths, strings.TrimRight(value, "/")+"/"+
60-
e.namespace+"/"+e.name+"/bigboot")
56+
cachePaths, originPaths, originQuotas := jindoutils.ProcessTiredStoreInfo(e.runtimeInfo)
57+
var quotaWithJindoUnit []string // 1Gi or 1Gi,2Gi,3Gi
58+
for _, quota := range originQuotas {
59+
quotaWithJindoUnit = append(quotaWithJindoUnit, utils.TransformQuantityToJindoUnit(quota))
6160
}
61+
6262
metaPath := cachePaths[0]
6363
dataPath := strings.Join(cachePaths, ",")
64-
65-
var userSetQuota []string // 1Gi or 1Gi,2Gi,3Gi
66-
if runtime.Spec.TieredStore.Levels[0].Quota != nil {
67-
userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(runtime.Spec.TieredStore.Levels[0].Quota))
68-
}
69-
70-
if runtime.Spec.TieredStore.Levels[0].QuotaList != "" {
71-
quotaList := runtime.Spec.TieredStore.Levels[0].QuotaList
72-
quotas := strings.Split(quotaList, ",")
73-
if len(quotas) != len(originPath) {
74-
err = fmt.Errorf("the num of cache path and quota must be equal")
75-
return
76-
}
77-
for _, value := range quotas {
78-
if strings.HasSuffix(value, "Gi") {
79-
value = strings.ReplaceAll(value, "Gi", "g")
80-
}
81-
userSetQuota = append(userSetQuota, value)
82-
}
83-
}
84-
userQuotas := strings.Join(userSetQuota, ",") // 1g or 1g,2g
64+
userQuotas := strings.Join(quotaWithJindoUnit, ",")
8565

8666
jindoSmartdataImage, smartdataTag, dnsServer := e.getSmartDataConfigs()
8767
jindoFuseImage, fuseTag := e.parseFuseImage()
@@ -111,7 +91,7 @@ func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jind
11191
},
11292
Mounts: Mounts{
11393
Master: e.transformMasterMountPath(metaPath),
114-
WorkersAndClients: e.transformWorkerMountPath(originPath),
94+
WorkersAndClients: e.transformWorkerMountPath(originPaths),
11595
},
11696
Owner: transformer.GenerateOwnerReferenceFromObject(runtime),
11797
RuntimeIdentity: common.RuntimeIdentity{

pkg/ddc/jindocache/master_internal_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,16 @@ func TestSetupMasterInternal(t *testing.T) {
8585
testObjs = append(testObjs, datasetInput.DeepCopy())
8686
}
8787
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
88-
89-
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindocache")
88+
quota := resource.MustParse("20Gi")
89+
tiredStore := datav1alpha1.TieredStore{
90+
Levels: []datav1alpha1.Level{{
91+
MediumType: common.Memory,
92+
Quota: &quota,
93+
High: "0.8",
94+
Low: "0.1",
95+
}},
96+
}
97+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime, base.WithTieredStore(tiredStore))
9098
if err != nil {
9199
t.Errorf("fail to create the runtimeInfo with error %v", err)
92100
}
@@ -190,6 +198,18 @@ func TestGenerateJindoValueFile(t *testing.T) {
190198
t.Errorf("fail to create the runtimeInfo with error %v", err)
191199
}
192200
result := resource.MustParse("20Gi")
201+
tiredStore := datav1alpha1.TieredStore{
202+
Levels: []datav1alpha1.Level{{
203+
MediumType: common.Memory,
204+
Quota: &result,
205+
High: "0.8",
206+
Low: "0.1",
207+
}},
208+
}
209+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime, base.WithTieredStore(tiredStore))
210+
if err != nil {
211+
t.Errorf("fail to create the runtimeInfo with error %v", err)
212+
}
193213
engine := JindoCacheEngine{
194214
name: "hbase",
195215
namespace: "fluid",
@@ -200,14 +220,7 @@ func TestGenerateJindoValueFile(t *testing.T) {
200220
Master: datav1alpha1.JindoCompTemplateSpec{
201221
Replicas: 2,
202222
},
203-
TieredStore: datav1alpha1.TieredStore{
204-
Levels: []datav1alpha1.Level{{
205-
MediumType: common.Memory,
206-
Quota: &result,
207-
High: "0.8",
208-
Low: "0.1",
209-
}},
210-
},
223+
TieredStore: tiredStore,
211224
},
212225
},
213226
runtimeInfo: runtimeInfo,

pkg/ddc/jindocache/transform.go

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ import (
2626
"strings"
2727
"time"
2828

29-
versionutil "github.com/fluid-cloudnative/fluid/pkg/utils/version"
3029
"github.com/pkg/errors"
31-
32-
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
30+
corev1 "k8s.io/api/core/v1"
3331
apierrors "k8s.io/apimachinery/pkg/api/errors"
32+
"k8s.io/apimachinery/pkg/api/resource"
33+
"k8s.io/client-go/util/retry"
3434

3535
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
3636
"github.com/fluid-cloudnative/fluid/pkg/common"
3737
"github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator"
3838
"github.com/fluid-cloudnative/fluid/pkg/utils"
3939
"github.com/fluid-cloudnative/fluid/pkg/utils/docker"
40+
jindoutils "github.com/fluid-cloudnative/fluid/pkg/utils/jindo"
41+
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
4042
"github.com/fluid-cloudnative/fluid/pkg/utils/transformer"
41-
corev1 "k8s.io/api/core/v1"
42-
"k8s.io/apimachinery/pkg/api/resource"
43-
"k8s.io/client-go/util/retry"
43+
versionutil "github.com/fluid-cloudnative/fluid/pkg/utils/version"
4444
)
4545

4646
type smartdataConfig struct {
@@ -62,47 +62,16 @@ func (e *JindoCacheEngine) transform(runtime *datav1alpha1.JindoRuntime) (value
6262
return
6363
}
6464

65-
var cachePaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot
66-
var storagePath = "/dev/shm/"
67-
if len(runtime.Spec.TieredStore.Levels) > 0 {
68-
storagePath = runtime.Spec.TieredStore.Levels[0].Path
69-
}
70-
originPath := strings.Split(storagePath, ",")
71-
for _, value := range originPath {
72-
cachePaths = append(cachePaths, strings.TrimRight(value, "/")+"/"+
73-
e.namespace+"/"+e.name+"/jindocache")
65+
cachePaths, originPaths, originQuotas := jindoutils.ProcessTiredStoreInfo(e.runtimeInfo)
66+
var quotaWithJindoUnit, quotaStrings []string // 1Gi or 1Gi,2Gi,3Gi
67+
for _, quota := range originQuotas {
68+
quotaWithJindoUnit = append(quotaWithJindoUnit, utils.TransformQuantityToJindoUnit(quota))
69+
quotaStrings = append(quotaStrings, quota.String())
7470
}
71+
7572
metaPath := cachePaths[0]
7673
dataPath := strings.Join(cachePaths, ",")
77-
78-
var quotas []string
79-
var userSetQuota []string // 1Gi or 1Gi,2Gi,3Gi
80-
if len(runtime.Spec.TieredStore.Levels) == 0 {
81-
userSetQuota = append(userSetQuota, "1Gi")
82-
quotas = append(quotas, "1Gi")
83-
} else if runtime.Spec.TieredStore.Levels[0].Quota != nil {
84-
userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(runtime.Spec.TieredStore.Levels[0].Quota))
85-
quotas = append(quotas, runtime.Spec.TieredStore.Levels[0].Quota.String())
86-
}
87-
88-
if len(runtime.Spec.TieredStore.Levels) != 0 && runtime.Spec.TieredStore.Levels[0].QuotaList != "" {
89-
quotaList := runtime.Spec.TieredStore.Levels[0].QuotaList
90-
quotas = strings.Split(quotaList, ",")
91-
if len(quotas) != len(originPath) {
92-
err = fmt.Errorf("the num of cache path and quota must be equal")
93-
return
94-
}
95-
for _, value := range quotas {
96-
if strings.HasSuffix(value, "Gi") {
97-
value = strings.ReplaceAll(value, "Gi", "g")
98-
}
99-
if strings.HasSuffix(value, "Mi") {
100-
value = strings.ReplaceAll(value, "Mi", "m")
101-
}
102-
userSetQuota = append(userSetQuota, value)
103-
}
104-
}
105-
userQuotas := strings.Join(userSetQuota, ",") // 1g or 1g,2g
74+
userQuotas := strings.Join(quotaWithJindoUnit, ",")
10675

10776
smartdataConfig := e.getSmartDataConfigs(runtime)
10877
smartdataTag := smartdataConfig.imageTag
@@ -145,7 +114,7 @@ func (e *JindoCacheEngine) transform(runtime *datav1alpha1.JindoRuntime) (value
145114
},
146115
Mounts: Mounts{
147116
Master: e.transformMasterMountPath(metaPath, mediumType, volumeType),
148-
WorkersAndClients: e.transformWorkerMountPath(originPath, quotas, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType),
117+
WorkersAndClients: e.transformWorkerMountPath(originPaths, quotaStrings, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType),
149118
},
150119
Owner: transformer.GenerateOwnerReferenceFromObject(runtime),
151120
RuntimeIdentity: common.RuntimeIdentity{

pkg/ddc/jindocache/transform_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func TestJindoCacheEngine_transform(t *testing.T) {
637637
s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{})
638638
_ = corev1.AddToScheme(s)
639639
client := fake.NewFakeClientWithScheme(s, runtimeObjs...)
640-
runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jindocache")
640+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime)
641641
if err != nil {
642642
t.Errorf("fail to create the runtimeInfo with error %v", err)
643643
}
@@ -1149,11 +1149,10 @@ func TestJindoCacheEngine_transformPolicy(t *testing.T) {
11491149
s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{})
11501150
_ = corev1.AddToScheme(s)
11511151
client := fake.NewFakeClientWithScheme(s, runtimeObjs...)
1152-
runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jinocache")
1152+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime)
11531153
if err != nil {
11541154
t.Errorf("fail to create the runtimeInfo with error %v", err)
11551155
}
1156-
11571156
e := &JindoCacheEngine{
11581157
runtime: tt.fields.runtime,
11591158
name: tt.fields.name,
@@ -1364,11 +1363,10 @@ func TestJindoCacheEngine_transformCacheSet(t *testing.T) {
13641363
s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{})
13651364
_ = corev1.AddToScheme(s)
13661365
client := fake.NewFakeClientWithScheme(s, runtimeObjs...)
1367-
runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jindocache")
1366+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime)
13681367
if err != nil {
13691368
t.Errorf("fail to create the runtimeInfo with error %v", err)
13701369
}
1371-
13721370
e := &JindoCacheEngine{
13731371
runtime: tt.fields.runtime,
13741372
name: tt.fields.name,

pkg/ddc/jindofsx/master_internal_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,16 @@ func TestSetupMasterInternal(t *testing.T) {
8585
testObjs = append(testObjs, datasetInput.DeepCopy())
8686
}
8787
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
88-
89-
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindofsx")
88+
quota := resource.MustParse("20Gi")
89+
tiredStore := datav1alpha1.TieredStore{
90+
Levels: []datav1alpha1.Level{{
91+
MediumType: common.Memory,
92+
Quota: &quota,
93+
High: "0.8",
94+
Low: "0.1",
95+
}},
96+
}
97+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime, base.WithTieredStore(tiredStore))
9098
if err != nil {
9199
t.Errorf("fail to create the runtimeInfo with error %v", err)
92100
}
@@ -182,13 +190,11 @@ func TestGenerateJindoValueFile(t *testing.T) {
182190
}
183191

184192
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
185-
186-
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindofsx")
193+
result := resource.MustParse("20Gi")
194+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime)
187195
if err != nil {
188196
t.Errorf("fail to create the runtimeInfo with error %v", err)
189197
}
190-
191-
result := resource.MustParse("20Gi")
192198
engine := JindoFSxEngine{
193199
name: "hbase",
194200
namespace: "fluid",

0 commit comments

Comments
 (0)