mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #96112 from wojtek-t/remove_variadic_from_storage_interface
Remove variadic argument from storage interface
This commit is contained in:
commit
95c56ada4b
@ -108,7 +108,7 @@ func (s *storageLeases) UpdateLease(ip string) error {
|
||||
klog.V(6).Infof("Resetting TTL on master IP %q listed in storage to %v", ip, leaseTime)
|
||||
|
||||
return existing, &leaseTime, nil
|
||||
})
|
||||
}, nil)
|
||||
}
|
||||
|
||||
// RemoveLease removes the lease on a master IP in storage
|
||||
|
@ -231,7 +231,7 @@ func (r *RollbackREST) setDeploymentRollback(ctx context.Context, deploymentID s
|
||||
d.Spec.RollbackTo = config
|
||||
finalDeployment = d
|
||||
return d, nil
|
||||
}), dryRun)
|
||||
}), dryRun, nil)
|
||||
return finalDeployment, err
|
||||
}
|
||||
|
||||
|
@ -221,6 +221,7 @@ func (r *REST) Delete(ctx context.Context, name string, deleteValidation rest.Va
|
||||
return existingNamespace, nil
|
||||
}),
|
||||
dryrun.IsDryRun(options.DryRun),
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -214,7 +214,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx context.Context, podID, oldMa
|
||||
})
|
||||
finalPod = pod
|
||||
return pod, nil
|
||||
}), dryRun)
|
||||
}), dryRun, nil)
|
||||
return finalPod, err
|
||||
}
|
||||
|
||||
|
@ -172,6 +172,7 @@ func (e *Etcd) tryUpdate(fn func() error) error {
|
||||
existing.Data = data
|
||||
return existing, nil
|
||||
}),
|
||||
nil,
|
||||
)
|
||||
return storeerr.InterpretUpdateError(err, e.resource, "")
|
||||
}
|
||||
@ -207,6 +208,7 @@ func (e *Etcd) CreateOrUpdate(snapshot *api.RangeAllocation) error {
|
||||
last = snapshot.ResourceVersion
|
||||
return snapshot, nil
|
||||
}),
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return storeerr.InterpretUpdateError(err, e.resource, "")
|
||||
|
@ -145,6 +145,7 @@ func (r *REST) Delete(ctx context.Context, name string, deleteValidation rest.Va
|
||||
return existingCRD, nil
|
||||
}),
|
||||
dryrun.IsDryRun(options.DryRun),
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -78,7 +78,7 @@ func (s *DryRunnableStorage) List(ctx context.Context, key string, opts storage.
|
||||
|
||||
func (s *DryRunnableStorage) GuaranteedUpdate(
|
||||
ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool,
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, suggestion ...runtime.Object) error {
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, suggestion runtime.Object) error {
|
||||
if dryRun {
|
||||
err := s.Storage.Get(ctx, key, storage.GetOptions{IgnoreNotFound: ignoreNotFound}, ptrToType)
|
||||
if err != nil {
|
||||
@ -98,7 +98,7 @@ func (s *DryRunnableStorage) GuaranteedUpdate(
|
||||
}
|
||||
return s.copyInto(out, ptrToType)
|
||||
}
|
||||
return s.Storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, suggestion...)
|
||||
return s.Storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, suggestion)
|
||||
}
|
||||
|
||||
func (s *DryRunnableStorage) Count(key string) (int64, error) {
|
||||
|
@ -121,7 +121,7 @@ func TestDryRunUpdateMissingObjectFails(t *testing.T) {
|
||||
return input, nil, errors.New("UpdateFunction shouldn't be called")
|
||||
}
|
||||
|
||||
err := s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true)
|
||||
err := s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true, nil)
|
||||
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound {
|
||||
t.Errorf("Expected key to be not found, error: %v", err)
|
||||
}
|
||||
@ -148,12 +148,12 @@ func TestDryRunUpdatePreconditions(t *testing.T) {
|
||||
}
|
||||
wrongID := types.UID("wrong-uid")
|
||||
myID := types.UID("my-uid")
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, &storage.Preconditions{UID: &wrongID}, updateFunc, true)
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, &storage.Preconditions{UID: &wrongID}, updateFunc, true, nil)
|
||||
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeInvalidObj {
|
||||
t.Errorf("Expected invalid object, error: %v", err)
|
||||
}
|
||||
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, &storage.Preconditions{UID: &myID}, updateFunc, true)
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, &storage.Preconditions{UID: &myID}, updateFunc, true, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to update with valid precondition: %v", err)
|
||||
}
|
||||
@ -180,7 +180,7 @@ func TestDryRunUpdateDoesntUpdate(t *testing.T) {
|
||||
return u, nil, nil
|
||||
}
|
||||
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true)
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to dry-run update: %v", err)
|
||||
}
|
||||
@ -212,7 +212,7 @@ func TestDryRunUpdateReturnsObject(t *testing.T) {
|
||||
return u, nil, nil
|
||||
}
|
||||
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true)
|
||||
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to dry-run update: %v", err)
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObj
|
||||
return obj, &ttl, nil
|
||||
}
|
||||
return obj, nil, nil
|
||||
}, dryrun.IsDryRun(options.DryRun))
|
||||
}, dryrun.IsDryRun(options.DryRun), nil)
|
||||
|
||||
if err != nil {
|
||||
// delete the object
|
||||
@ -855,6 +855,7 @@ func (e *Store) updateForGracefulDeletionAndFinalizers(ctx context.Context, name
|
||||
return existing, nil
|
||||
}),
|
||||
dryrun.IsDryRun(options.DryRun),
|
||||
nil,
|
||||
)
|
||||
switch err {
|
||||
case nil:
|
||||
|
@ -1926,7 +1926,7 @@ type staleGuaranteedUpdateStorage struct {
|
||||
// GuaranteedUpdate overwrites the method with one that always suggests the cachedObj.
|
||||
func (s *staleGuaranteedUpdateStorage) GuaranteedUpdate(
|
||||
ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool,
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, _ ...runtime.Object) error {
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, _ runtime.Object) error {
|
||||
return s.Interface.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, s.cachedObj)
|
||||
}
|
||||
|
||||
|
@ -730,7 +730,7 @@ func (c *Cacher) List(ctx context.Context, key string, opts storage.ListOptions,
|
||||
// GuaranteedUpdate implements storage.Interface.
|
||||
func (c *Cacher) GuaranteedUpdate(
|
||||
ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool,
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, _ ...runtime.Object) error {
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, _ runtime.Object) error {
|
||||
// Ignore the suggestion and try to pass down the current version of the object
|
||||
// read from cache.
|
||||
if elem, exists, err := c.watchCache.GetByKey(key); err != nil {
|
||||
@ -740,7 +740,7 @@ func (c *Cacher) GuaranteedUpdate(
|
||||
return c.storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, currObj)
|
||||
}
|
||||
// If we couldn't get the object, fallback to no-suggestion.
|
||||
return c.storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate)
|
||||
return c.storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, nil)
|
||||
}
|
||||
|
||||
// Count implements storage.Interface.
|
||||
|
@ -319,7 +319,7 @@ func (d *dummyStorage) List(_ context.Context, _ string, _ storage.ListOptions,
|
||||
podList.ListMeta = metav1.ListMeta{ResourceVersion: "100"}
|
||||
return d.err
|
||||
}
|
||||
func (d *dummyStorage) GuaranteedUpdate(_ context.Context, _ string, _ runtime.Object, _ bool, _ *storage.Preconditions, _ storage.UpdateFunc, _ ...runtime.Object) error {
|
||||
func (d *dummyStorage) GuaranteedUpdate(_ context.Context, _ string, _ runtime.Object, _ bool, _ *storage.Preconditions, _ storage.UpdateFunc, _ runtime.Object) error {
|
||||
return fmt.Errorf("unimplemented")
|
||||
}
|
||||
func (d *dummyStorage) Count(_ string) (int64, error) {
|
||||
|
@ -238,7 +238,7 @@ func (s *store) conditionalDelete(ctx context.Context, key string, out runtime.O
|
||||
// GuaranteedUpdate implements storage.Interface.GuaranteedUpdate.
|
||||
func (s *store) GuaranteedUpdate(
|
||||
ctx context.Context, key string, out runtime.Object, ignoreNotFound bool,
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, suggestion ...runtime.Object) error {
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, suggestion runtime.Object) error {
|
||||
trace := utiltrace.New("GuaranteedUpdate etcd3", utiltrace.Field{"type", getTypeName(out)})
|
||||
defer trace.LogIfLong(500 * time.Millisecond)
|
||||
|
||||
@ -260,8 +260,8 @@ func (s *store) GuaranteedUpdate(
|
||||
|
||||
var origState *objState
|
||||
var mustCheckData bool
|
||||
if len(suggestion) == 1 && suggestion[0] != nil {
|
||||
origState, err = s.getStateFromObject(suggestion[0])
|
||||
if suggestion != nil {
|
||||
origState, err = s.getStateFromObject(suggestion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func TestGet(t *testing.T) {
|
||||
func(_ runtime.Object, _ storage.ResponseMeta) (runtime.Object, *uint64, error) {
|
||||
ttl := uint64(1)
|
||||
return updateObj, &ttl, nil
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Update failed: %v", err)
|
||||
}
|
||||
@ -592,7 +592,7 @@ func TestGuaranteedUpdate(t *testing.T) {
|
||||
}
|
||||
pod.Name = name
|
||||
return &pod, nil
|
||||
}))
|
||||
}), nil)
|
||||
store.transformer = originalTransformer
|
||||
|
||||
if tt.expectNotFoundErr {
|
||||
@ -645,7 +645,7 @@ func TestGuaranteedUpdateWithTTL(t *testing.T) {
|
||||
func(_ runtime.Object, _ storage.ResponseMeta) (runtime.Object, *uint64, error) {
|
||||
ttl := uint64(1)
|
||||
return input, &ttl, nil
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
}
|
||||
@ -742,7 +742,7 @@ func TestGuaranteedUpdateWithConflict(t *testing.T) {
|
||||
pod.Name = "foo-1"
|
||||
secondToEnter.Wait()
|
||||
return pod, nil
|
||||
}))
|
||||
}), nil)
|
||||
firstToFinish.Done()
|
||||
errChan <- err
|
||||
}()
|
||||
@ -758,7 +758,7 @@ func TestGuaranteedUpdateWithConflict(t *testing.T) {
|
||||
pod := obj.(*example.Pod)
|
||||
pod.Name = "foo-2"
|
||||
return pod, nil
|
||||
}))
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Second GuaranteedUpdate error %#v", err)
|
||||
}
|
||||
@ -784,6 +784,7 @@ func TestGuaranteedUpdateWithSuggestionAndConflict(t *testing.T) {
|
||||
pod.Name = "foo-2"
|
||||
return pod, nil
|
||||
}),
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@ -875,7 +876,7 @@ func TestTransformationFailure(t *testing.T) {
|
||||
// GuaranteedUpdate without suggestion should return an error
|
||||
if err := store.GuaranteedUpdate(ctx, preset[1].key, &example.Pod{}, false, nil, func(input runtime.Object, res storage.ResponseMeta) (output runtime.Object, ttl *uint64, err error) {
|
||||
return input, nil, nil
|
||||
}); !storage.IsInternalError(err) {
|
||||
}, nil); !storage.IsInternalError(err) {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
// GuaranteedUpdate with suggestion should return an error if we don't change the object
|
||||
|
@ -108,7 +108,7 @@ func testWatch(t *testing.T, recursive bool) {
|
||||
err := store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
return watchTest.obj, nil
|
||||
}))
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("GuaranteedUpdate failed: %v", err)
|
||||
}
|
||||
@ -161,7 +161,7 @@ func TestWatchFromZero(t *testing.T) {
|
||||
err = store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
return &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "ns", Annotations: map[string]string{"a": "1"}}}, nil
|
||||
}))
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("GuaranteedUpdate failed: %v", err)
|
||||
}
|
||||
@ -179,7 +179,7 @@ func TestWatchFromZero(t *testing.T) {
|
||||
err = store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
return &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "ns"}}, nil
|
||||
}))
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("GuaranteedUpdate failed: %v", err)
|
||||
}
|
||||
@ -217,7 +217,7 @@ func TestWatchFromNoneZero(t *testing.T) {
|
||||
store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
return &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "bar"}}, err
|
||||
}))
|
||||
}), nil)
|
||||
testCheckResult(t, 0, watch.Modified, w, out)
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ func TestWatchError(t *testing.T) {
|
||||
validStore.GuaranteedUpdate(ctx, "/abc", &example.Pod{}, true, nil, storage.SimpleUpdate(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
return &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, nil
|
||||
}))
|
||||
}), nil)
|
||||
testCheckEventType(t, watch.Error, w)
|
||||
}
|
||||
|
||||
|
@ -215,9 +215,9 @@ type Interface interface {
|
||||
// or zero value in 'ptrToType' parameter otherwise.
|
||||
// If the object to update has the same value as previous, it won't do any update
|
||||
// but will return the object in 'ptrToType' parameter.
|
||||
// If 'suggestion' can contain zero or one element - in such case this can be used as
|
||||
// a suggestion about the current version of the object to avoid read operation from
|
||||
// storage to get it.
|
||||
// If 'suggestion' is non-nil, it can be used as a suggestion about the current version
|
||||
// of the object to avoid read operation from storage to get it. However, the
|
||||
// implementations have to retry in case suggestion is stale.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
@ -239,7 +239,7 @@ type Interface interface {
|
||||
// )
|
||||
GuaranteedUpdate(
|
||||
ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool,
|
||||
precondtions *Preconditions, tryUpdate UpdateFunc, suggestion ...runtime.Object) error
|
||||
precondtions *Preconditions, tryUpdate UpdateFunc, suggestion runtime.Object) error
|
||||
|
||||
// Count returns number of different entries under the key (generally being path prefix).
|
||||
Count(key string) (int64, error)
|
||||
|
@ -149,7 +149,7 @@ func updatePod(t *testing.T, s storage.Interface, obj, old *example.Pod) *exampl
|
||||
return obj.DeepCopyObject(), nil, nil
|
||||
}
|
||||
key := "pods/" + obj.Namespace + "/" + obj.Name
|
||||
if err := s.GuaranteedUpdate(context.TODO(), key, &example.Pod{}, old == nil, nil, updateFn); err != nil {
|
||||
if err := s.GuaranteedUpdate(context.TODO(), key, &example.Pod{}, old == nil, nil, updateFn, nil); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
obj.ResourceVersion = ""
|
||||
|
Loading…
Reference in New Issue
Block a user