No Proxy for Dashboard and moving logic to proxy package
parent
ddb95e1488
commit
8120cdd505
|
@ -59,7 +59,7 @@ var dashboardCmd = &cobra.Command{
|
|||
if err != nil && !os.IsNotExist(err) {
|
||||
console.ErrLn("Error loading profile config: %v", err)
|
||||
}
|
||||
proxy.UpdateEnv(cc.KubernetesConfig.NodeIP, "NO_PROXY")
|
||||
proxy.UpdateEnv(cc.KubernetesConfig.NodeIP, "NO_PROXY") // to be used for http get calls
|
||||
|
||||
kubectl, err := exec.LookPath("kubectl")
|
||||
if err != nil {
|
||||
|
|
|
@ -19,10 +19,13 @@ package proxy
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// EnvVars are variables we plumb through to the underlying container runtime
|
||||
|
@ -97,3 +100,21 @@ func isValidEnv(env string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetNoProxyK8s takes a k8s config and upadates the proxy
|
||||
func SetNoProxyK8s(cfg *rest.Config) *rest.Config {
|
||||
wt := cfg.WrapTransport // Config might already have a transport wrapper
|
||||
cfg.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
|
||||
if wt != nil {
|
||||
rt = wt(rt)
|
||||
}
|
||||
if ht, ok := rt.(*http.Transport); ok {
|
||||
ht.Proxy = nil
|
||||
rt = ht
|
||||
} else {
|
||||
glog.Errorf("Error while casting RoundTripper to *http.Transport : %v", ok)
|
||||
}
|
||||
return rt
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"github.com/pkg/browser"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
@ -40,6 +40,7 @@ import (
|
|||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/console"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/proxy"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
|
@ -84,6 +85,7 @@ func (*K8sClientGetter) GetClientset(timeout time.Duration) (*kubernetes.Clients
|
|||
return nil, fmt.Errorf("Error creating kubeConfig: %v", err)
|
||||
}
|
||||
clientConfig.Timeout = timeout
|
||||
clientConfig = proxy.SetNoProxyK8s(clientConfig)
|
||||
client, err := kubernetes.NewForConfig(clientConfig)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error creating new client from kubeConfig.ClientConfig()")
|
||||
|
|
|
@ -18,7 +18,6 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -34,10 +33,10 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
rest "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/minikube/pkg/minikube/proxy"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -69,25 +68,6 @@ func (s *PodStore) Stop() {
|
|||
close(s.stopCh)
|
||||
}
|
||||
|
||||
// setNoProxyConfig takes a k8s config and returns a config without proxy
|
||||
// to avoid connectivity issues when http(s) proxy is used.
|
||||
func setNoProxyConfig(cfg *rest.Config) *rest.Config {
|
||||
wt := cfg.WrapTransport // Config might already have a transport wrapper
|
||||
cfg.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
|
||||
if wt != nil {
|
||||
rt = wt(rt)
|
||||
}
|
||||
if ht, ok := rt.(*http.Transport); ok {
|
||||
ht.Proxy = nil
|
||||
rt = ht
|
||||
} else {
|
||||
glog.Errorf("Error while casting RoundTripper to *http.Transport : %v", ok)
|
||||
}
|
||||
return rt
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
// GetClient gets the client from config
|
||||
func GetClient() (kubernetes.Interface, error) {
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
|
@ -97,7 +77,7 @@ func GetClient() (kubernetes.Interface, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("Error creating kubeConfig: %v", err)
|
||||
}
|
||||
config = setNoProxyConfig(config)
|
||||
config = proxy.SetNoProxyK8s(config)
|
||||
client, err := kubernetes.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error creating new client from kubeConfig.ClientConfig()")
|
||||
|
|
Loading…
Reference in New Issue