From b27df82256a7f563564407fcde6c774c0debe00f Mon Sep 17 00:00:00 2001 From: trafalgarzzz Date: Tue, 6 Aug 2024 14:26:39 +0800 Subject: [PATCH] bugfix: fix options affecting sharedOptions in other mounts Signed-off-by: trafalgarzzz --- pkg/ddc/thin/ufs_internal.go | 9 ++------- pkg/utils/map.go | 12 ++---------- pkg/utils/map_test.go | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/pkg/ddc/thin/ufs_internal.go b/pkg/ddc/thin/ufs_internal.go index 75f0c3d53d0..d1bda494e28 100644 --- a/pkg/ddc/thin/ufs_internal.go +++ b/pkg/ddc/thin/ufs_internal.go @@ -22,6 +22,7 @@ import ( datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" "github.com/fluid-cloudnative/fluid/pkg/common" "github.com/fluid-cloudnative/fluid/pkg/ddc/thin/operations" + "github.com/fluid-cloudnative/fluid/pkg/utils" "github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient" securityutil "github.com/fluid-cloudnative/fluid/pkg/utils/security" ) @@ -76,13 +77,7 @@ func (t *ThinEngine) usedSpaceInternal() (usedSpace int64, err error) { func (t *ThinEngine) genFuseMountOptions(m datav1alpha1.Mount, SharedOptions map[string]string, SharedEncryptOptions []datav1alpha1.EncryptOption, extractEncryptOptions bool) (map[string]string, error) { // initialize mount options - mOptions := map[string]string{} - if len(SharedOptions) > 0 { - mOptions = SharedOptions - } - for key, value := range m.Options { - mOptions[key] = value - } + mOptions := utils.UnionMapsWithOverride(SharedOptions, m.Options) // if encryptOptions have the same key with options // it will overwrite the corresponding value diff --git a/pkg/utils/map.go b/pkg/utils/map.go index cc9f65f728e..3754a96f933 100644 --- a/pkg/utils/map.go +++ b/pkg/utils/map.go @@ -32,17 +32,9 @@ func ContainsAll(m map[string]string, slice []string) bool { return true } -// UnionMapsWithOverride unions two maps into one. If either of the maps is empty, return the other one. -// If both maps share the same key, the value in map2 overrides the corresponding value in map1. +// UnionMapsWithOverride unions two maps into one. If both maps are empty or nil, return an empty map. +// If both maps share the same key, the value in map2 overrides the value in map1. func UnionMapsWithOverride(map1 map[string]string, map2 map[string]string) map[string]string { - if len(map1) == 0 || len(map2) == 0 { - if len(map1) == 0 { - return map2 - } else { - return map1 - } - } - retMap := map[string]string{} for k, v := range map1 { retMap[k] = v diff --git a/pkg/utils/map_test.go b/pkg/utils/map_test.go index b58ca0a918c..e393727791b 100644 --- a/pkg/utils/map_test.go +++ b/pkg/utils/map_test.go @@ -144,7 +144,7 @@ func TestUnionMapsWithOverride(t *testing.T) { map1: nil, map2: nil, }, - want: nil, + want: map[string]string{}, }, } for _, tt := range tests {