Code change:
// namespace used for all tests, do not change this const testNamespace = "dryrunnamespace" <ins> func DryRunCreateWithGenerateNameTest(t *testing.T, rsc dynamic.ResourceInterface, obj *unstructured.Unstructured, gvResource schema.GroupVersionResource) { // 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("") DryRunCreateTest(t, rsc, gnObj, gvResource) } </ins> func DryRunCreateTest(t *testing.T, rsc dynamic.ResourceInterface, obj *unstructured.Unstructured, gvResource schema.GroupVersionResource) { createdObj, err := rsc.Create(context.TODO(), obj, metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}}) if err != nil { <del> t.Fatalf("failed to dry-run create stub for %s: %#v", gvResource, err) </del> <ins> t.Fatalf("failed to dry-run create stub for %s: %#v: %v", gvResource, err, obj) </ins> } if obj.GroupVersionKind() != createdObj.GroupVersionKind() { t.Fatalf("created object doesn't have the same gvk as original object: got %v, expected %v", createdObj.GroupVersionKind(), obj.GroupVersionKind()) } <ins> if createdObj.GetUID() != "" { t.Fatalf("created object shouldn't have a uid: %v", createdObj) } if createdObj.GetResourceVersion() != "" { t.Fatalf("created object shouldn't have a resource version: %v", createdObj) } if obj.GetGenerateName() != "" && createdObj.GetName() != "" { t.Fatalf("created object's name should be an empty string if using GenerateName: %v", createdObj) } </ins> <del> if _, err := rsc.Get(context.TODO(), obj.GetName(), metav1.GetOptions{}); !apierrors.IsNotFound(err) { t.Fatalf("object shouldn't exist: %v", err) </del> <ins> // 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) } </ins> } }

Related discussion:
text: Running kubectl create with dry-run returns unwanted uid metadata field, as well as a generated name when using generateName. This is inconsistent with the expectations as defined in which states I expected uid, and a generated name to be empty when using the dry-run create option. Expected metadata: Actual metadata: No response <detailsI've tested this from 1.19.0 through 1.23.0 </details<details</details<details</details<details</details<details</details<details</details
/sig api-machinery
/assign /triage accepted
reopening, is reverted in to make sure requests with both name+generateName are handled correctly
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Mark this issue or PR as fresh with Mark this issue or PR as rotten with Close this issue or PR with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at . /lifecycle stale [1]:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Mark this issue or PR as fresh with Close this issue or PR with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at . /lifecycle rotten [1]:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Reopen this issue or PR with Mark this issue or PR as fresh with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at .