mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
Merge pull request #118422 from apelisse/dry-run-empty
dryrun: Don't reuse current object for conversion
This commit is contained in:
commit
336e46101c
@ -18,7 +18,10 @@ package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
@ -72,19 +75,30 @@ func (s *DryRunnableStorage) GuaranteedUpdate(
|
||||
ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool,
|
||||
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, cachedExistingObject runtime.Object) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
err = preconditions.Check(key, destination)
|
||||
err = preconditions.Check(key, current)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rev, err := s.Versioner().ObjectResourceVersion(destination)
|
||||
rev, err := s.Versioner().ObjectResourceVersion(current)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updated, _, err := tryUpdate(destination, storage.ResponseMeta{ResourceVersion: rev})
|
||||
updated, _, err := tryUpdate(current, storage.ResponseMeta{ResourceVersion: rev})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user