published by bot

(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 71ba8a90f0a4f3a307cffeb8f8566d13277cb135
This commit is contained in:
Kubernetes Publisher
2016-10-30 21:06:23 +00:00
parent f11d57fed7
commit b22087a53b
266 changed files with 61351 additions and 53498 deletions

View File

@@ -18,6 +18,7 @@ package rest
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
@@ -141,34 +154,48 @@ 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)
if !ok {
return nil, fmt.Errorf("serializer for %s not registered", contentType)
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)
}
streamInfo, ok := negotiated.StreamingSerializerForMediaType(contentType, nil)
info, ok := runtime.SerializerInfoForMediaType(mediaTypes, mediaType)
if !ok {
return nil, fmt.Errorf("streaming 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]
}
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).