Skip to content

Commit f805f9f

Browse files
author
jiuyu
committed
Support to set single quota for multipath in tireStore.level
Signed-off-by: jiuyu <guotongyu.gty@alibaba-inc.com>
1 parent 4e199c8 commit f805f9f

File tree

8 files changed

+134
-135
lines changed

8 files changed

+134
-135
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/master_internal_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package jindocache
1818

1919
import (
20+
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
2021
"testing"
2122

2223
"github.com/fluid-cloudnative/fluid/pkg/common"
@@ -84,6 +85,19 @@ func TestSetupMasterInternal(t *testing.T) {
8485
testObjs = append(testObjs, datasetInput.DeepCopy())
8586
}
8687
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
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))
98+
if err != nil {
99+
t.Errorf("fail to create the runtimeInfo with error %v", err)
100+
}
87101

88102
engine := JindoCacheEngine{
89103
name: "hbase",
@@ -97,8 +111,9 @@ func TestSetupMasterInternal(t *testing.T) {
97111
},
98112
},
99113
},
114+
runtimeInfo: runtimeInfo,
100115
}
101-
err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts)
116+
err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts)
102117
if err != nil {
103118
t.Fatal(err.Error())
104119
}

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/master_internal_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package jindofsx
1818

1919
import (
20+
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
2021
"testing"
2122

2223
"github.com/fluid-cloudnative/fluid/pkg/common"
@@ -84,7 +85,19 @@ func TestSetupMasterInternal(t *testing.T) {
8485
testObjs = append(testObjs, datasetInput.DeepCopy())
8586
}
8687
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
87-
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))
98+
if err != nil {
99+
t.Errorf("fail to create the runtimeInfo with error %v", err)
100+
}
88101
engine := JindoFSxEngine{
89102
name: "hbase",
90103
namespace: "fluid",
@@ -97,8 +110,9 @@ func TestSetupMasterInternal(t *testing.T) {
97110
},
98111
},
99112
},
113+
runtimeInfo: runtimeInfo,
100114
}
101-
err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts)
115+
err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts)
102116
if err != nil {
103117
t.Fatal(err.Error())
104118
}

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{

0 commit comments

Comments
 (0)