Skip to content

Commit eb660ba

Browse files
committed
Fix 2.
1 parent f73848f commit eb660ba

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

pkg/cmd/server/kubernetes/node/options/options.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package node
33
import (
44
"fmt"
55
"net"
6+
"regexp"
67
"sort"
8+
//"strconv"
79
"strings"
810

911
"k8s.io/apimachinery/pkg/util/sets"
@@ -17,6 +19,21 @@ import (
1719
"github.com/openshift/origin/pkg/network"
1820
)
1921

22+
// safeArgRegexp matches only characters that are known safe. DO NOT add to this list
23+
// without fully considering whether that new character can be used to break shell escaping
24+
// rules.
25+
var safeArgRegexp = regexp.MustCompile(`^[\da-zA-Z\-=_\.,/\:]+$`)
26+
27+
// shellEscapeArg quotes an argument if it contains characters that my cause a shell
28+
// interpreter to split the single argument into multiple.
29+
func shellEscapeArg(s string) string {
30+
if safeArgRegexp.MatchString(s) {
31+
return s
32+
}
33+
//return strconv.Quote(s)
34+
return fmt.Sprintf("\"%v\"", s)
35+
}
36+
2037
// ComputeKubeletFlags returns the flags to use when starting the kubelet.
2138
func ComputeKubeletFlags(startingArgs map[string][]string, options configapi.NodeConfig) ([]string, error) {
2239
args := map[string][]string{}
@@ -127,7 +144,11 @@ func ComputeKubeletFlags(startingArgs map[string][]string, options configapi.Nod
127144
var arguments []string
128145
for _, key := range keys {
129146
for _, token := range args[key] {
130-
arguments = append(arguments, fmt.Sprintf("--%s=%v", key, token))
147+
if len(token) > 0 {
148+
arguments = append(arguments, fmt.Sprintf("--%s=%v", key, shellEscapeArg(token)))
149+
} else {
150+
arguments = append(arguments, fmt.Sprintf("--%s=%v", key, token))
151+
}
131152
}
132153
}
133154
return arguments, nil

pkg/cmd/server/origin/node/node.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package node
22

33
import (
44
"fmt"
5-
"regexp"
6-
"strconv"
75
"strings"
86

97
"github.com/golang/glog"
@@ -12,20 +10,6 @@ import (
1210
cmdutil "github.com/openshift/origin/pkg/cmd/util"
1311
)
1412

15-
// safeArgRegexp matches only characters that are known safe. DO NOT add to this list
16-
// without fully considering whether that new character can be used to break shell escaping
17-
// rules.
18-
var safeArgRegexp = regexp.MustCompile(`^[\da-zA-Z\-=_\.,/\:]+$`)
19-
20-
// shellEscapeArg quotes an argument if it contains characters that my cause a shell
21-
// interpreter to split the single argument into multiple.
22-
func shellEscapeArg(s string) string {
23-
if safeArgRegexp.MatchString(s) {
24-
return s
25-
}
26-
return strconv.Quote(s)
27-
}
28-
2913
// FinalizeNodeConfig controls the node configuration before it is used by the Kubelet
3014
func FinalizeNodeConfig(nodeConfig *configapi.NodeConfig) error {
3115
if nodeConfig.DNSIP == "0.0.0.0" {
@@ -53,7 +37,7 @@ func WriteKubeletFlags(nodeConfig configapi.NodeConfig) error {
5337
}
5438
var outputArgs []string
5539
for _, s := range kubeletArgs {
56-
outputArgs = append(outputArgs, shellEscapeArg(s))
40+
outputArgs = append(outputArgs, s)
5741
}
5842
fmt.Println(strings.Join(outputArgs, " "))
5943
return nil

0 commit comments

Comments
 (0)