kubernetes: Confusing error when object with generateName already exists

Spawned from https://github.com/openshift/origin/issues/10237

https://github.com/openshift/origin/blob/master/vendor/k8s.io/kubernetes/pkg/api/rest/create.go#L106 is converting an AlreadyExists error into a server timeout error if it has a generateName

// CheckGeneratedNameError checks whether an error that occurred creating a resource is due
// to generation being unable to pick a valid name.
func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime.Object) error {
    if !errors.IsAlreadyExists(err) {
        return err
    }

    objectMeta, kind, kerr := objectMetaAndKind(strategy, obj)
    if kerr != nil {
        return kerr
    }

    if len(objectMeta.GenerateName) == 0 {
        return err
    }

    return errors.NewServerTimeoutForKind(kind.GroupKind(), "POST", 0)
}

That means that this returns really confusing errors:

data='{"kind":"Secret","apiVersion":"v1","metadata":{"name":"foo","generateName":"foo"}}'
$ oc create -f - <<< "$data"
secret "foo" created
$ oc create -f - <<< "$data"
Error from server: error when creating "STDIN": The POST operation against Secret could not be completed at this time, please try again.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 35 (20 by maintainers)

Most upvoted comments

I have taken a look at the complete flow of the issue. From what I understand, there are a couple of choices

Option - (1) Validate in BeforeCreate function if an object has both name and generateName and fail the request if that is the case. Option - (2) in BeforeCreate, set generateName to empty if it also has a name. This will make sure that the error in CheckGeneratedNameError is ServerTimeOut (when the generated name is conflicting with the already existing name of some other object). This is essentially the approach took in this PR, which no longer is actively worked on.

/cc @liggitt @deads2k

Would be really helpful if solved 😃

/remove-lifecycle rotten