Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
tools/lxdclient: use utils/proxy.DefaultConfig #7014
Conversation
|
P.S. here's the proxy program I used for testing: package main
import (
"log"
"net"
"net/http"
"github.com/elazarl/goproxy"
)
func main() {
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
proxy.OnRequest().HandleConnectFunc(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
if addr, _, _ := net.SplitHostPort(host); addr == "10.250.243.1" {
return goproxy.RejectConnect, host
}
return goproxy.OkConnect, host
})
log.Fatal(http.ListenAndServe(":8080", proxy))
} |
jameinel
approved these changes
Feb 21, 2017
This feels like something where we need a more concrete upstream fix. Either a shared library that LXD and Juju use, or a patch towards Go's core library that can at least have a way to trigger "reread the ENV variables because I just set them."
I can live with this, though monkey-patching the internal transport of a client always feels like you're a bit lucky they exposed it at all.
| @@ -262,6 +264,12 @@ func newRawClient(remote Remote) (*lxd.Client, error) { | ||
| return nil, errors.Trace(err) | ||
| } | ||
| + // Replace the proxy handler with the one managed | ||
| + // by Juju's worker/proxyupdater. | ||
| + if tr, ok := client.Http.Transport.(*http.Transport); ok && tr.Proxy != nil { |
jameinel
Feb 21, 2017
Owner
While this is a bit ugly, if we're going to do it, shouldn't we be universally setting tr.Proxy and not just setting it if there is already a proxy? (from what I can tell, its probably always setting ProxyFromEnvironment, which also does the read-only-once stuff.)
axw
Feb 21, 2017
Member
Yes, it does always do that. I've made it unconditional though, in case LXD changes that.
Indeed. We have a test that should protect us, but it would be good to have a statement of support for this in the LXD client docs. |
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
axw commentedFeb 21, 2017
•
Edited 1 time
-
axw
Feb 21, 2017
Description of change
Use the Juju-managed HTTP proxy configuration
when making LXD client connections, rather than
the default proxy handler that looks at the
environment variables once and only once.
As well as this, initialise the proxy config
for the client, so that $http_proxy and co. will
be picked up by the client.
QA steps
(Address of LXD host on lxdbr0 is 10.250.243.1)
lxc image alias delete juju/trusty/amd64if necessaryThe two machines should be added successfully.
Documentation changes
None.
Bug reference
Fixes https://bugs.launchpad.net/juju/+bug/1642385