Update godeps
This commit is contained in:
parent
1c8773fc98
commit
1bc383f9c5
1723 changed files with 287976 additions and 411028 deletions
83
vendor/k8s.io/kubernetes/pkg/client/restclient/BUILD
generated
vendored
Normal file
83
vendor/k8s.io/kubernetes/pkg/client/restclient/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
"go_test",
|
||||
"cgo_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"client.go",
|
||||
"config.go",
|
||||
"plugin.go",
|
||||
"request.go",
|
||||
"transport.go",
|
||||
"url_utils.go",
|
||||
"urlbackoff.go",
|
||||
"versions.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/api/unversioned:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/api/validation/path:go_default_library",
|
||||
"//pkg/client/metrics:go_default_library",
|
||||
"//pkg/client/transport:go_default_library",
|
||||
"//pkg/client/unversioned/clientcmd/api:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/serializer/streaming:go_default_library",
|
||||
"//pkg/util/cert:go_default_library",
|
||||
"//pkg/util/flowcontrol:go_default_library",
|
||||
"//pkg/util/net:go_default_library",
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//pkg/version:go_default_library",
|
||||
"//pkg/watch:go_default_library",
|
||||
"//pkg/watch/versioned:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"client_test.go",
|
||||
"config_test.go",
|
||||
"plugin_test.go",
|
||||
"request_test.go",
|
||||
"url_utils_test.go",
|
||||
"urlbackoff_test.go",
|
||||
],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/api/testapi:go_default_library",
|
||||
"//pkg/api/unversioned:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apimachinery/registered:go_default_library",
|
||||
"//pkg/client/unversioned/clientcmd/api:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/serializer/streaming:go_default_library",
|
||||
"//pkg/util/clock:go_default_library",
|
||||
"//pkg/util/diff:go_default_library",
|
||||
"//pkg/util/flowcontrol:go_default_library",
|
||||
"//pkg/util/httpstream:go_default_library",
|
||||
"//pkg/util/intstr:go_default_library",
|
||||
"//pkg/util/testing:go_default_library",
|
||||
"//pkg/watch:go_default_library",
|
||||
"//pkg/watch/versioned:go_default_library",
|
||||
"//vendor:github.com/google/gofuzz",
|
||||
],
|
||||
)
|
||||
72
vendor/k8s.io/kubernetes/pkg/client/restclient/client.go
generated
vendored
72
vendor/k8s.io/kubernetes/pkg/client/restclient/client.go
generated
vendored
|
|
@ -18,6 +18,7 @@ package restclient
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
|
@ -38,6 +39,18 @@ const (
|
|||
envBackoffDuration = "KUBE_CLIENT_BACKOFF_DURATION"
|
||||
)
|
||||
|
||||
// Interface captures the set of operations for generically interacting with Kubernetes REST apis.
|
||||
type Interface interface {
|
||||
GetRateLimiter() flowcontrol.RateLimiter
|
||||
Verb(verb string) *Request
|
||||
Post() *Request
|
||||
Put() *Request
|
||||
Patch(pt api.PatchType) *Request
|
||||
Get() *Request
|
||||
Delete() *Request
|
||||
APIVersion() unversioned.GroupVersion
|
||||
}
|
||||
|
||||
// RESTClient imposes common Kubernetes API conventions on a set of resource paths.
|
||||
// The baseURL is expected to point to an HTTP or HTTPS path that is the parent
|
||||
// of one or more resources. The server should return a decodable API resource
|
||||
|
|
@ -54,7 +67,7 @@ type RESTClient struct {
|
|||
// contentConfig is the information used to communicate with the server.
|
||||
contentConfig ContentConfig
|
||||
|
||||
// serializers contain all serializers for undelying content type.
|
||||
// serializers contain all serializers for underlying content type.
|
||||
serializers Serializers
|
||||
|
||||
// creates BackoffManager that is passed to requests.
|
||||
|
|
@ -141,34 +154,55 @@ func readExpBackoffConfig() BackoffManager {
|
|||
}
|
||||
|
||||
// createSerializers creates all necessary serializers for given contentType.
|
||||
// TODO: the negotiated serializer passed to this method should probably return
|
||||
// serializers that control decoding and versioning without this package
|
||||
// being aware of the types. Depends on whether RESTClient must deal with
|
||||
// generic infrastructure.
|
||||
func createSerializers(config ContentConfig) (*Serializers, error) {
|
||||
negotiated := config.NegotiatedSerializer
|
||||
mediaTypes := config.NegotiatedSerializer.SupportedMediaTypes()
|
||||
contentType := config.ContentType
|
||||
info, ok := negotiated.SerializerForMediaType(contentType, nil)
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the content type specified in the client configuration is not recognized: %v", err)
|
||||
}
|
||||
info, ok := runtime.SerializerInfoForMediaType(mediaTypes, mediaType)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("serializer for %s not registered", contentType)
|
||||
if len(contentType) != 0 || len(mediaTypes) == 0 {
|
||||
return nil, fmt.Errorf("no serializers registered for %s", contentType)
|
||||
}
|
||||
info = mediaTypes[0]
|
||||
}
|
||||
streamInfo, ok := negotiated.StreamingSerializerForMediaType(contentType, nil)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("streaming serializer for %s not registered", contentType)
|
||||
|
||||
internalGV := unversioned.GroupVersions{
|
||||
{
|
||||
Group: config.GroupVersion.Group,
|
||||
Version: runtime.APIVersionInternal,
|
||||
},
|
||||
// always include the legacy group as a decoding target to handle non-error `Status` return types
|
||||
{
|
||||
Group: "",
|
||||
Version: runtime.APIVersionInternal,
|
||||
},
|
||||
}
|
||||
internalGV := unversioned.GroupVersion{
|
||||
Group: config.GroupVersion.Group,
|
||||
Version: runtime.APIVersionInternal,
|
||||
}
|
||||
return &Serializers{
|
||||
Encoder: negotiated.EncoderForVersion(info.Serializer, *config.GroupVersion),
|
||||
Decoder: negotiated.DecoderToVersion(info.Serializer, internalGV),
|
||||
StreamingSerializer: streamInfo.Serializer,
|
||||
Framer: streamInfo.Framer,
|
||||
|
||||
s := &Serializers{
|
||||
Encoder: config.NegotiatedSerializer.EncoderForVersion(info.Serializer, *config.GroupVersion),
|
||||
Decoder: config.NegotiatedSerializer.DecoderToVersion(info.Serializer, internalGV),
|
||||
|
||||
RenegotiatedDecoder: func(contentType string, params map[string]string) (runtime.Decoder, error) {
|
||||
renegotiated, ok := negotiated.SerializerForMediaType(contentType, params)
|
||||
info, ok := runtime.SerializerInfoForMediaType(mediaTypes, contentType)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("serializer for %s not registered", contentType)
|
||||
}
|
||||
return negotiated.DecoderToVersion(renegotiated.Serializer, internalGV), nil
|
||||
return config.NegotiatedSerializer.DecoderToVersion(info.Serializer, internalGV), nil
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
if info.StreamSerializer != nil {
|
||||
s.StreamingSerializer = info.StreamSerializer.Serializer
|
||||
s.Framer = info.StreamSerializer.Framer
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Verb begins a request with a verb (GET, POST, PUT, DELETE).
|
||||
|
|
|
|||
37
vendor/k8s.io/kubernetes/pkg/client/restclient/config.go
generated
vendored
37
vendor/k8s.io/kubernetes/pkg/client/restclient/config.go
generated
vendored
|
|
@ -25,6 +25,7 @@ import (
|
|||
"path"
|
||||
gruntime "runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/crypto"
|
||||
certutil "k8s.io/kubernetes/pkg/util/cert"
|
||||
"k8s.io/kubernetes/pkg/util/flowcontrol"
|
||||
"k8s.io/kubernetes/pkg/version"
|
||||
)
|
||||
|
|
@ -109,6 +110,9 @@ type Config struct {
|
|||
// Rate limiter for limiting connections to the master from this client. If present overwrites QPS/Burst
|
||||
RateLimiter flowcontrol.RateLimiter
|
||||
|
||||
// The maximum length of time to wait before giving up on a server request. A value of zero means no timeout.
|
||||
Timeout time.Duration
|
||||
|
||||
// Version forces a specific version to be used (if registered)
|
||||
// Do we need this?
|
||||
// Version string
|
||||
|
|
@ -185,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)
|
||||
|
|
@ -210,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
|
||||
|
|
@ -261,7 +271,7 @@ func InClusterConfig() (*Config, error) {
|
|||
}
|
||||
tlsClientConfig := TLSClientConfig{}
|
||||
rootCAFile := "/var/run/secrets/kubernetes.io/serviceaccount/" + api.ServiceAccountRootCAKey
|
||||
if _, err := crypto.CertPoolFromFile(rootCAFile); err != nil {
|
||||
if _, err := certutil.NewPool(rootCAFile); err != nil {
|
||||
glog.Errorf("Expected to load root CA config from %s, but got err: %v", rootCAFile, err)
|
||||
} else {
|
||||
tlsClientConfig.CAFile = rootCAFile
|
||||
|
|
@ -333,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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
167
vendor/k8s.io/kubernetes/pkg/client/restclient/request.go
generated
vendored
167
vendor/k8s.io/kubernetes/pkg/client/restclient/request.go
generated
vendored
|
|
@ -35,7 +35,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
pathvalidation "k8s.io/kubernetes/pkg/api/validation/path"
|
||||
"k8s.io/kubernetes/pkg/client/metrics"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
|
|
@ -179,7 +179,7 @@ func (r *Request) Resource(resource string) *Request {
|
|||
r.err = fmt.Errorf("resource already set to %q, cannot change to %q", r.resource, resource)
|
||||
return r
|
||||
}
|
||||
if msgs := validation.IsValidPathSegmentName(resource); len(msgs) != 0 {
|
||||
if msgs := pathvalidation.IsValidPathSegmentName(resource); len(msgs) != 0 {
|
||||
r.err = fmt.Errorf("invalid resource %q: %v", resource, msgs)
|
||||
return r
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ func (r *Request) SubResource(subresources ...string) *Request {
|
|||
return r
|
||||
}
|
||||
for _, s := range subresources {
|
||||
if msgs := validation.IsValidPathSegmentName(s); len(msgs) != 0 {
|
||||
if msgs := pathvalidation.IsValidPathSegmentName(s); len(msgs) != 0 {
|
||||
r.err = fmt.Errorf("invalid subresource %q: %v", s, msgs)
|
||||
return r
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ func (r *Request) Name(resourceName string) *Request {
|
|||
r.err = fmt.Errorf("resource name already set to %q, cannot change to %q", r.resourceName, resourceName)
|
||||
return r
|
||||
}
|
||||
if msgs := validation.IsValidPathSegmentName(resourceName); len(msgs) != 0 {
|
||||
if msgs := pathvalidation.IsValidPathSegmentName(resourceName); len(msgs) != 0 {
|
||||
r.err = fmt.Errorf("invalid resource name %q: %v", resourceName, msgs)
|
||||
return r
|
||||
}
|
||||
|
|
@ -238,7 +238,7 @@ func (r *Request) Namespace(namespace string) *Request {
|
|||
r.err = fmt.Errorf("namespace already set to %q, cannot change to %q", r.namespace, namespace)
|
||||
return r
|
||||
}
|
||||
if msgs := validation.IsValidPathSegmentName(namespace); len(msgs) != 0 {
|
||||
if msgs := pathvalidation.IsValidPathSegmentName(namespace); len(msgs) != 0 {
|
||||
r.err = fmt.Errorf("invalid namespace %q: %v", namespace, msgs)
|
||||
return r
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -744,23 +745,11 @@ func (r *Request) Stream() (io.ReadCloser, error) {
|
|||
// ensure we close the body before returning the error
|
||||
defer resp.Body.Close()
|
||||
|
||||
// we have a decent shot at taking the object returned, parsing it as a status object and returning a more normal error
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v while accessing %v", resp.Status, url)
|
||||
result := r.transformResponse(resp, req)
|
||||
if result.err != nil {
|
||||
return nil, result.err
|
||||
}
|
||||
|
||||
// TODO: Check ContentType.
|
||||
if runtimeObject, err := runtime.Decode(r.serializers.Decoder, bodyBytes); err == nil {
|
||||
statusError := errors.FromObject(runtimeObject)
|
||||
|
||||
if _, ok := statusError.(errors.APIStatus); ok {
|
||||
return nil, statusError
|
||||
}
|
||||
}
|
||||
|
||||
bodyText := string(bodyBytes)
|
||||
return nil, fmt.Errorf("%s while accessing %v: %s", resp.Status, url, bodyText)
|
||||
return nil, fmt.Errorf("%d while accessing %v: %s", result.statusCode, url, string(result.body))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -806,6 +795,12 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
|
|||
req.Header = r.headers
|
||||
|
||||
r.backoffMgr.Sleep(r.backoffMgr.CalculateBackoff(r.URL()))
|
||||
if retries > 0 {
|
||||
// We are retrying the request that we already send to apiserver
|
||||
// at least once before.
|
||||
// This request should also be throttled with the client-internal throttler.
|
||||
r.tryThrottle()
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
updateURLMetrics(r, resp, err)
|
||||
if err != nil {
|
||||
|
|
@ -901,10 +896,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))
|
||||
}
|
||||
}
|
||||
|
|
@ -934,33 +930,21 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
|||
}
|
||||
}
|
||||
|
||||
// Did the server give us a status response?
|
||||
isStatusResponse := false
|
||||
status := &unversioned.Status{}
|
||||
// Because release-1.1 server returns Status with empty APIVersion at paths
|
||||
// to the Extensions resources, we need to use DecodeInto here to provide
|
||||
// default groupVersion, otherwise a status response won't be correctly
|
||||
// decoded.
|
||||
err := runtime.DecodeInto(decoder, body, status)
|
||||
if err == nil && len(status.Status) > 0 {
|
||||
isStatusResponse = true
|
||||
}
|
||||
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusSwitchingProtocols:
|
||||
// no-op, we've been upgraded
|
||||
case resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusPartialContent:
|
||||
if !isStatusResponse {
|
||||
return Result{err: r.transformUnstructuredResponseError(resp, req, body)}
|
||||
// calculate an unstructured error from the response which the Result object may use if the caller
|
||||
// did not return a structured error.
|
||||
retryAfter, _ := retryAfterSeconds(resp)
|
||||
err := r.newUnstructuredResponseError(body, isTextResponse(resp), resp.StatusCode, req.Method, retryAfter)
|
||||
return Result{
|
||||
body: body,
|
||||
contentType: contentType,
|
||||
statusCode: resp.StatusCode,
|
||||
decoder: decoder,
|
||||
err: err,
|
||||
}
|
||||
return Result{err: errors.FromObject(status)}
|
||||
}
|
||||
|
||||
// If the server gave us a status back, look at what it was.
|
||||
success := resp.StatusCode >= http.StatusOK && resp.StatusCode <= http.StatusPartialContent
|
||||
if isStatusResponse && (status.Status != unversioned.StatusSuccess && !success) {
|
||||
// "Failed" requests are clearly just an error and it makes sense to return them as such.
|
||||
return Result{err: errors.FromObject(status)}
|
||||
}
|
||||
|
||||
return Result{
|
||||
|
|
@ -971,6 +955,9 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
|||
}
|
||||
}
|
||||
|
||||
// maxUnstructuredResponseTextBytes is an upper bound on how much output to include in the unstructured error.
|
||||
const maxUnstructuredResponseTextBytes = 2048
|
||||
|
||||
// transformUnstructuredResponseError handles an error from the server that is not in a structured form.
|
||||
// It is expected to transform any response that is not recognizable as a clear server sent error from the
|
||||
// K8S API using the information provided with the request. In practice, HTTP proxies and client libraries
|
||||
|
|
@ -991,20 +978,29 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
|||
// TODO: introduce transformation of generic http.Client.Do() errors that separates 4.
|
||||
func (r *Request) transformUnstructuredResponseError(resp *http.Response, req *http.Request, body []byte) error {
|
||||
if body == nil && resp.Body != nil {
|
||||
if data, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||
if data, err := ioutil.ReadAll(&io.LimitedReader{R: resp.Body, N: maxUnstructuredResponseTextBytes}); err == nil {
|
||||
body = data
|
||||
}
|
||||
}
|
||||
retryAfter, _ := retryAfterSeconds(resp)
|
||||
return r.newUnstructuredResponseError(body, isTextResponse(resp), resp.StatusCode, req.Method, retryAfter)
|
||||
}
|
||||
|
||||
// newUnstructuredResponseError instantiates the appropriate generic error for the provided input. It also logs the body.
|
||||
func (r *Request) newUnstructuredResponseError(body []byte, isTextResponse bool, statusCode int, method string, retryAfter int) error {
|
||||
// cap the amount of output we create
|
||||
if len(body) > maxUnstructuredResponseTextBytes {
|
||||
body = body[:maxUnstructuredResponseTextBytes]
|
||||
}
|
||||
glog.V(8).Infof("Response Body: %#v", string(body))
|
||||
|
||||
message := "unknown"
|
||||
if isTextResponse(resp) {
|
||||
if isTextResponse {
|
||||
message = strings.TrimSpace(string(body))
|
||||
}
|
||||
retryAfter, _ := retryAfterSeconds(resp)
|
||||
return errors.NewGenericServerResponse(
|
||||
resp.StatusCode,
|
||||
req.Method,
|
||||
statusCode,
|
||||
method,
|
||||
unversioned.GroupResource{
|
||||
Group: r.content.GroupVersion.Group,
|
||||
Resource: r.resource,
|
||||
|
|
@ -1068,15 +1064,31 @@ func (r Result) Raw() ([]byte, error) {
|
|||
return r.body, r.err
|
||||
}
|
||||
|
||||
// Get returns the result as an object.
|
||||
// Get returns the result as an object, which means it passes through the decoder.
|
||||
// If the returned object is of type Status and has .Status != StatusSuccess, the
|
||||
// additional information in Status will be used to enrich the error.
|
||||
func (r Result) Get() (runtime.Object, error) {
|
||||
if r.err != nil {
|
||||
return nil, r.err
|
||||
// Check whether the result has a Status object in the body and prefer that.
|
||||
return nil, r.Error()
|
||||
}
|
||||
if r.decoder == nil {
|
||||
return nil, fmt.Errorf("serializer for %s doesn't exist", r.contentType)
|
||||
}
|
||||
return runtime.Decode(r.decoder, r.body)
|
||||
|
||||
// decode, but if the result is Status return that as an error instead.
|
||||
out, _, err := r.decoder.Decode(r.body, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch t := out.(type) {
|
||||
case *unversioned.Status:
|
||||
// any status besides StatusSuccess is considered an error.
|
||||
if t.Status != unversioned.StatusSuccess {
|
||||
return nil, errors.FromObject(t)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// StatusCode returns the HTTP status code of the request. (Only valid if no
|
||||
|
|
@ -1087,14 +1099,31 @@ func (r Result) StatusCode(statusCode *int) Result {
|
|||
}
|
||||
|
||||
// Into stores the result into obj, if possible. If obj is nil it is ignored.
|
||||
// If the returned object is of type Status and has .Status != StatusSuccess, the
|
||||
// additional information in Status will be used to enrich the error.
|
||||
func (r Result) Into(obj runtime.Object) error {
|
||||
if r.err != nil {
|
||||
return r.err
|
||||
// Check whether the result has a Status object in the body and prefer that.
|
||||
return r.Error()
|
||||
}
|
||||
if r.decoder == nil {
|
||||
return fmt.Errorf("serializer for %s doesn't exist", r.contentType)
|
||||
}
|
||||
return runtime.DecodeInto(r.decoder, r.body, obj)
|
||||
|
||||
out, _, err := r.decoder.Decode(r.body, nil, obj)
|
||||
if err != nil || out == obj {
|
||||
return err
|
||||
}
|
||||
// if a different object is returned, see if it is Status and avoid double decoding
|
||||
// the object.
|
||||
switch t := out.(type) {
|
||||
case *unversioned.Status:
|
||||
// any status besides StatusSuccess is considered an error.
|
||||
if t.Status != unversioned.StatusSuccess {
|
||||
return errors.FromObject(t)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// WasCreated updates the provided bool pointer to whether the server returned
|
||||
|
|
@ -1105,7 +1134,29 @@ func (r Result) WasCreated(wasCreated *bool) Result {
|
|||
}
|
||||
|
||||
// Error returns the error executing the request, nil if no error occurred.
|
||||
// If the returned object is of type Status and has Status != StatusSuccess, the
|
||||
// additional information in Status will be used to enrich the error.
|
||||
// See the Request.Do() comment for what errors you might get.
|
||||
func (r Result) Error() error {
|
||||
// if we have received an unexpected server error, and we have a body and decoder, we can try to extract
|
||||
// a Status object.
|
||||
if r.err == nil || !errors.IsUnexpectedServerError(r.err) || len(r.body) == 0 || r.decoder == nil {
|
||||
return r.err
|
||||
}
|
||||
|
||||
// attempt to convert the body into a Status object
|
||||
// to be backwards compatible with old servers that do not return a version, default to "v1"
|
||||
out, _, err := r.decoder.Decode(r.body, &unversioned.GroupVersionKind{Version: "v1"}, nil)
|
||||
if err != nil {
|
||||
glog.V(5).Infof("body was not decodable (unable to check for Status): %v", err)
|
||||
return r.err
|
||||
}
|
||||
switch t := out.(type) {
|
||||
case *unversioned.Status:
|
||||
// because we default the kind, we *must* check for StatusFailure
|
||||
if t.Status == unversioned.StatusFailure {
|
||||
return errors.FromObject(t)
|
||||
}
|
||||
}
|
||||
return r.err
|
||||
}
|
||||
|
|
|
|||
10
vendor/k8s.io/kubernetes/pkg/client/restclient/transport.go
generated
vendored
10
vendor/k8s.io/kubernetes/pkg/client/restclient/transport.go
generated
vendored
|
|
@ -26,7 +26,7 @@ import (
|
|||
// 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue