kubernetes-sigs/kubectl-validate

the validator fails when only generatedName is set

richardvflux opened this issue · 7 comments

What happened?

With a job, we set only the "generatedName" value as recommended by Argo https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks/#using-a-hook-to-send-a-slack-message - however on rendered validation, it fails because there is no name. Having no name is valid it appears if generatedName is set https://kubernetes.io/docs/reference/using-api/api-concepts/#generated-values

What did you expect to happen?

validation to pass

How can we reproduce it (as minimally and precisely as possible)?

use the sample Argo resource as an example

Anything else we need to know?

nope!

Kubernetes version

$ kubectl version
Client Version: v1.29.1

It seems it's caused by the rest/create.go which make the name initialized earlier in the create process。(kubernetes/kubernetes@af9d36f)

 if len(objectMeta.GetGenerateName()) > 0 && len(objectMeta.GetName()) == 0 {
		return errors.NewInternalError(fmt.Errorf("metadata.name was not generated"))
  }

A straight forward fix will be to generate name before invoking rest.BeforeCreate in validator.go. I'll open a PR.

/assign

Currently facing this issue as well. Thanks for your PR