Skip to content

Commit

Permalink
Fix #1151: Probabilistic panic when create clusters with multiple nodes
Browse files Browse the repository at this point in the history
Signed-off-by: cumirror <jacksontong@yunify.com>
  • Loading branch information
jacksontong committed Mar 24, 2022
1 parent c81fe6f commit 1358b2a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/core/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package util
import (
"bytes"
"fmt"
"github.com/pkg/errors"
"math"
"os"
"os/exec"
Expand All @@ -28,6 +27,8 @@ import (
"sort"
"strings"
"text/template"

"github.com/pkg/errors"
)

type Data map[string]interface{}
Expand Down Expand Up @@ -92,20 +93,27 @@ func homeWindows() (string, error) {
}

func GetArgs(argsMap map[string]string, args []string) ([]string, map[string]string) {
for _, arg := range args {
targetMap := make(map[string]string, len(argsMap))
for k, v := range argsMap {
targetMap[k] = v
}
targetSlice := make([]string, len(args))
copy(targetSlice, args)

for _, arg := range targetSlice {
splitArg := strings.SplitN(arg, "=", 2)
if len(splitArg) < 2 {
continue
}
argsMap[splitArg[0]] = splitArg[1]
targetMap[splitArg[0]] = splitArg[1]
}

for arg, value := range argsMap {
for arg, value := range targetMap {
cmd := fmt.Sprintf("%s=%s", arg, value)
args = append(args, cmd)
targetSlice = append(targetSlice, cmd)
}
sort.Strings(args)
return args, argsMap
sort.Strings(targetSlice)
return targetSlice, targetMap
}

// Round returns the result of rounding 'val' according to the specified 'precision' precision (the number of digits after the decimal point)。
Expand Down

0 comments on commit 1358b2a

Please sign in to comment.