From cfd43a7fd31181ead08566662dddb1fe6dc0f467 Mon Sep 17 00:00:00 2001 From: jiuyu Date: Fri, 17 Jan 2025 15:54:30 +0800 Subject: [PATCH] Support to set single quota for multipath in tireStore.level Signed-off-by: jiuyu --- pkg/ddc/jindo/master_internal_test.go | 30 +++++++++------ pkg/ddc/jindo/transform.go | 47 ++++++++++++----------- pkg/ddc/jindocache/transform.go | 53 +++++++++++--------------- pkg/ddc/jindofsx/transform.go | 55 ++++++++++++--------------- pkg/utils/quantity.go | 3 ++ 5 files changed, 92 insertions(+), 96 deletions(-) diff --git a/pkg/ddc/jindo/master_internal_test.go b/pkg/ddc/jindo/master_internal_test.go index 8154c16e802..f8e9ce1f1d0 100644 --- a/pkg/ddc/jindo/master_internal_test.go +++ b/pkg/ddc/jindo/master_internal_test.go @@ -19,15 +19,15 @@ package jindo import ( "testing" - "github.com/fluid-cloudnative/fluid/pkg/common" - "k8s.io/apimachinery/pkg/api/resource" - "github.com/brahma-adshonor/gohook" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/common" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/helm" "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/net" @@ -177,6 +177,18 @@ func TestGenerateJindoValueFile(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) result := resource.MustParse("20Gi") + tiredStore := datav1alpha1.TieredStore{ + Levels: []datav1alpha1.Level{{ + MediumType: common.Memory, + Quota: &result, + High: "0.8", + Low: "0.1", + }}, + } + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", common.JindoRuntime, base.WithTieredStore(tiredStore)) + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := JindoEngine{ name: "hbase", namespace: "fluid", @@ -187,19 +199,13 @@ func TestGenerateJindoValueFile(t *testing.T) { Master: datav1alpha1.JindoCompTemplateSpec{ Replicas: 2, }, - TieredStore: datav1alpha1.TieredStore{ - Levels: []datav1alpha1.Level{{ - MediumType: common.Memory, - Quota: &result, - High: "0.8", - Low: "0.1", - }}, - }, + TieredStore: tiredStore, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/ddc/jindo/transform.go b/pkg/ddc/jindo/transform.go index 69248db038d..a59dfc84bdc 100644 --- a/pkg/ddc/jindo/transform.go +++ b/pkg/ddc/jindo/transform.go @@ -52,36 +52,37 @@ func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jind return } - var cachePaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot - storagePath := runtime.Spec.TieredStore.Levels[0].Path - originPath := strings.Split(storagePath, ",") - for _, value := range originPath { - cachePaths = append(cachePaths, strings.TrimRight(value, "/")+"/"+ - e.namespace+"/"+e.name+"/bigboot") + var cachePaths, originPaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot + var defaultStoragePath = "/dev/shm/" + + tireStoreInfo := e.runtimeInfo.GetTieredStoreInfo() + if len(tireStoreInfo.Levels) > 0 { + for _, path := range runtime.Spec.TieredStore.Levels { + originPaths = append(originPaths, path.Path) + cachePaths = append(cachePaths, strings.TrimRight(path.Path, "/")+"/"+ + e.namespace+"/"+e.name+"/jindocache") + } + } + if len(cachePaths) == 0 { + originPaths = append(originPaths, defaultStoragePath) + cachePaths = append(cachePaths, strings.TrimRight(defaultStoragePath, "/")+"/"+ + e.namespace+"/"+e.name+"/jindocache") + } + metaPath := cachePaths[0] dataPath := strings.Join(cachePaths, ",") var userSetQuota []string // 1Gi or 1Gi,2Gi,3Gi - if runtime.Spec.TieredStore.Levels[0].Quota != nil { - userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(runtime.Spec.TieredStore.Levels[0].Quota)) - } - if runtime.Spec.TieredStore.Levels[0].QuotaList != "" { - quotaList := runtime.Spec.TieredStore.Levels[0].QuotaList - quotas := strings.Split(quotaList, ",") - if len(quotas) != len(originPath) { - err = fmt.Errorf("the num of cache path and quota must be equal") - return - } - for _, value := range quotas { - if strings.HasSuffix(value, "Gi") { - value = strings.ReplaceAll(value, "Gi", "g") - } - userSetQuota = append(userSetQuota, value) + if len(tireStoreInfo.Levels) == 0 { + userSetQuota = append(userSetQuota, "1Gi") + } else { + for _, cachePath := range tireStoreInfo.Levels[0].CachePaths { + userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(cachePath.Quota)) } } - userQuotas := strings.Join(userSetQuota, ",") // 1g or 1g,2g + userQuotas := strings.Join(userSetQuota, ",") jindoSmartdataImage, smartdataTag, dnsServer := e.getSmartDataConfigs() jindoFuseImage, fuseTag := e.parseFuseImage() @@ -111,7 +112,7 @@ func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jind }, Mounts: Mounts{ Master: e.transformMasterMountPath(metaPath), - WorkersAndClients: e.transformWorkerMountPath(originPath), + WorkersAndClients: e.transformWorkerMountPath(originPaths), }, Owner: transformer.GenerateOwnerReferenceFromObject(runtime), RuntimeIdentity: common.RuntimeIdentity{ diff --git a/pkg/ddc/jindocache/transform.go b/pkg/ddc/jindocache/transform.go index 323452aa827..50126cf475d 100644 --- a/pkg/ddc/jindocache/transform.go +++ b/pkg/ddc/jindocache/transform.go @@ -62,47 +62,40 @@ func (e *JindoCacheEngine) transform(runtime *datav1alpha1.JindoRuntime) (value return } - var cachePaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot - var storagePath = "/dev/shm/" - if len(runtime.Spec.TieredStore.Levels) > 0 { - storagePath = runtime.Spec.TieredStore.Levels[0].Path + var cachePaths, originPaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot + var defaultStoragePath = "/dev/shm/" + + tireStoreInfo := e.runtimeInfo.GetTieredStoreInfo() + if len(tireStoreInfo.Levels) > 0 { + for _, path := range runtime.Spec.TieredStore.Levels { + originPaths = append(originPaths, path.Path) + cachePaths = append(cachePaths, strings.TrimRight(path.Path, "/")+"/"+ + e.namespace+"/"+e.name+"/jindocache") + } + } - originPath := strings.Split(storagePath, ",") - for _, value := range originPath { - cachePaths = append(cachePaths, strings.TrimRight(value, "/")+"/"+ + if len(cachePaths) == 0 { + originPaths = append(originPaths, defaultStoragePath) + cachePaths = append(cachePaths, strings.TrimRight(defaultStoragePath, "/")+"/"+ e.namespace+"/"+e.name+"/jindocache") } + metaPath := cachePaths[0] dataPath := strings.Join(cachePaths, ",") var quotas []string var userSetQuota []string // 1Gi or 1Gi,2Gi,3Gi - if len(runtime.Spec.TieredStore.Levels) == 0 { + + if len(tireStoreInfo.Levels) == 0 { userSetQuota = append(userSetQuota, "1Gi") quotas = append(quotas, "1Gi") - } else if runtime.Spec.TieredStore.Levels[0].Quota != nil { - userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(runtime.Spec.TieredStore.Levels[0].Quota)) - quotas = append(quotas, runtime.Spec.TieredStore.Levels[0].Quota.String()) - } - - if len(runtime.Spec.TieredStore.Levels) != 0 && runtime.Spec.TieredStore.Levels[0].QuotaList != "" { - quotaList := runtime.Spec.TieredStore.Levels[0].QuotaList - quotas = strings.Split(quotaList, ",") - if len(quotas) != len(originPath) { - err = fmt.Errorf("the num of cache path and quota must be equal") - return - } - for _, value := range quotas { - if strings.HasSuffix(value, "Gi") { - value = strings.ReplaceAll(value, "Gi", "g") - } - if strings.HasSuffix(value, "Mi") { - value = strings.ReplaceAll(value, "Mi", "m") - } - userSetQuota = append(userSetQuota, value) + } else { + for _, cachePath := range tireStoreInfo.Levels[0].CachePaths { + quotas = append(quotas, cachePath.Quota.String()) + userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(cachePath.Quota)) } } - userQuotas := strings.Join(userSetQuota, ",") // 1g or 1g,2g + userQuotas := strings.Join(userSetQuota, ",") smartdataConfig := e.getSmartDataConfigs(runtime) smartdataTag := smartdataConfig.imageTag @@ -145,7 +138,7 @@ func (e *JindoCacheEngine) transform(runtime *datav1alpha1.JindoRuntime) (value }, Mounts: Mounts{ Master: e.transformMasterMountPath(metaPath, mediumType, volumeType), - WorkersAndClients: e.transformWorkerMountPath(originPath, quotas, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType), + WorkersAndClients: e.transformWorkerMountPath(originPaths, quotas, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType), }, Owner: transformer.GenerateOwnerReferenceFromObject(runtime), RuntimeIdentity: common.RuntimeIdentity{ diff --git a/pkg/ddc/jindofsx/transform.go b/pkg/ddc/jindofsx/transform.go index 8310dd0a817..62565c790e6 100644 --- a/pkg/ddc/jindofsx/transform.go +++ b/pkg/ddc/jindofsx/transform.go @@ -62,47 +62,40 @@ func (e *JindoFSxEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *J return } - var cachePaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot - var storagePath = "/dev/shm/" - if len(runtime.Spec.TieredStore.Levels) > 0 { - storagePath = runtime.Spec.TieredStore.Levels[0].Path + var cachePaths, originPaths []string // /mnt/disk1/bigboot or /mnt/disk1/bigboot,/mnt/disk2/bigboot + var defaultStoragePath = "/dev/shm/" + + tireStoreInfo := e.runtimeInfo.GetTieredStoreInfo() + if len(tireStoreInfo.Levels) > 0 { + for _, path := range runtime.Spec.TieredStore.Levels { + originPaths = append(originPaths, path.Path) + cachePaths = append(cachePaths, strings.TrimRight(path.Path, "/")+"/"+ + e.namespace+"/"+e.name+"/jindocache") + } + } - originPath := strings.Split(storagePath, ",") - for _, value := range originPath { - cachePaths = append(cachePaths, strings.TrimRight(value, "/")+"/"+ - e.namespace+"/"+e.name+"/jindofsx") + if len(cachePaths) == 0 { + originPaths = append(originPaths, defaultStoragePath) + cachePaths = append(cachePaths, strings.TrimRight(defaultStoragePath, "/")+"/"+ + e.namespace+"/"+e.name+"/jindocache") } + metaPath := cachePaths[0] dataPath := strings.Join(cachePaths, ",") var quotas []string var userSetQuota []string // 1Gi or 1Gi,2Gi,3Gi - if len(runtime.Spec.TieredStore.Levels) == 0 { + + if len(tireStoreInfo.Levels) == 0 { userSetQuota = append(userSetQuota, "1Gi") quotas = append(quotas, "1Gi") - } else if runtime.Spec.TieredStore.Levels[0].Quota != nil { - userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(runtime.Spec.TieredStore.Levels[0].Quota)) - quotas = append(quotas, runtime.Spec.TieredStore.Levels[0].Quota.String()) - } - - if len(runtime.Spec.TieredStore.Levels) != 0 && runtime.Spec.TieredStore.Levels[0].QuotaList != "" { - quotaList := runtime.Spec.TieredStore.Levels[0].QuotaList - quotas = strings.Split(quotaList, ",") - if len(quotas) != len(originPath) { - err = fmt.Errorf("the num of cache path and quota must be equal") - return - } - for _, value := range quotas { - if strings.HasSuffix(value, "Gi") { - value = strings.ReplaceAll(value, "Gi", "g") - } - if strings.HasSuffix(value, "Mi") { - value = strings.ReplaceAll(value, "Mi", "m") - } - userSetQuota = append(userSetQuota, value) + } else { + for _, cachePath := range tireStoreInfo.Levels[0].CachePaths { + quotas = append(quotas, cachePath.Quota.String()) + userSetQuota = append(userSetQuota, utils.TransformQuantityToJindoUnit(cachePath.Quota)) } } - userQuotas := strings.Join(userSetQuota, ",") // 1g or 1g,2g + userQuotas := strings.Join(userSetQuota, ",") smartdataConfig := e.getSmartDataConfigs(runtime) smartdataTag := smartdataConfig.imageTag @@ -145,7 +138,7 @@ func (e *JindoFSxEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *J }, Mounts: Mounts{ Master: e.transformMasterMountPath(metaPath, mediumType, volumeType), - WorkersAndClients: e.transformWorkerMountPath(originPath, quotas, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType), + WorkersAndClients: e.transformWorkerMountPath(originPaths, quotas, e.getMediumTypeFromVolumeSource(string(mediumType), runtime.Spec.TieredStore.Levels), volumeType), }, Owner: transformer.GenerateOwnerReferenceFromObject(runtime), RuntimeIdentity: common.RuntimeIdentity{ diff --git a/pkg/utils/quantity.go b/pkg/utils/quantity.go index e6170e450de..5d53c0e9b0b 100644 --- a/pkg/utils/quantity.go +++ b/pkg/utils/quantity.go @@ -41,6 +41,9 @@ func TransformQuantityToAlluxioUnit(q *resource.Quantity) (value string) { // that can be recognized by Jindo. func TransformQuantityToJindoUnit(q *resource.Quantity) (value string) { value = q.String() + if strings.HasSuffix(value, "Ti") { + value = strings.ReplaceAll(value, "Ti", "t") + } if strings.HasSuffix(value, "Gi") { value = strings.ReplaceAll(value, "Gi", "g") }