remove unwanted values returned from dry-run

Remove the uid and the resourceVersion from dry-run results per kep 576

https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/576-dry-run/README.md#generated-values
This commit is contained in:
Joe Julian
2021-12-16 12:44:02 -08:00
parent 48994c1518
commit 60c1d58d02
3 changed files with 50 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ package dryrun
import (
"context"
"strings"
"testing"
v1 "k8s.io/api/core/v1"
@@ -47,7 +48,11 @@ var kindAllowList = sets.NewString()
const testNamespace = "dryrunnamespace"
func DryRunCreateWithGenerateNameTest(t *testing.T, rsc dynamic.ResourceInterface, obj *unstructured.Unstructured, gvResource schema.GroupVersionResource) {
// Create a new object with generateName
// special resources with dots in the name cannot use generateName
if strings.Contains(obj.GetName(), ".") {
return
}
// Create a new object with generateName to ensure we don't taint the original object
gnObj := obj.DeepCopy()
gnObj.SetGenerateName(obj.GetName() + "-")
gnObj.SetName("")
@@ -74,8 +79,11 @@ func DryRunCreateTest(t *testing.T, rsc dynamic.ResourceInterface, obj *unstruct
t.Fatalf("created object's name should be an empty string if using GenerateName: %v", createdObj)
}
if _, err := rsc.Get(context.TODO(), obj.GetName(), metav1.GetOptions{}); !apierrors.IsNotFound(err) {
t.Fatalf("object shouldn't exist: %v", err)
// we won't have a generated name here, so we won't check for this case
if obj.GetGenerateName() == "" {
if _, err := rsc.Get(context.TODO(), obj.GetName(), metav1.GetOptions{}); !apierrors.IsNotFound(err) {
t.Fatalf("object shouldn't exist: %v, %v", obj, err)
}
}
}