Skip to content

Commit

Permalink
fix: reconfiguring parameters labels not exist (#5517)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Oct 18, 2023
1 parent fefc5e5 commit c155c89
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
37 changes: 35 additions & 2 deletions controllers/apps/operations/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ func (p *pipeline) doMergeImpl(parameters appsv1alpha1.ConfigurationItem) error
return cfgcore.MakeError("not allowed to update file content: %s", key.Key)
}
updateParameters(item, key.Key, key.Parameters)
p.updatedParameters = append(p.updatedParameters, cfgcore.ParamPairs{
Key: key.Key,
UpdatedParams: fromKeyValuePair(key.Parameters),
})
continue
}
if key.FileContent != "" {
Expand Down Expand Up @@ -196,8 +200,16 @@ func (p *pipeline) createUpdatePatch(item *appsv1alpha1.ConfigurationItemDetail,
}

func updateFileContent(item *appsv1alpha1.ConfigurationItemDetail, key string, content string) {
params, ok := item.ConfigFileParams[key]
if !ok {
item.ConfigFileParams[key] = appsv1alpha1.ConfigParams{
Content: &content,
}
return
}
item.ConfigFileParams[key] = appsv1alpha1.ConfigParams{
Content: &content,
Parameters: params.Parameters,
Content: &content,
}
}

Expand All @@ -206,9 +218,30 @@ func updateParameters(item *appsv1alpha1.ConfigurationItemDetail, key string, pa
for _, parameter := range parameters {
updatedParams[parameter.Key] = parameter.Value
}

params, ok := item.ConfigFileParams[key]
if !ok {
item.ConfigFileParams[key] = appsv1alpha1.ConfigParams{
Parameters: updatedParams,
}
return
}

item.ConfigFileParams[key] = appsv1alpha1.ConfigParams{
Parameters: updatedParams,
Content: params.Content,
Parameters: mergeMaps(params.Parameters, updatedParams),
}
}

func mergeMaps(m1 map[string]*string, m2 map[string]*string) map[string]*string {
merged := make(map[string]*string)
for key, value := range m1 {
merged[key] = value
}
for key, value := range m2 {
merged[key] = value
}
return merged
}

func (p *pipeline) doMerge() error {
Expand Down
3 changes: 2 additions & 1 deletion internal/configuration/core/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package core
import (
"context"
"regexp"
"strings"

"github.com/spf13/cast"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -41,7 +42,7 @@ const pattern = `^[a-z0-9A-Z]([a-zA-Z0-9\.\-\_]*[a-zA-Z0-9])?$`
var regxPattern = regexp.MustCompile(pattern)

func FromValueToString(val interface{}) string {
str := cast.ToString(val)
str := strings.Trim(cast.ToString(val), ` '"`)
if regxPattern.MatchString(str) {
return str
}
Expand Down

0 comments on commit c155c89

Please sign in to comment.