Skip to content

Commit adb7621

Browse files
committed
Revert "remove unwanted values returned from dry-run"
This reverts commit 60c1d58.
1 parent 820247a commit adb7621

File tree

3 files changed

+3
-50
lines changed

3 files changed

+3
-50
lines changed

staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go

-5
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,6 @@ func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation
439439
if e.Decorator != nil {
440440
e.Decorator(out)
441441
}
442-
if dryrun.IsDryRun(options.DryRun) {
443-
if err := dryrun.ResetMetadata(obj, out); err != nil {
444-
return nil, err
445-
}
446-
}
447442
return out, nil
448443
}
449444

staging/src/k8s.io/apiserver/pkg/util/dryrun/dryrun.go

-34
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,7 @@ limitations under the License.
1616

1717
package dryrun
1818

19-
import (
20-
"k8s.io/apimachinery/pkg/api/errors"
21-
"k8s.io/apimachinery/pkg/api/meta"
22-
"k8s.io/apimachinery/pkg/runtime"
23-
)
24-
2519
// IsDryRun returns true if the DryRun flag is an actual dry-run.
2620
func IsDryRun(flag []string) bool {
2721
return len(flag) > 0
2822
}
29-
30-
// ResetMetadata resets metadata fields that are not allowed to be set by dry-run.
31-
func ResetMetadata(originalObj, newObj runtime.Object) error {
32-
originalObjMeta, err := meta.Accessor(originalObj)
33-
if err != nil {
34-
return errors.NewInternalError(err)
35-
}
36-
newObjMeta, err := meta.Accessor(newObj)
37-
if err != nil {
38-
return errors.NewInternalError(err)
39-
}
40-
// If a resource is created with dry-run enabled where generateName is set, the
41-
// store will set the name to the generated name. We need to reset the name and restore
42-
// the generateName metadata fields in order for the returned object to match the intent
43-
// of the original template.
44-
if originalObjMeta.GetGenerateName() != "" {
45-
newObjMeta.SetName("")
46-
}
47-
newObjMeta.SetGenerateName(originalObjMeta.GetGenerateName())
48-
// If UID is set in the dry-run output then that output cannot be used to create a resource. Reset
49-
// the UID to allow the output to be used to create resources.
50-
newObjMeta.SetUID("")
51-
// If the resourceVersion is set in the dry-run output then that output cannot be used to create
52-
// a resource. Reset the resourceVersion to allow the output to be used to create resources.
53-
newObjMeta.SetResourceVersion("")
54-
55-
return nil
56-
}

test/integration/dryrun/dryrun_test.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package dryrun
1818

1919
import (
2020
"context"
21-
"strings"
2221
"testing"
2322

2423
v1 "k8s.io/api/core/v1"
@@ -48,11 +47,7 @@ var kindAllowList = sets.NewString()
4847
const testNamespace = "dryrunnamespace"
4948

5049
func DryRunCreateWithGenerateNameTest(t *testing.T, rsc dynamic.ResourceInterface, obj *unstructured.Unstructured, gvResource schema.GroupVersionResource) {
51-
// special resources with dots in the name cannot use generateName
52-
if strings.Contains(obj.GetName(), ".") {
53-
return
54-
}
55-
// Create a new object with generateName to ensure we don't taint the original object
50+
// Create a new object with generateName
5651
gnObj := obj.DeepCopy()
5752
gnObj.SetGenerateName(obj.GetName() + "-")
5853
gnObj.SetName("")
@@ -79,11 +74,8 @@ func DryRunCreateTest(t *testing.T, rsc dynamic.ResourceInterface, obj *unstruct
7974
t.Fatalf("created object's name should be an empty string if using GenerateName: %v", createdObj)
8075
}
8176

82-
// we won't have a generated name here, so we won't check for this case
83-
if obj.GetGenerateName() == "" {
84-
if _, err := rsc.Get(context.TODO(), obj.GetName(), metav1.GetOptions{}); !apierrors.IsNotFound(err) {
85-
t.Fatalf("object shouldn't exist: %v, %v", obj, err)
86-
}
77+
if _, err := rsc.Get(context.TODO(), obj.GetName(), metav1.GetOptions{}); !apierrors.IsNotFound(err) {
78+
t.Fatalf("object shouldn't exist: %v", err)
8779
}
8880
}
8981

0 commit comments

Comments
 (0)