mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update kubernetes to latest
updating the kubernetes release to the latest in main go.mod Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
63c4c05b35
commit
5a66991bb3
146
vendor/k8s.io/client-go/rest/request.go
generated
vendored
146
vendor/k8s.io/client-go/rest/request.go
generated
vendored
@ -37,12 +37,15 @@ import (
|
||||
"golang.org/x/net/http2"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
clientfeatures "k8s.io/client-go/features"
|
||||
restclientwatch "k8s.io/client-go/rest/watch"
|
||||
"k8s.io/client-go/tools/metrics"
|
||||
"k8s.io/client-go/util/flowcontrol"
|
||||
@ -768,6 +771,142 @@ func (r *Request) Watch(ctx context.Context) (watch.Interface, error) {
|
||||
}
|
||||
}
|
||||
|
||||
type WatchListResult struct {
|
||||
// err holds any errors we might have received
|
||||
// during streaming.
|
||||
err error
|
||||
|
||||
// items hold the collected data
|
||||
items []runtime.Object
|
||||
|
||||
// initialEventsEndBookmarkRV holds the resource version
|
||||
// extracted from the bookmark event that marks
|
||||
// the end of the stream.
|
||||
initialEventsEndBookmarkRV string
|
||||
|
||||
// gv represents the API version
|
||||
// it is used to construct the final list response
|
||||
// normally this information is filled by the server
|
||||
gv schema.GroupVersion
|
||||
}
|
||||
|
||||
func (r WatchListResult) Into(obj runtime.Object) error {
|
||||
if r.err != nil {
|
||||
return r.err
|
||||
}
|
||||
|
||||
listPtr, err := meta.GetItemsPtr(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listVal, err := conversion.EnforcePtr(listPtr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if listVal.Kind() != reflect.Slice {
|
||||
return fmt.Errorf("need a pointer to slice, got %v", listVal.Kind())
|
||||
}
|
||||
|
||||
if len(r.items) == 0 {
|
||||
listVal.Set(reflect.MakeSlice(listVal.Type(), 0, 0))
|
||||
} else {
|
||||
listVal.Set(reflect.MakeSlice(listVal.Type(), len(r.items), len(r.items)))
|
||||
for i, o := range r.items {
|
||||
if listVal.Type().Elem() != reflect.TypeOf(o).Elem() {
|
||||
return fmt.Errorf("received object type = %v at index = %d, doesn't match the list item type = %v", reflect.TypeOf(o).Elem(), i, listVal.Type().Elem())
|
||||
}
|
||||
listVal.Index(i).Set(reflect.ValueOf(o).Elem())
|
||||
}
|
||||
}
|
||||
|
||||
listMeta, err := meta.ListAccessor(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listMeta.SetResourceVersion(r.initialEventsEndBookmarkRV)
|
||||
|
||||
typeMeta, err := meta.TypeAccessor(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
version := r.gv.String()
|
||||
typeMeta.SetAPIVersion(version)
|
||||
typeMeta.SetKind(reflect.TypeOf(obj).Elem().Name())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WatchList establishes a stream to get a consistent snapshot of data
|
||||
// from the server as described in https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3157-watch-list#proposal
|
||||
//
|
||||
// Note that the watchlist requires properly setting the ListOptions
|
||||
// otherwise it just establishes a regular watch with the server.
|
||||
// Check the documentation https://kubernetes.io/docs/reference/using-api/api-concepts/#streaming-lists
|
||||
// to see what parameters are currently required.
|
||||
func (r *Request) WatchList(ctx context.Context) WatchListResult {
|
||||
if !clientfeatures.FeatureGates().Enabled(clientfeatures.WatchListClient) {
|
||||
return WatchListResult{err: fmt.Errorf("%q feature gate is not enabled", clientfeatures.WatchListClient)}
|
||||
}
|
||||
// TODO(#115478): consider validating request parameters (i.e sendInitialEvents).
|
||||
// Most users use the generated client, which handles the proper setting of parameters.
|
||||
// We don't have validation for other methods (e.g., the Watch)
|
||||
// thus, for symmetry, we haven't added additional checks for the WatchList method.
|
||||
w, err := r.Watch(ctx)
|
||||
if err != nil {
|
||||
return WatchListResult{err: err}
|
||||
}
|
||||
return r.handleWatchList(ctx, w)
|
||||
}
|
||||
|
||||
// handleWatchList holds the actual logic for easier unit testing.
|
||||
// Note that this function will close the passed watch.
|
||||
func (r *Request) handleWatchList(ctx context.Context, w watch.Interface) WatchListResult {
|
||||
defer w.Stop()
|
||||
var lastKey string
|
||||
var items []runtime.Object
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return WatchListResult{err: ctx.Err()}
|
||||
case event, ok := <-w.ResultChan():
|
||||
if !ok {
|
||||
return WatchListResult{err: fmt.Errorf("unexpected watch close")}
|
||||
}
|
||||
if event.Type == watch.Error {
|
||||
return WatchListResult{err: errors.FromObject(event.Object)}
|
||||
}
|
||||
meta, err := meta.Accessor(event.Object)
|
||||
if err != nil {
|
||||
return WatchListResult{err: fmt.Errorf("failed to parse watch event: %#v", event)}
|
||||
}
|
||||
|
||||
switch event.Type {
|
||||
case watch.Added:
|
||||
// the following check ensures that the response is ordered.
|
||||
// earlier servers had a bug that caused them to not sort the output.
|
||||
// in such cases, return an error which can trigger fallback logic.
|
||||
key := objectKeyFromMeta(meta)
|
||||
if len(lastKey) > 0 && lastKey > key {
|
||||
return WatchListResult{err: fmt.Errorf("cannot add the obj (%#v) with the key = %s, as it violates the ordering guarantees provided by the watchlist feature in beta phase, lastInsertedKey was = %s", event.Object, key, lastKey)}
|
||||
}
|
||||
items = append(items, event.Object)
|
||||
lastKey = key
|
||||
case watch.Bookmark:
|
||||
if meta.GetAnnotations()[metav1.InitialEventsAnnotationKey] == "true" {
|
||||
return WatchListResult{
|
||||
items: items,
|
||||
initialEventsEndBookmarkRV: meta.GetResourceVersion(),
|
||||
gv: r.c.content.GroupVersion,
|
||||
}
|
||||
}
|
||||
default:
|
||||
return WatchListResult{err: fmt.Errorf("unexpected watch event %#v, expected to only receive watch.Added and watch.Bookmark events", event)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Request) newStreamWatcher(resp *http.Response) (watch.Interface, error) {
|
||||
contentType := resp.Header.Get("Content-Type")
|
||||
mediaType, params, err := mime.ParseMediaType(contentType)
|
||||
@ -1470,3 +1609,10 @@ func ValidatePathSegmentName(name string, prefix bool) []string {
|
||||
}
|
||||
return IsValidPathSegmentName(name)
|
||||
}
|
||||
|
||||
func objectKeyFromMeta(objMeta metav1.Object) string {
|
||||
if len(objMeta.GetNamespace()) > 0 {
|
||||
return fmt.Sprintf("%s/%s", objMeta.GetNamespace(), objMeta.GetName())
|
||||
}
|
||||
return objMeta.GetName()
|
||||
}
|
||||
|
2
vendor/k8s.io/client-go/rest/watch/decoder.go
generated
vendored
2
vendor/k8s.io/client-go/rest/watch/decoder.go
generated
vendored
@ -51,7 +51,7 @@ func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) {
|
||||
return "", nil, err
|
||||
}
|
||||
if res != &got {
|
||||
return "", nil, fmt.Errorf("unable to decode to metav1.Event")
|
||||
return "", nil, fmt.Errorf("unable to decode to metav1.WatchEvent")
|
||||
}
|
||||
switch got.Type {
|
||||
case string(watch.Added), string(watch.Modified), string(watch.Deleted), string(watch.Error), string(watch.Bookmark):
|
||||
|
Reference in New Issue
Block a user