mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
rebase: update K8s packages to v0.32.1
Update K8s packages in go.mod to v0.32.1 Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
159
vendor/k8s.io/client-go/rest/client.go
generated
vendored
159
vendor/k8s.io/client-go/rest/client.go
generated
vendored
@ -17,16 +17,21 @@ limitations under the License.
|
||||
package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/munnerz/goautoneg"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
clientfeatures "k8s.io/client-go/features"
|
||||
"k8s.io/client-go/util/flowcontrol"
|
||||
)
|
||||
|
||||
@ -85,7 +90,7 @@ type RESTClient struct {
|
||||
versionedAPIPath string
|
||||
|
||||
// content describes how a RESTClient encodes and decodes responses.
|
||||
content ClientContentConfig
|
||||
content requestClientContentConfigProvider
|
||||
|
||||
// creates BackoffManager that is passed to requests.
|
||||
createBackoffMgr func() BackoffManager
|
||||
@ -105,10 +110,6 @@ type RESTClient struct {
|
||||
// NewRESTClient creates a new RESTClient. This client performs generic REST functions
|
||||
// such as Get, Put, Post, and Delete on specified paths.
|
||||
func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ClientContentConfig, rateLimiter flowcontrol.RateLimiter, client *http.Client) (*RESTClient, error) {
|
||||
if len(config.ContentType) == 0 {
|
||||
config.ContentType = "application/json"
|
||||
}
|
||||
|
||||
base := *baseURL
|
||||
if !strings.HasSuffix(base.Path, "/") {
|
||||
base.Path += "/"
|
||||
@ -119,14 +120,53 @@ func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ClientConte
|
||||
return &RESTClient{
|
||||
base: &base,
|
||||
versionedAPIPath: versionedAPIPath,
|
||||
content: config,
|
||||
content: requestClientContentConfigProvider{base: scrubCBORContentConfigIfDisabled(config)},
|
||||
createBackoffMgr: readExpBackoffConfig,
|
||||
rateLimiter: rateLimiter,
|
||||
|
||||
Client: client,
|
||||
Client: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func scrubCBORContentConfigIfDisabled(content ClientContentConfig) ClientContentConfig {
|
||||
if clientfeatures.FeatureGates().Enabled(clientfeatures.ClientsAllowCBOR) {
|
||||
content.Negotiator = clientNegotiatorWithCBORSequenceStreamDecoder{content.Negotiator}
|
||||
return content
|
||||
}
|
||||
|
||||
if mediatype, _, err := mime.ParseMediaType(content.ContentType); err == nil && mediatype == "application/cbor" {
|
||||
content.ContentType = "application/json"
|
||||
}
|
||||
|
||||
clauses := goautoneg.ParseAccept(content.AcceptContentTypes)
|
||||
scrubbed := false
|
||||
for i, clause := range clauses {
|
||||
if clause.Type == "application" && clause.SubType == "cbor" {
|
||||
scrubbed = true
|
||||
clauses[i].SubType = "json"
|
||||
}
|
||||
}
|
||||
if !scrubbed {
|
||||
// No application/cbor in AcceptContentTypes, nothing more to do.
|
||||
return content
|
||||
}
|
||||
|
||||
parts := make([]string, 0, len(clauses))
|
||||
for _, clause := range clauses {
|
||||
// ParseAccept does not store the parameter "q" in Params.
|
||||
params := clause.Params
|
||||
if clause.Q < 1 { // omit q=1, it's the default
|
||||
if params == nil {
|
||||
params = make(map[string]string, 1)
|
||||
}
|
||||
params["q"] = strconv.FormatFloat(clause.Q, 'g', 3, 32)
|
||||
}
|
||||
parts = append(parts, mime.FormatMediaType(fmt.Sprintf("%s/%s", clause.Type, clause.SubType), params))
|
||||
}
|
||||
content.AcceptContentTypes = strings.Join(parts, ",")
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
// GetRateLimiter returns rate limiter for a given client, or nil if it's called on a nil client
|
||||
func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter {
|
||||
if c == nil {
|
||||
@ -198,5 +238,106 @@ func (c *RESTClient) Delete() *Request {
|
||||
|
||||
// APIVersion returns the APIVersion this RESTClient is expected to use.
|
||||
func (c *RESTClient) APIVersion() schema.GroupVersion {
|
||||
return c.content.GroupVersion
|
||||
config, _ := c.content.GetClientContentConfig()
|
||||
return config.GroupVersion
|
||||
}
|
||||
|
||||
// requestClientContentConfigProvider observes HTTP 415 (Unsupported Media Type) responses to detect
|
||||
// that the server does not understand CBOR. Once this has happened, future requests are forced to
|
||||
// use JSON so they can succeed. This is convenient for client users that want to prefer CBOR, but
|
||||
// also need to interoperate with older servers so requests do not permanently fail. The clients
|
||||
// will not default to using CBOR until at least all supported kube-apiservers have enable-CBOR
|
||||
// locked to true, so this path will be rarely taken. Additionally, all generated clients accessing
|
||||
// built-in kube resources are forced to protobuf, so those will not degrade to JSON.
|
||||
type requestClientContentConfigProvider struct {
|
||||
base ClientContentConfig
|
||||
|
||||
// Becomes permanently true if a server responds with HTTP 415 (Unsupported Media Type) to a
|
||||
// request with "Content-Type" header containing the CBOR media type.
|
||||
sawUnsupportedMediaTypeForCBOR atomic.Bool
|
||||
}
|
||||
|
||||
// GetClientContentConfig returns the ClientContentConfig that should be used for new requests by
|
||||
// this client and true if the request ContentType was selected by default.
|
||||
func (p *requestClientContentConfigProvider) GetClientContentConfig() (ClientContentConfig, bool) {
|
||||
config := p.base
|
||||
|
||||
defaulted := config.ContentType == ""
|
||||
if defaulted {
|
||||
config.ContentType = "application/json"
|
||||
}
|
||||
|
||||
if !clientfeatures.FeatureGates().Enabled(clientfeatures.ClientsAllowCBOR) {
|
||||
return config, defaulted
|
||||
}
|
||||
|
||||
if defaulted && clientfeatures.FeatureGates().Enabled(clientfeatures.ClientsPreferCBOR) {
|
||||
config.ContentType = "application/cbor"
|
||||
}
|
||||
|
||||
if sawUnsupportedMediaTypeForCBOR := p.sawUnsupportedMediaTypeForCBOR.Load(); !sawUnsupportedMediaTypeForCBOR {
|
||||
return config, defaulted
|
||||
}
|
||||
|
||||
if mediaType, _, _ := mime.ParseMediaType(config.ContentType); mediaType != runtime.ContentTypeCBOR {
|
||||
return config, defaulted
|
||||
}
|
||||
|
||||
// The effective ContentType is CBOR and the client has previously received an HTTP 415 in
|
||||
// response to a CBOR request. Override ContentType to JSON.
|
||||
config.ContentType = runtime.ContentTypeJSON
|
||||
return config, defaulted
|
||||
}
|
||||
|
||||
// UnsupportedMediaType reports that the server has responded to a request with HTTP 415 Unsupported
|
||||
// Media Type.
|
||||
func (p *requestClientContentConfigProvider) UnsupportedMediaType(requestContentType string) {
|
||||
if !clientfeatures.FeatureGates().Enabled(clientfeatures.ClientsAllowCBOR) {
|
||||
return
|
||||
}
|
||||
|
||||
// This could be extended to consider the Content-Encoding request header, the Accept and
|
||||
// Accept-Encoding response headers, the request method, and URI (as mentioned in
|
||||
// https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.16). The request Content-Type
|
||||
// header is sufficient to implement a blanket CBOR fallback mechanism.
|
||||
requestContentType, _, _ = mime.ParseMediaType(requestContentType)
|
||||
switch requestContentType {
|
||||
case runtime.ContentTypeCBOR, string(types.ApplyCBORPatchType):
|
||||
p.sawUnsupportedMediaTypeForCBOR.Store(true)
|
||||
}
|
||||
}
|
||||
|
||||
// clientNegotiatorWithCBORSequenceStreamDecoder is a ClientNegotiator that delegates to another
|
||||
// ClientNegotiator to select the appropriate Encoder or Decoder for a given media type. As a
|
||||
// special case, it will resolve "application/cbor-seq" (a CBOR Sequence, the concatenation of zero
|
||||
// or more CBOR data items) as an alias for "application/cbor" (exactly one CBOR data item) when
|
||||
// selecting a stream decoder.
|
||||
type clientNegotiatorWithCBORSequenceStreamDecoder struct {
|
||||
negotiator runtime.ClientNegotiator
|
||||
}
|
||||
|
||||
func (n clientNegotiatorWithCBORSequenceStreamDecoder) Encoder(contentType string, params map[string]string) (runtime.Encoder, error) {
|
||||
return n.negotiator.Encoder(contentType, params)
|
||||
}
|
||||
|
||||
func (n clientNegotiatorWithCBORSequenceStreamDecoder) Decoder(contentType string, params map[string]string) (runtime.Decoder, error) {
|
||||
return n.negotiator.Decoder(contentType, params)
|
||||
}
|
||||
|
||||
func (n clientNegotiatorWithCBORSequenceStreamDecoder) StreamDecoder(contentType string, params map[string]string) (runtime.Decoder, runtime.Serializer, runtime.Framer, error) {
|
||||
if !clientfeatures.FeatureGates().Enabled(clientfeatures.ClientsAllowCBOR) {
|
||||
return n.negotiator.StreamDecoder(contentType, params)
|
||||
}
|
||||
|
||||
switch contentType {
|
||||
case runtime.ContentTypeCBORSequence:
|
||||
return n.negotiator.StreamDecoder(runtime.ContentTypeCBOR, params)
|
||||
case runtime.ContentTypeCBOR:
|
||||
// This media type is only appropriate for exactly one data item, not the zero or
|
||||
// more events of a watch stream.
|
||||
return nil, nil, nil, runtime.NegotiateError{ContentType: contentType, Stream: true}
|
||||
default:
|
||||
return n.negotiator.StreamDecoder(contentType, params)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user