Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object creation with generateName should return AlreadyExists instead of a Timeout #104699

Merged
merged 1 commit into from Sep 8, 2021

Conversation

vincepri
Copy link
Member

@vincepri vincepri commented Sep 1, 2021

Signed-off-by: Vince Prignano vincepri@vmware.com

What type of PR is this?

/kind cleanup
/kind api-change
Marking this as api-change given that it's a behavioral change for clients, feel free to remove if it's not appropriate.

What this PR does / why we need it:

This PR solves a long standing issue where we now allow objects being created to have both name and generateName set. If the object already exists, the CheckGeneratedNameError function is called which can then throw a timeout error (500) instead of actually informing the user that the name generated has caused a conflict.

In alternative to the approach proposed in this PR, I've also considered allowing the both generatedName and name to be set, but give precedence to the name; this assumes user intent and we should probably discuss if that's the best way to move forward or not. If this is the case, we can also opt to completely remove the CheckGeneratedNameError like @lavalamp suggested in the related issue.

The current function throws the timeout error in two cases today:

  • If the name was generated and it caused a conflict.
  • If both generatedName and name are provided by the user and the object already exists.

Which issue(s) this PR fixes:

Fixes #32220

Special notes for your reviewer:

  • The current behavior might break a lot of clients out there, I'm happy to consider an option where we keep the current behavior and find a more backward compatible solution.
  • The timeout error is very confusing, the underlying code is a 500, which leads users to think there is something wrong with the api-server or underlying infrastructure.

Does this PR introduce a user-facing change?

When creating an object with generateName, if a conflict occurs the server now returns an AlreadyExists error with a retry option.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 1, 2021
@vincepri
Copy link
Member Author

vincepri commented Sep 1, 2021

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 1, 2021
@vincepri
Copy link
Member Author

vincepri commented Sep 1, 2021

Once we agree on a path forward, I'll make sure to either update or add new tests.

@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@dims
Copy link
Member

dims commented Sep 1, 2021

cc @deads2k @liggitt

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 2, 2021
@vincepri vincepri changed the title Object creation with generateName should return a proper error Object creation with generateName should return AlreadyExists instead of a Timeout Sep 2, 2021
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 2, 2021
@fedebongio
Copy link
Contributor

/assign @lavalamp @liggitt
thank you for your comments even before our triage!
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 2, 2021
@vincepri vincepri force-pushed the generate-name-error branch 2 times, most recently from a9b4185 to b6d02dc Compare September 3, 2021 15:53
@vincepri
Copy link
Member Author

vincepri commented Sep 3, 2021

PTAL

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Sep 3, 2021
Signed-off-by: Vince Prignano <vincepri@vmware.com>
@liggitt
Copy link
Member

liggitt commented Sep 7, 2021

this looks reasonable to me... will defer lgtm to @lavalamp

@vincepri
Copy link
Member Author

vincepri commented Sep 7, 2021

@liggitt One follow-up question, if the user provides both name and generateName the code above is going to use name portion, but the error checking logic is going to ask for a retry. Should we opt to clear generateName when name is present as well?

@liggitt
Copy link
Member

liggitt commented Sep 7, 2021

Should we opt to clear generateName when name is present as well?

where are you suggesting that be cleared, server-side or client-side?

@vincepri
Copy link
Member Author

vincepri commented Sep 7, 2021

Yes, right after

if len(objectMeta.GetGenerateName()) > 0 && len(objectMeta.GetName()) == 0 {
objectMeta.SetName(strategy.GenerateName(objectMeta.GetGenerateName()))
}
— We're already ignoring generateName there if name is set, we could add a branch of that if that sets generateName to an empty string field if name is set.

@liggitt
Copy link
Member

liggitt commented Sep 7, 2021

I did a quick sweep, and it doesn't look like there are any in-tree places we're setting both name and generateName. I guess I'd want to understand how widespread setting both was for out-of-tree clients, and how dropping the generateName data would impact them.

@vincepri
Copy link
Member Author

vincepri commented Sep 7, 2021

@liggitt Yeah that makes sense, truthfully we arrived to this issue because we were setting both GenerateName and Name in Cluster API, which caused the timeout-cryptic error. With the changes above at least the error returned is in line with what a user would expect

if !errors.IsAlreadyExists(err) {
return err
}

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

if len(objectMeta.GetGenerateName()) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only remaining thought is, can we make the message less misleading if the user sets both?

What if we do something like this:

if gn, n := objectMeta.GetGenerateName(), objectMeta.GetName(); len(gn) == 0 || !strings.HasPrefix(n, gn) {

It's not perfect, but this should at least detect cases where user has set obviously conflicting generateName & name?

We can do it in a followup if this is making it too complicated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea, although we might need more signal that the above comparison, because the generateName can still be a prefix of name. In most cases, users setting both have probably gotten current objects through kubectl or other clients, and then tried to recreate them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, people in that situation will have to ask themselves, "hm why does the server choose the same name every time??"

I'd fix that too but I think it requires more plumbing and I've already made enough requests on this PR :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's merge this as-is and iterate on it as we go?

@lavalamp
Copy link
Member

lavalamp commented Sep 7, 2021

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 7, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 7, 2021
@k8s-ci-robot k8s-ci-robot merged commit 85b11ad into kubernetes:master Sep 8, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing error when object with generateName already exists
8 participants