update dependencies (#6267)
Signed-off-by: hongming <coder.scala@gmail.com>
This commit is contained in:
8
vendor/k8s.io/apiserver/pkg/registry/generic/options.go
generated
vendored
8
vendor/k8s.io/apiserver/pkg/registry/generic/options.go
generated
vendored
@@ -19,6 +19,7 @@ package generic
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
"k8s.io/apiserver/pkg/storage/storagebackend"
|
||||
@@ -39,12 +40,15 @@ type RESTOptions struct {
|
||||
}
|
||||
|
||||
// Implement RESTOptionsGetter so that RESTOptions can directly be used when available (i.e. tests)
|
||||
func (opts RESTOptions) GetRESTOptions(schema.GroupResource) (RESTOptions, error) {
|
||||
func (opts RESTOptions) GetRESTOptions(schema.GroupResource, runtime.Object) (RESTOptions, error) {
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
type RESTOptionsGetter interface {
|
||||
GetRESTOptions(resource schema.GroupResource) (RESTOptions, error)
|
||||
// GetRESTOptions returns the RESTOptions for the given resource and example object.
|
||||
// The example object is used to determine the storage version for the resource.
|
||||
// If the example object is nil, the storage version will be determined by the resource's default storage version.
|
||||
GetRESTOptions(resource schema.GroupResource, example runtime.Object) (RESTOptions, error)
|
||||
}
|
||||
|
||||
// StoreOptions is set of configuration options used to complete generic registries.
|
||||
|
||||
66
vendor/k8s.io/apiserver/pkg/registry/generic/registry/store.go
generated
vendored
66
vendor/k8s.io/apiserver/pkg/registry/generic/registry/store.go
generated
vendored
@@ -23,6 +23,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
|
||||
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/api/validation"
|
||||
@@ -40,15 +42,16 @@ import (
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
storeerr "k8s.io/apiserver/pkg/storage/errors"
|
||||
"k8s.io/apiserver/pkg/storage/etcd3/metrics"
|
||||
"k8s.io/apiserver/pkg/util/dryrun"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
flowcontrolrequest "k8s.io/apiserver/pkg/util/flowcontrol/request"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
@@ -223,6 +226,10 @@ type Store struct {
|
||||
// storageVersionHash as empty in the discovery document.
|
||||
StorageVersioner runtime.GroupVersioner
|
||||
|
||||
// ReadinessCheckFunc checks if the storage is ready for accepting requests.
|
||||
// The field is optional, if set needs to be thread-safe.
|
||||
ReadinessCheckFunc func() error
|
||||
|
||||
// DestroyFunc cleans up clients used by the underlying Storage; optional.
|
||||
// If set, DestroyFunc has to be implemented in thread-safe way and
|
||||
// be prepared for being called more than once.
|
||||
@@ -231,6 +238,7 @@ type Store struct {
|
||||
|
||||
// Note: the rest.StandardStorage interface aggregates the common REST verbs
|
||||
var _ rest.StandardStorage = &Store{}
|
||||
var _ rest.StorageWithReadiness = &Store{}
|
||||
var _ rest.TableConvertor = &Store{}
|
||||
var _ GenericStore = &Store{}
|
||||
|
||||
@@ -289,6 +297,14 @@ func (e *Store) New() runtime.Object {
|
||||
return e.NewFunc()
|
||||
}
|
||||
|
||||
// ReadinessCheck checks if the storage is ready for accepting requests.
|
||||
func (e *Store) ReadinessCheck() error {
|
||||
if e.ReadinessCheckFunc != nil {
|
||||
return e.ReadinessCheckFunc()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Destroy cleans up its resources on shutdown.
|
||||
func (e *Store) Destroy() {
|
||||
if e.DestroyFunc != nil {
|
||||
@@ -392,11 +408,54 @@ func (e *Store) ListPredicate(ctx context.Context, p storage.SelectionPredicate,
|
||||
// finishNothing is a do-nothing FinishFunc.
|
||||
func finishNothing(context.Context, bool) {}
|
||||
|
||||
// maxNameGenerationCreateAttempts is the maximum number of
|
||||
// times create will be attempted when generateName is used
|
||||
// and create attempts fails due to name conflict errors.
|
||||
// Each attempt uses a newly randomly generated name.
|
||||
// 8 was selected as the max because it is sufficient to generate
|
||||
// 1 million names per generateName prefix, with only a 0.1%
|
||||
// probability of any generated name conflicting with existing names.
|
||||
// Without retry, a 0.1% probability occurs at ~500
|
||||
// generated names and a 50% probability occurs at ~4500
|
||||
// generated names.
|
||||
const maxNameGenerationCreateAttempts = 8
|
||||
|
||||
// Create inserts a new item according to the unique key from the object.
|
||||
// Note that registries may mutate the input object (e.g. in the strategy
|
||||
// hooks). Tests which call this might want to call DeepCopy if they expect to
|
||||
// be able to examine the input and output objects for differences.
|
||||
func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.RetryGenerateName) && needsNameGeneration(obj) {
|
||||
return e.createWithGenerateNameRetry(ctx, obj, createValidation, options)
|
||||
}
|
||||
|
||||
return e.create(ctx, obj, createValidation, options)
|
||||
}
|
||||
|
||||
// needsNameGeneration returns true if the obj has a generateName but no name.
|
||||
func needsNameGeneration(obj runtime.Object) bool {
|
||||
if objectMeta, err := meta.Accessor(obj); err == nil {
|
||||
if len(objectMeta.GetGenerateName()) > 0 && len(objectMeta.GetName()) == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// createWithGenerateNameRetry attempts to create obj up to maxNameGenerationCreateAttempts
|
||||
// when create fails due to a name conflict error. Each attempt randomly generates a new
|
||||
// name based on generateName.
|
||||
func (e *Store) createWithGenerateNameRetry(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (resultObj runtime.Object, err error) {
|
||||
for i := 0; i < maxNameGenerationCreateAttempts; i++ {
|
||||
resultObj, err = e.create(ctx, obj.DeepCopyObject(), createValidation, options)
|
||||
if err == nil || !apierrors.IsAlreadyExists(err) {
|
||||
return resultObj, err
|
||||
}
|
||||
}
|
||||
return resultObj, err
|
||||
}
|
||||
|
||||
func (e *Store) create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
|
||||
var finishCreate FinishFunc = finishNothing
|
||||
|
||||
// Init metadata as early as possible.
|
||||
@@ -1472,7 +1531,7 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
opts, err := options.RESTOptions.GetRESTOptions(e.DefaultQualifiedResource)
|
||||
opts, err := options.RESTOptions.GetRESTOptions(e.DefaultQualifiedResource, e.NewFunc())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1568,6 +1627,9 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.Storage.Storage != nil {
|
||||
e.ReadinessCheckFunc = e.Storage.Storage.ReadinessCheck
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user