Skip to content

Commit

Permalink
refactor: user net/url query parameter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jpts committed Sep 24, 2022
1 parent 1d79e1b commit a440c31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
15 changes: 9 additions & 6 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,26 @@ func (c *cliSession) prepExec() (*http.Request, error) {
}

u.Path = fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/exec", c.namespace, c.opts.Pod)
query := "stdout=true&stderr=true"
query := url.Values{}
query.Add("stdout", "true")
query.Add("stderr", "true")

for _, c := range c.opts.Command {
query += "&command=" + c
query.Add("command", c)
}

if c.opts.Container != "" {
query += "&container=" + c.opts.Container
query.Add("container", c.opts.Container)
}

if c.opts.TTY {
query += "&tty=true"
query.Add("tty", "true")
}

if c.opts.Stdin {
query += "&stdin=true"
query.Add("stdin", "true")
}
u.RawQuery = query
u.RawQuery = query.Encode()

req := &http.Request{
Method: http.MethodGet,
Expand Down
13 changes: 8 additions & 5 deletions cmd/kubeletexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,22 @@ func (c *cliSession) prepKubeletExec() (*http.Request, error) {
}

u.Path = fmt.Sprintf("/exec/%s/%s/%s", c.namespace, c.opts.Pod, ctrName)
query := "output=1&error=1"
query := url.Values{}
query.Add("output", "1")
query.Add("error", "1")

for _, c := range c.opts.Command {
query += "&command=" + c
query.Add("command", c)
}

if c.opts.TTY {
query += "&tty=1"
query.Add("tty", "1")
}

if c.opts.Stdin {
query += "&input=1"
query.Add("input", "1")
}
u.RawQuery = query
u.RawQuery = query.Encode()

req := &http.Request{
Method: http.MethodGet,
Expand Down

0 comments on commit a440c31

Please sign in to comment.