Merge pull request #118422 from apelisse/dry-run-empty
dryrun: Don't reuse current object for conversion
This commit is contained in:
		| @@ -18,7 +18,10 @@ package registry | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"fmt" | ||||||
|  | 	"reflect" | ||||||
|  |  | ||||||
|  | 	"k8s.io/apimachinery/pkg/conversion" | ||||||
| 	"k8s.io/apimachinery/pkg/runtime" | 	"k8s.io/apimachinery/pkg/runtime" | ||||||
| 	"k8s.io/apimachinery/pkg/watch" | 	"k8s.io/apimachinery/pkg/watch" | ||||||
| 	"k8s.io/apiserver/pkg/storage" | 	"k8s.io/apiserver/pkg/storage" | ||||||
| @@ -72,19 +75,30 @@ func (s *DryRunnableStorage) GuaranteedUpdate( | |||||||
| 	ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, | 	ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, | ||||||
| 	preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, cachedExistingObject runtime.Object) error { | 	preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, cachedExistingObject runtime.Object) error { | ||||||
| 	if dryRun { | 	if dryRun { | ||||||
| 		err := s.Storage.Get(ctx, key, storage.GetOptions{IgnoreNotFound: ignoreNotFound}, destination) | 		var current runtime.Object | ||||||
|  | 		v, err := conversion.EnforcePtr(destination) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return fmt.Errorf("unable to convert output object to pointer: %v", err) | ||||||
|  | 		} | ||||||
|  | 		if u, ok := v.Addr().Interface().(runtime.Unstructured); ok { | ||||||
|  | 			current = u.NewEmptyInstance() | ||||||
|  | 		} else { | ||||||
|  | 			current = reflect.New(v.Type()).Interface().(runtime.Object) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		err = s.Storage.Get(ctx, key, storage.GetOptions{IgnoreNotFound: ignoreNotFound}, current) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		err = preconditions.Check(key, destination) | 		err = preconditions.Check(key, current) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		rev, err := s.Versioner().ObjectResourceVersion(destination) | 		rev, err := s.Versioner().ObjectResourceVersion(current) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		updated, _, err := tryUpdate(destination, storage.ResponseMeta{ResourceVersion: rev}) | 		updated, _, err := tryUpdate(current, storage.ResponseMeta{ResourceVersion: rev}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot