Skip to content

Commit

Permalink
Refactor func ThinEngine.transformFuseConfig
Browse files Browse the repository at this point in the history
Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
  • Loading branch information
TrafalgarZZZ committed May 8, 2024
1 parent 4aa5401 commit 0fd8fd3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pkg/ddc/thin/transform_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getFuseConfigStorage() string {
return "configmap"
}

func (t *ThinEngine) transformFuseConfig(runtime *datav1alpha1.ThinRuntime, dataset *datav1alpha1.Dataset, value *ThinValue) (string, error) {
func (t *ThinEngine) transformFuseConfig(runtime *datav1alpha1.ThinRuntime, dataset *datav1alpha1.Dataset, value *ThinValue) (error) {
fuseConfigStorage := getFuseConfigStorage()

mounts := []datav1alpha1.Mount{}
Expand All @@ -55,7 +55,7 @@ func (t *ThinEngine) transformFuseConfig(runtime *datav1alpha1.ThinRuntime, data
pvcName := strings.TrimPrefix(m.MountPoint, common.VolumeScheme.String())
csiInfo, mountOptions, err := t.extractVolumeInfo(pvcName)
if err != nil {
return "", errors.Wrapf(err, "failed to extract volume info from PersistentVolumeClaim \"%s\"", pvcName)
return errors.Wrapf(err, "failed to extract volume info from PersistentVolumeClaim \"%s\"", pvcName)
}

pvAttributes[pvcName] = csiInfo
Expand All @@ -64,7 +64,7 @@ func (t *ThinEngine) transformFuseConfig(runtime *datav1alpha1.ThinRuntime, data

options, err := t.extractMountOptions(m, dataset, fuseConfigStorage, value)
if err != nil {
return "", err
return err
}
m.Options = options
m.EncryptOptions = nil
Expand All @@ -86,11 +86,11 @@ func (t *ThinEngine) transformFuseConfig(runtime *datav1alpha1.ThinRuntime, data
var configStr []byte
configStr, err := json.Marshal(config)
if err != nil {
return "", errors.Wrapf(err, "failed to dump fuse config to json, runtime: \"%s/%s\"", runtime.Namespace, runtime.Name)
return errors.Wrapf(err, "failed to dump fuse config to json, runtime: \"%s/%s\"", runtime.Namespace, runtime.Name)
}
value.Fuse.ConfigValue = string(configStr)
value.Fuse.ConfigStorage = fuseConfigStorage
return string(configStr), nil
return nil
}

func (t *ThinEngine) transformEncryptOptionsWithSecretVolumes(m datav1alpha1.Mount, sharedEncryptOptions []datav1alpha1.EncryptOption, value *ThinValue) (options map[string]string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/thin/transform_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (t *ThinEngine) transformFuse(runtime *datav1alpha1.ThinRuntime, profile *d
}

// 12. fuse config
_, err = t.transformFuseConfig(runtime, dataset, value)
err = t.transformFuseConfig(runtime, dataset, value)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/ddc/thin/ufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ func (t ThinEngine) updateFuseConfigOnChange(runtime *datav1alpha1.ThinRuntime,
return update, nil
}

configStr, err := t.transformFuseConfig(runtime, dataset, &ThinValue{})
updatedThinValue := &ThinValue{}
err = t.transformFuseConfig(runtime, dataset, updatedThinValue)
if err != nil {
return update, nil
}

fuseConfigMapToUpdate := fuseConfigMap.DeepCopy()
fuseConfigMapToUpdate.Data["config.json"] = configStr
fuseConfigMapToUpdate.Data["config.json"] = updatedThinValue.Fuse.ConfigValue
if !reflect.DeepEqual(fuseConfigMap, fuseConfigMapToUpdate) {
t.Log.Info("Update fuse config", "fuse config", configStr)
t.Log.Info("Update fuse config", "fuse config", updatedThinValue.Fuse.ConfigValue)
err = kubeclient.UpdateConfigMap(t.Client, fuseConfigMapToUpdate)
if err != nil {
return update, err
Expand Down

0 comments on commit 0fd8fd3

Please sign in to comment.