Commit 4bd692a3 authored by Alexander Kanevskiy's avatar Alexander Kanevskiy

kubeadm: Utilize transport defaults from API machinery for http calls

Default Go HTTP transport does not allow to use CIDR notations in NO_PROXY variables, thus for certain HTTP calls that is done inside kubeadm user needs to put explicitly multiple IP addresses. For most of calls done via API machinery it is get solved by setting different Proxy resolver. This patch allows to use CIDR notations in NO_PROXY variables for currently all other HTTP calls that is made inside kubeadm.
parent d12d711b
...@@ -11,6 +11,7 @@ go_library( ...@@ -11,6 +11,7 @@ go_library(
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/discovery/https", importpath = "k8s.io/kubernetes/cmd/kubeadm/app/discovery/https",
deps = [ deps = [
"//cmd/kubeadm/app/discovery/file:go_default_library", "//cmd/kubeadm/app/discovery/file:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library", "//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library", "//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
], ],
......
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
netutil "k8s.io/apimachinery/pkg/util/net"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/kubernetes/cmd/kubeadm/app/discovery/file" "k8s.io/kubernetes/cmd/kubeadm/app/discovery/file"
...@@ -29,7 +30,8 @@ import ( ...@@ -29,7 +30,8 @@ import (
// securely to the API Server using the provided CA cert and // securely to the API Server using the provided CA cert and
// optionally refreshes the cluster-info information from the cluster-info ConfigMap // optionally refreshes the cluster-info information from the cluster-info ConfigMap
func RetrieveValidatedClusterInfo(httpsURL string) (*clientcmdapi.Cluster, error) { func RetrieveValidatedClusterInfo(httpsURL string) (*clientcmdapi.Cluster, error) {
response, err := http.Get(httpsURL) client := &http.Client{Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
response, err := client.Get(httpsURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -332,7 +332,7 @@ func (hst HTTPProxyCheck) Check() (warnings, errors []error) { ...@@ -332,7 +332,7 @@ func (hst HTTPProxyCheck) Check() (warnings, errors []error) {
return nil, []error{err} return nil, []error{err}
} }
proxy, err := http.DefaultTransport.(*http.Transport).Proxy(req) proxy, err := netutil.SetOldTransportDefaults(&http.Transport{}).Proxy(req)
if err != nil { if err != nil {
return nil, []error{err} return nil, []error{err}
} }
...@@ -670,15 +670,15 @@ func (evc ExternalEtcdVersionCheck) configCertAndKey(config *tls.Config) (*tls.C ...@@ -670,15 +670,15 @@ func (evc ExternalEtcdVersionCheck) configCertAndKey(config *tls.Config) (*tls.C
func (evc ExternalEtcdVersionCheck) getHTTPClient(config *tls.Config) *http.Client { func (evc ExternalEtcdVersionCheck) getHTTPClient(config *tls.Config) *http.Client {
if config != nil { if config != nil {
transport := &http.Transport{ transport := netutil.SetOldTransportDefaults(&http.Transport{
TLSClientConfig: config, TLSClientConfig: config,
} })
return &http.Client{ return &http.Client{
Transport: transport, Transport: transport,
Timeout: externalEtcdRequestTimeout, Timeout: externalEtcdRequestTimeout,
} }
} }
return &http.Client{Timeout: externalEtcdRequestTimeout} return &http.Client{Timeout: externalEtcdRequestTimeout, Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
} }
func getEtcdVersionResponse(client *http.Client, url string, target interface{}) error { func getEtcdVersionResponse(client *http.Client, url string, target interface{}) error {
......
...@@ -23,6 +23,7 @@ go_library( ...@@ -23,6 +23,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library", "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
], ],
) )
......
...@@ -28,6 +28,7 @@ go_library( ...@@ -28,6 +28,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/dynamic:go_default_library", "//vendor/k8s.io/client-go/dynamic:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library", "//vendor/k8s.io/client-go/kubernetes:go_default_library",
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
netutil "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/cmd/kubeadm/app/constants" "k8s.io/kubernetes/cmd/kubeadm/app/constants"
...@@ -130,7 +131,8 @@ func (w *KubeWaiter) WaitForPodToDisappear(podName string) error { ...@@ -130,7 +131,8 @@ func (w *KubeWaiter) WaitForPodToDisappear(podName string) error {
func (w *KubeWaiter) WaitForHealthyKubelet(initalTimeout time.Duration, healthzEndpoint string) error { func (w *KubeWaiter) WaitForHealthyKubelet(initalTimeout time.Duration, healthzEndpoint string) error {
time.Sleep(initalTimeout) time.Sleep(initalTimeout)
return TryRunCommand(func() error { return TryRunCommand(func() error {
resp, err := http.Get(healthzEndpoint) client := &http.Client{Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
resp, err := client.Get(healthzEndpoint)
if err != nil { if err != nil {
fmt.Printf("[kubelet-check] It seems like the kubelet isn't running or healthy.\n") fmt.Printf("[kubelet-check] It seems like the kubelet isn't running or healthy.\n")
fmt.Printf("[kubelet-check] The HTTP call equal to 'curl -sSL %s' failed with error: %v.\n", healthzEndpoint, err) fmt.Printf("[kubelet-check] The HTTP call equal to 'curl -sSL %s' failed with error: %v.\n", healthzEndpoint, err)
......
...@@ -22,6 +22,8 @@ import ( ...@@ -22,6 +22,8 @@ import (
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
netutil "k8s.io/apimachinery/pkg/util/net"
) )
var ( var (
...@@ -131,7 +133,8 @@ func splitVersion(version string) (string, string, error) { ...@@ -131,7 +133,8 @@ func splitVersion(version string) (string, string, error) {
// Internal helper: return content of URL // Internal helper: return content of URL
func fetchFromURL(url string) (string, error) { func fetchFromURL(url string) (string, error) {
resp, err := http.Get(url) client := &http.Client{Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
resp, err := client.Get(url)
if err != nil { if err != nil {
return "", fmt.Errorf("unable to get URL %q: %s", url, err.Error()) return "", fmt.Errorf("unable to get URL %q: %s", url, err.Error())
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment