mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-24 20:47:56 +00:00
published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub) copied from https://github.com/kubernetes/kubernetes.git, branch master, last commit is e56cfc5322138aa23e6418ee30a6ab54c7c6fe8c
This commit is contained in:
@@ -25,10 +25,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
"k8s.io/client-go/1.5/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@@ -27,13 +27,14 @@ import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
"k8s.io/client-go/1.5/pkg/api/errors"
|
||||
"k8s.io/client-go/1.5/pkg/api/testapi"
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
"k8s.io/client-go/1.5/pkg/util/diff"
|
||||
utiltesting "k8s.io/client-go/1.5/pkg/util/testing"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/errors"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/apimachinery/registered"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/util/diff"
|
||||
utiltesting "k8s.io/client-go/pkg/util/testing"
|
||||
)
|
||||
|
||||
type TestParam struct {
|
||||
@@ -185,7 +186,7 @@ func validate(testParam TestParam, t *testing.T, body []byte, fakeHandler *utilt
|
||||
t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", testParam.expStatus, statusOut)
|
||||
}
|
||||
}
|
||||
fakeHandler.ValidateRequest(t, "/"+testapi.Default.GroupVersion().String()+"/test", "GET", nil)
|
||||
fakeHandler.ValidateRequest(t, "/"+registered.GroupOrDie(api.GroupName).GroupVersion.String()+"/test", "GET", nil)
|
||||
|
||||
}
|
||||
|
||||
@@ -272,7 +273,7 @@ func restClient(testServer *httptest.Server) (*RESTClient, error) {
|
||||
c, err := RESTClientFor(&Config{
|
||||
Host: testServer.URL,
|
||||
ContentConfig: ContentConfig{
|
||||
GroupVersion: testapi.Default.GroupVersion(),
|
||||
GroupVersion: ®istered.GroupOrDie(api.GroupName).GroupVersion,
|
||||
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
||||
},
|
||||
Username: "user",
|
||||
|
@@ -29,13 +29,13 @@ import (
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
certutil "k8s.io/client-go/1.5/pkg/util/cert"
|
||||
"k8s.io/client-go/1.5/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/1.5/pkg/version"
|
||||
clientcmdapi "k8s.io/client-go/1.5/tools/clientcmd/api"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
certutil "k8s.io/client-go/pkg/util/cert"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/pkg/version"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -189,6 +189,9 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
||||
var httpClient *http.Client
|
||||
if transport != http.DefaultTransport {
|
||||
httpClient = &http.Client{Transport: transport}
|
||||
if config.Timeout > 0 {
|
||||
httpClient.Timeout = config.Timeout
|
||||
}
|
||||
}
|
||||
|
||||
return NewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, qps, burst, config.RateLimiter, httpClient)
|
||||
@@ -214,6 +217,9 @@ func UnversionedRESTClientFor(config *Config) (*RESTClient, error) {
|
||||
var httpClient *http.Client
|
||||
if transport != http.DefaultTransport {
|
||||
httpClient = &http.Client{Transport: transport}
|
||||
if config.Timeout > 0 {
|
||||
httpClient.Timeout = config.Timeout
|
||||
}
|
||||
}
|
||||
|
||||
versionConfig := config.ContentConfig
|
||||
@@ -337,3 +343,26 @@ func AddUserAgent(config *Config, userAgent string) *Config {
|
||||
config.UserAgent = fullUserAgent
|
||||
return config
|
||||
}
|
||||
|
||||
// AnonymousClientConfig returns a copy of the given config with all user credentials (cert/key, bearer token, and username/password) removed
|
||||
func AnonymousClientConfig(config *Config) *Config {
|
||||
// copy only known safe fields
|
||||
return &Config{
|
||||
Host: config.Host,
|
||||
APIPath: config.APIPath,
|
||||
Prefix: config.Prefix,
|
||||
ContentConfig: config.ContentConfig,
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CAFile: config.TLSClientConfig.CAFile,
|
||||
CAData: config.TLSClientConfig.CAData,
|
||||
},
|
||||
RateLimiter: config.RateLimiter,
|
||||
Insecure: config.Insecure,
|
||||
UserAgent: config.UserAgent,
|
||||
Transport: config.Transport,
|
||||
WrapTransport: config.WrapTransport,
|
||||
QPS: config.QPS,
|
||||
Burst: config.Burst,
|
||||
Timeout: config.Timeout,
|
||||
}
|
||||
}
|
||||
|
@@ -17,10 +17,22 @@ limitations under the License.
|
||||
package rest
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api/testapi"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/apimachinery/registered"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/util/diff"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
func TestIsConfigTransportTLS(t *testing.T) {
|
||||
@@ -90,10 +102,143 @@ func TestRESTClientRequires(t *testing.T) {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: testapi.Default.NegotiatedSerializer()}}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}); err == nil {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: ®istered.GroupOrDie(api.GroupName).GroupVersion}}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion(), NegotiatedSerializer: testapi.Default.NegotiatedSerializer()}}); err != nil {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: ®istered.GroupOrDie(api.GroupName).GroupVersion, NegotiatedSerializer: testapi.Default.NegotiatedSerializer()}}); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeLimiter struct {
|
||||
FakeSaturation float64
|
||||
FakeQPS float32
|
||||
}
|
||||
|
||||
func (t *fakeLimiter) TryAccept() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *fakeLimiter) Saturation() float64 {
|
||||
return t.FakeSaturation
|
||||
}
|
||||
|
||||
func (t *fakeLimiter) QPS() float32 {
|
||||
return t.FakeQPS
|
||||
}
|
||||
|
||||
func (t *fakeLimiter) Stop() {}
|
||||
|
||||
func (t *fakeLimiter) Accept() {}
|
||||
|
||||
type fakeCodec struct{}
|
||||
|
||||
func (c *fakeCodec) Decode([]byte, *unversioned.GroupVersionKind, runtime.Object) (runtime.Object, *unversioned.GroupVersionKind, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (c *fakeCodec) Encode(obj runtime.Object, stream io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type fakeRoundTripper struct{}
|
||||
|
||||
func (r *fakeRoundTripper) RoundTrip(*http.Request) (*http.Response, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var fakeWrapperFunc = func(http.RoundTripper) http.RoundTripper {
|
||||
return &fakeRoundTripper{}
|
||||
}
|
||||
|
||||
type fakeNegotiatedSerializer struct{}
|
||||
|
||||
func (n *fakeNegotiatedSerializer) SupportedMediaTypes() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (n *fakeNegotiatedSerializer) SerializerForMediaType(mediaType string, params map[string]string) (s runtime.SerializerInfo, ok bool) {
|
||||
return runtime.SerializerInfo{}, true
|
||||
}
|
||||
|
||||
func (n *fakeNegotiatedSerializer) SupportedStreamingMediaTypes() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (n *fakeNegotiatedSerializer) StreamingSerializerForMediaType(mediaType string, params map[string]string) (s runtime.StreamSerializerInfo, ok bool) {
|
||||
return runtime.StreamSerializerInfo{}, true
|
||||
}
|
||||
|
||||
func (n *fakeNegotiatedSerializer) EncoderForVersion(serializer runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
|
||||
return &fakeCodec{}
|
||||
}
|
||||
|
||||
func (n *fakeNegotiatedSerializer) DecoderToVersion(serializer runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder {
|
||||
return &fakeCodec{}
|
||||
}
|
||||
|
||||
func TestAnonymousConfig(t *testing.T) {
|
||||
f := fuzz.New().NilChance(0.0).NumElements(1, 1)
|
||||
f.Funcs(
|
||||
func(r *runtime.Codec, f fuzz.Continue) {
|
||||
codec := &fakeCodec{}
|
||||
f.Fuzz(codec)
|
||||
*r = codec
|
||||
},
|
||||
func(r *http.RoundTripper, f fuzz.Continue) {
|
||||
roundTripper := &fakeRoundTripper{}
|
||||
f.Fuzz(roundTripper)
|
||||
*r = roundTripper
|
||||
},
|
||||
func(fn *func(http.RoundTripper) http.RoundTripper, f fuzz.Continue) {
|
||||
*fn = fakeWrapperFunc
|
||||
},
|
||||
func(r *runtime.NegotiatedSerializer, f fuzz.Continue) {
|
||||
serializer := &fakeNegotiatedSerializer{}
|
||||
f.Fuzz(serializer)
|
||||
*r = serializer
|
||||
},
|
||||
func(r *flowcontrol.RateLimiter, f fuzz.Continue) {
|
||||
limiter := &fakeLimiter{}
|
||||
f.Fuzz(limiter)
|
||||
*r = limiter
|
||||
},
|
||||
// Authentication does not require fuzzer
|
||||
func(r *AuthProviderConfigPersister, f fuzz.Continue) {},
|
||||
func(r *clientcmdapi.AuthProviderConfig, f fuzz.Continue) {
|
||||
r.Config = map[string]string{}
|
||||
},
|
||||
)
|
||||
for i := 0; i < 20; i++ {
|
||||
original := &Config{}
|
||||
f.Fuzz(original)
|
||||
actual := AnonymousClientConfig(original)
|
||||
expected := *original
|
||||
|
||||
// this is the list of known security related fields, add to this list if a new field
|
||||
// is added to Config, update AnonymousClientConfig to preserve the field otherwise.
|
||||
expected.Impersonate = ""
|
||||
expected.BearerToken = ""
|
||||
expected.Username = ""
|
||||
expected.Password = ""
|
||||
expected.AuthProvider = nil
|
||||
expected.AuthConfigPersister = nil
|
||||
expected.TLSClientConfig.CertData = nil
|
||||
expected.TLSClientConfig.CertFile = ""
|
||||
expected.TLSClientConfig.KeyData = nil
|
||||
expected.TLSClientConfig.KeyFile = ""
|
||||
|
||||
// The DeepEqual cannot handle the func comparison, so we just verify if the
|
||||
// function return the expected object.
|
||||
if actual.WrapTransport == nil || !reflect.DeepEqual(expected.WrapTransport(nil), &fakeRoundTripper{}) {
|
||||
t.Fatalf("AnonymousClientConfig dropped the WrapTransport field")
|
||||
} else {
|
||||
actual.WrapTransport = nil
|
||||
expected.WrapTransport = nil
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*actual, expected) {
|
||||
t.Fatalf("AnonymousClientConfig dropped unexpected fields, identify whether they are security related or not: %s", diff.ObjectGoPrintDiff(expected, actual))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
clientcmdapi "k8s.io/client-go/1.5/tools/clientcmd/api"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
type AuthProvider interface {
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
clientcmdapi "k8s.io/client-go/1.5/tools/clientcmd/api"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
func TestAuthPluginWrapTransport(t *testing.T) {
|
||||
@@ -61,7 +61,7 @@ func TestAuthPluginWrapTransport(t *testing.T) {
|
||||
if len(tc.plugin) != 0 {
|
||||
c.AuthProvider = &clientcmdapi.AuthProviderConfig{Name: tc.plugin}
|
||||
}
|
||||
tConfig, err := c.transportConfig()
|
||||
tConfig, err := c.TransportConfig()
|
||||
if err != nil {
|
||||
// Unknown/bad plugins are expected to fail here.
|
||||
if !tc.expectErr {
|
||||
|
@@ -32,20 +32,20 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/client-go/1.5/pkg/api/errors"
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/api/v1"
|
||||
pathvalidation "k8s.io/client-go/1.5/pkg/api/validation/path"
|
||||
"k8s.io/client-go/1.5/pkg/fields"
|
||||
"k8s.io/client-go/1.5/pkg/labels"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
"k8s.io/client-go/1.5/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/client-go/1.5/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/1.5/pkg/util/net"
|
||||
"k8s.io/client-go/1.5/pkg/util/sets"
|
||||
"k8s.io/client-go/1.5/pkg/watch"
|
||||
"k8s.io/client-go/1.5/pkg/watch/versioned"
|
||||
"k8s.io/client-go/1.5/tools/metrics"
|
||||
"k8s.io/client-go/pkg/api/errors"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
pathvalidation "k8s.io/client-go/pkg/api/validation/path"
|
||||
"k8s.io/client-go/pkg/fields"
|
||||
"k8s.io/client-go/pkg/labels"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/pkg/util/net"
|
||||
"k8s.io/client-go/pkg/util/sets"
|
||||
"k8s.io/client-go/pkg/watch"
|
||||
"k8s.io/client-go/pkg/watch/versioned"
|
||||
"k8s.io/client-go/tools/metrics"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -357,8 +357,9 @@ var fieldMappings = versionToResourceToFieldMapping{
|
||||
nodeUnschedulable: nodeUnschedulable,
|
||||
},
|
||||
"pods": clientFieldNameToAPIVersionFieldName{
|
||||
podHost: podHost,
|
||||
podStatus: podStatus,
|
||||
objectNameField: objectNameField,
|
||||
podHost: podHost,
|
||||
podStatus: podStatus,
|
||||
},
|
||||
"secrets": clientFieldNameToAPIVersionFieldName{
|
||||
secretType: secretType,
|
||||
@@ -889,10 +890,11 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
||||
}
|
||||
|
||||
if glog.V(8) {
|
||||
switch {
|
||||
case bytes.IndexFunc(body, func(r rune) bool { return r < 0x0a }) != -1:
|
||||
if bytes.IndexFunc(body, func(r rune) bool {
|
||||
return r < 0x0a
|
||||
}) != -1 {
|
||||
glog.Infof("Response Body:\n%s", hex.Dump(body))
|
||||
default:
|
||||
} else {
|
||||
glog.Infof("Response Body: %s", string(body))
|
||||
}
|
||||
}
|
||||
|
@@ -31,21 +31,22 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
apierrors "k8s.io/client-go/1.5/pkg/api/errors"
|
||||
"k8s.io/client-go/1.5/pkg/api/testapi"
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/api/v1"
|
||||
"k8s.io/client-go/1.5/pkg/labels"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
"k8s.io/client-go/1.5/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/client-go/1.5/pkg/util/clock"
|
||||
"k8s.io/client-go/1.5/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/1.5/pkg/util/httpstream"
|
||||
"k8s.io/client-go/1.5/pkg/util/intstr"
|
||||
utiltesting "k8s.io/client-go/1.5/pkg/util/testing"
|
||||
"k8s.io/client-go/1.5/pkg/watch"
|
||||
"k8s.io/client-go/1.5/pkg/watch/versioned"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
apierrors "k8s.io/client-go/pkg/api/errors"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apimachinery/registered"
|
||||
"k8s.io/client-go/pkg/labels"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/client-go/pkg/util/clock"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/pkg/util/httpstream"
|
||||
"k8s.io/client-go/pkg/util/intstr"
|
||||
utiltesting "k8s.io/client-go/pkg/util/testing"
|
||||
"k8s.io/client-go/pkg/watch"
|
||||
"k8s.io/client-go/pkg/watch/versioned"
|
||||
)
|
||||
|
||||
func TestNewRequestSetsAccept(t *testing.T) {
|
||||
@@ -89,7 +90,7 @@ func TestRequestSetsHeaders(t *testing.T) {
|
||||
func TestRequestWithErrorWontChange(t *testing.T) {
|
||||
original := Request{
|
||||
err: errors.New("test"),
|
||||
content: ContentConfig{GroupVersion: testapi.Default.GroupVersion()},
|
||||
content: ContentConfig{GroupVersion: ®istered.GroupOrDie(api.GroupName).GroupVersion},
|
||||
}
|
||||
r := original
|
||||
changed := r.Param("foo", "bar").
|
||||
@@ -273,7 +274,7 @@ func (obj NotAnAPIObject) SetGroupVersionKind(gvk *unversioned.GroupVersionKind)
|
||||
|
||||
func defaultContentConfig() ContentConfig {
|
||||
return ContentConfig{
|
||||
GroupVersion: testapi.Default.GroupVersion(),
|
||||
GroupVersion: ®istered.GroupOrDie(api.GroupName).GroupVersion,
|
||||
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
||||
}
|
||||
}
|
||||
@@ -1153,7 +1154,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
requestURL := testapi.Default.ResourcePathWithPrefix("foo", "bar", "", "baz")
|
||||
requestURL += "?" + unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String()) + "=name%3Dfoo&timeout=1s"
|
||||
requestURL += "?" + unversioned.LabelSelectorQueryParam(registered.GroupOrDie(api.GroupName).GroupVersion.String()) + "=name%3Dfoo&timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
|
||||
}
|
||||
|
||||
@@ -1193,7 +1194,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
requestURL := testapi.Default.ResourcePath("foo", "", "bar/baz")
|
||||
requestURL += "?" + unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String()) + "=name%3Dfoo&timeout=1s"
|
||||
requestURL += "?" + unversioned.LabelSelectorQueryParam(registered.GroupOrDie(api.GroupName).GroupVersion.String()) + "=name%3Dfoo&timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
|
||||
}
|
||||
|
||||
|
@@ -20,13 +20,13 @@ import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/client-go/1.5/transport"
|
||||
"k8s.io/client-go/transport"
|
||||
)
|
||||
|
||||
// TLSConfigFor returns a tls.Config that will provide the transport level security defined
|
||||
// by the provided Config. Will return nil if no transport level security is requested.
|
||||
func TLSConfigFor(config *Config) (*tls.Config, error) {
|
||||
cfg, err := config.transportConfig()
|
||||
cfg, err := config.TransportConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func TLSConfigFor(config *Config) (*tls.Config, error) {
|
||||
// or transport level security defined by the provided Config. Will return the
|
||||
// default http.DefaultTransport if no special case behavior is needed.
|
||||
func TransportFor(config *Config) (http.RoundTripper, error) {
|
||||
cfg, err := config.transportConfig()
|
||||
cfg, err := config.TransportConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -49,15 +49,15 @@ func TransportFor(config *Config) (http.RoundTripper, error) {
|
||||
// the underlying connection (like WebSocket or HTTP2 clients). Pure HTTP clients should use
|
||||
// the higher level TransportFor or RESTClientFor methods.
|
||||
func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTripper, error) {
|
||||
cfg, err := config.transportConfig()
|
||||
cfg, err := config.TransportConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return transport.HTTPWrappersForConfig(cfg, rt)
|
||||
}
|
||||
|
||||
// transportConfig converts a client config to an appropriate transport config.
|
||||
func (c *Config) transportConfig() (*transport.Config, error) {
|
||||
// TransportConfig converts a client config to an appropriate transport config.
|
||||
func (c *Config) TransportConfig() (*transport.Config, error) {
|
||||
wt := c.WrapTransport
|
||||
if c.AuthProvider != nil {
|
||||
provider, err := GetAuthProvider(c.Host, c.AuthProvider, c.AuthConfigPersister)
|
||||
|
@@ -21,7 +21,7 @@ import (
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
// DefaultServerURL converts a host, host:port, or URL string to the default base server API path
|
||||
|
@@ -20,7 +20,8 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/apimachinery/registered"
|
||||
)
|
||||
|
||||
func TestValidatesHostParameter(t *testing.T) {
|
||||
@@ -31,17 +32,17 @@ func TestValidatesHostParameter(t *testing.T) {
|
||||
URL string
|
||||
Err bool
|
||||
}{
|
||||
{"127.0.0.1", "", "http://127.0.0.1/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"127.0.0.1:8080", "", "http://127.0.0.1:8080/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"foo.bar.com", "", "http://foo.bar.com/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"http://host/prefix", "", "http://host/prefix/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"http://host", "", "http://host/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"http://host", "/", "http://host/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"http://host", "/other", "http://host/other/" + testapi.Default.GroupVersion().Version, false},
|
||||
{"127.0.0.1", "", "http://127.0.0.1/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"127.0.0.1:8080", "", "http://127.0.0.1:8080/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"foo.bar.com", "", "http://foo.bar.com/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"http://host/prefix", "", "http://host/prefix/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"http://host", "", "http://host/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"http://host", "/", "http://host/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"http://host", "/other", "http://host/other/" + registered.GroupOrDie(api.GroupName).GroupVersion.Version, false},
|
||||
{"host/server", "", "", true},
|
||||
}
|
||||
for i, testCase := range testCases {
|
||||
u, versionedAPIPath, err := DefaultServerURL(testCase.Host, testCase.APIPath, *testapi.Default.GroupVersion(), false)
|
||||
u, versionedAPIPath, err := DefaultServerURL(testCase.Host, testCase.APIPath, registered.GroupOrDie(api.GroupName).GroupVersion, false)
|
||||
switch {
|
||||
case err == nil && testCase.Err:
|
||||
t.Errorf("expected error but was nil")
|
||||
|
@@ -21,8 +21,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/client-go/1.5/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/1.5/pkg/util/sets"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/pkg/util/sets"
|
||||
)
|
||||
|
||||
// Set of resp. Codes that we backoff for.
|
||||
|
@@ -21,7 +21,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/util/flowcontrol"
|
||||
"k8s.io/client-go/pkg/util/flowcontrol"
|
||||
)
|
||||
|
||||
func parse(raw string) *url.URL {
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
const (
|
||||
|
Reference in New Issue
Block a user