Skip to content

Commit c57c209

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

File tree

6 files changed

+102
-132
lines changed

6 files changed

+102
-132
lines changed

pkg/ddc/jindo/master_internal_test.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ package jindo
1919
import (
2020
"testing"
2121

22-
"github.com/fluid-cloudnative/fluid/pkg/common"
23-
"k8s.io/apimachinery/pkg/api/resource"
24-
2522
"github.com/brahma-adshonor/gohook"
2623
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
24+
"github.com/fluid-cloudnative/fluid/pkg/common"
25+
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
2726
"github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator"
2827
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
2928
"github.com/fluid-cloudnative/fluid/pkg/utils/helm"
3029
"github.com/pkg/errors"
30+
"k8s.io/apimachinery/pkg/api/resource"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/runtime"
3333
"k8s.io/apimachinery/pkg/util/net"
@@ -177,6 +177,18 @@ func TestGenerateJindoValueFile(t *testing.T) {
177177

178178
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
179179
result := resource.MustParse("20Gi")
180+
tiredStore := datav1alpha1.TieredStore{
181+
Levels: []datav1alpha1.Level{{
182+
MediumType: common.Memory,
183+
Quota: &result,
184+
High: "0.8",
185+
Low: "0.1",
186+
}},
187+
}
188+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime, base.WithTieredStore(tiredStore))
189+
if err != nil {
190+
t.Errorf("fail to create the runtimeInfo with error %v", err)
191+
}
180192
engine := JindoEngine{
181193
name: "hbase",
182194
namespace: "fluid",
@@ -187,19 +199,13 @@ func TestGenerateJindoValueFile(t *testing.T) {
187199
Master: datav1alpha1.JindoCompTemplateSpec{
188200
Replicas: 2,
189201
},
190-
TieredStore: datav1alpha1.TieredStore{
191-
Levels: []datav1alpha1.Level{{
192-
MediumType: common.Memory,
193-
Quota: &result,
194-
High: "0.8",
195-
Low: "0.1",
196-
}},
197-
},
202+
TieredStore: tiredStore,
198203
},
199204
},
205+
runtimeInfo: runtimeInfo,
200206
}
201207

202-
err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts)
208+
err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts)
203209
if err != nil {
204210
t.Fatal(err.Error())
205211
}

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/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/jindofsx/transform.go

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

30-
versionutil "github.com/fluid-cloudnative/fluid/pkg/utils/version"
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 *JindoFSxEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *J
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+"/jindofsx")
65+
cachePaths, originPaths, originQuotas := jindoutils.ProcessTiredStoreInfo(e.runtimeInfo)
66+
var quotaWithJindoUnit, quotas []string // 1Gi or 1Gi,2Gi,3Gi
67+
for _, quota := range originQuotas {
68+
quotaWithJindoUnit = append(quotaWithJindoUnit, utils.TransformQuantityToJindoUnit(quota))
69+
quotas = append(quotas, 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 *JindoFSxEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *J
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, quotas, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType),
149118
},
150119
Owner: transformer.GenerateOwnerReferenceFromObject(runtime),
151120
RuntimeIdentity: common.RuntimeIdentity{

pkg/utils/jindo/jindo.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ package jindo
1818

1919
import (
2020
"os"
21+
"strings"
22+
23+
"k8s.io/apimachinery/pkg/api/resource"
2124

2225
"github.com/fluid-cloudnative/fluid/pkg/common"
26+
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
2327
)
2428

2529
const (
@@ -52,3 +56,42 @@ func GetRuntimeImage() (image string) {
5256
}
5357
return
5458
}
59+
60+
func ProcessTiredStoreInfo(runtimeInfo base.RuntimeInfoInterface) (originPaths []string, cachePaths []string, quotas []*resource.Quantity) {
61+
tireStoreInfo := runtimeInfo.GetTieredStoreInfo()
62+
var defaultStoragePath = "/dev/shm/"
63+
64+
var subPath string
65+
if GetDefaultEngineImpl() == common.JindoFSxEngineImpl {
66+
subPath = "jindofsx"
67+
} else if GetDefaultEngineImpl() == common.JindoFSEngineImpl {
68+
subPath = "bigboot"
69+
} else if GetDefaultEngineImpl() == common.JindoCacheEngineImpl {
70+
subPath = "jindocache"
71+
}
72+
73+
if len(tireStoreInfo.Levels) > 0 {
74+
for _, cachePath := range tireStoreInfo.Levels[0].CachePaths {
75+
originPaths = append(originPaths, cachePath.Path)
76+
cachePaths = append(cachePaths, strings.TrimRight(cachePath.Path, "/")+"/"+
77+
runtimeInfo.GetNamespace()+"/"+runtimeInfo.GetName()+"/"+subPath)
78+
}
79+
80+
}
81+
if len(cachePaths) == 0 {
82+
originPaths = append(originPaths, defaultStoragePath)
83+
cachePaths = append(cachePaths, strings.TrimRight(defaultStoragePath, "/")+"/"+
84+
runtimeInfo.GetNamespace()+"/"+runtimeInfo.GetName()+"/"+subPath)
85+
}
86+
87+
if len(tireStoreInfo.Levels) == 0 {
88+
Quantity1Gi, _ := resource.ParseQuantity("1Gi")
89+
quotas = append(quotas, &Quantity1Gi)
90+
} else {
91+
for _, cachePath := range tireStoreInfo.Levels[0].CachePaths {
92+
quotas = append(quotas, cachePath.Quota)
93+
}
94+
}
95+
96+
return
97+
}

pkg/utils/quantity.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TransformQuantityToAlluxioUnit(q *resource.Quantity) (value string) {
4141
// that can be recognized by Jindo.
4242
func TransformQuantityToJindoUnit(q *resource.Quantity) (value string) {
4343
value = q.String()
44+
if strings.HasSuffix(value, "Ti") {
45+
value = strings.ReplaceAll(value, "Ti", "t")
46+
}
4447
if strings.HasSuffix(value, "Gi") {
4548
value = strings.ReplaceAll(value, "Gi", "g")
4649
}

0 commit comments

Comments
 (0)