-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
conversion: Return typed error on failure to convert for CRs #115650
base: master
Are you sure you want to change the base?
conversion: Return typed error on failure to convert for CRs #115650
Conversation
Skipping CI for Draft Pull Request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with this code but that seems reasonable. Can you add a test to reproduce the bug that this is attempting to fix in ssa? Thank you!
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/converter.go
Outdated
Show resolved
Hide resolved
318b8b9
to
d4c3974
Compare
@apelisse I've added a reproducer test for the bug now, could you PTAL? Thanks! |
/test pull-kubernetes-conformance-kind-ipv6-parallel |
/kind bug |
8689845
to
2c1cadb
Compare
@liggitt @apelisse I've addressed most comments (except #115650 (comment)), could you PTAL? |
// Migrate existing CR to new storage version by applying an | ||
// empty merge patch. | ||
_, err = dynamicClient.Resource(gvr). | ||
Patch(context.TODO(), name, types.MergePatchType, []byte("{}"), metav1.PatchOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe send an apply in the new version that changes other fields, so that you have two entries at that point, one in the old version and one in the new version.
|
||
apiVersion = noxuDefinition.Spec.Group + "/" + noxuDefinition.Spec.Versions[0].Name | ||
yamlBody = []byte(fmt.Sprintf(` | ||
apiVersion: %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure you send new fields in that apply so that you can see from the list of managed fields exactly what happened. (i.e. the old entry was removed even though it still should have owned some fields), the second entry that was inserted also still exists, and that last one also exist. You should have two entries at the end.
@MadhavJivrajani bump |
Thanks for the ping, this had dropped off my radar. Planning to get back to this. |
This commit adds the ability to inject a custom string instead of the default scheme name. It also consequently edits what is printed when a custom string is passed. This commit also adds tests to exercise the different code paths taken for notRegisteredErr. This is needed when we want to return typed errors and scheme names are not known before hand, such as conversion in custom resources. Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Return a typed error that also passes as a "Missing Version Error" so that server side apply updates are not blocked from happening on custom resources that have a version that is no longer available. This commit also adds an integration test to verify the same. Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
2c1cadb
to
fa6dcc7
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: MadhavJivrajani The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@apelisse 👋🏼 Copy pasting the output here for easy access:
|
If I run the added test against
|
/retest |
/retest |
Can we cherry pick this change back to supported releases? This issue has affected K8s since 1.22 |
if len(s) == 0 { | ||
return "" | ||
} | ||
return " in scheme " + strconv.Quote(string(s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Padding the context with a space prefix here feels clunky. Could we do all the formatting in one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpbetz the reason for this is in how the notRegisteredErr
string is formatted here: https://github.com/MadhavJivrajani/kubernetes/blob/fa6dcc734bf6d6faa720714628b8709c27736f19/staging/src/k8s.io/apimachinery/pkg/runtime/error.go#L73
There are two main cases to take care of: when we use a genericContext
and when we use a schemeContext
. If the genericContext
is used (meaning we already know what the scheme is, such as in cases of built in types), things would be okay for the most part, however, if we use a schemeContext
(for when we don't know the scheme before hand such as in CRs), we need to add in a in scheme
there towards the end of the formatted notRegisteredErr
error string. So to handle both cases and not overcomplicate the formatting logic, a space is padded here.
if len(s) == 0 { | ||
return "" | ||
} | ||
return " " + string(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
return ¬RegisteredErr{context: schemeContext(schemeName), gvk: gvk, target: target} | ||
} | ||
|
||
func NewNotRegisteredGVKErrForTargetWithContext(context string, gvk schema.GroupVersionKind, target GroupVersioner) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised to see context use type string here. It makes it easy to bypass the use of genericContext (..and the formatting that genericContext adds, which makes me think we should handle the formatting differently..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context
is probably a misnomer, but happy to change what it is called.
It makes it easy to bypass the use of genericContext (..and the formatting that genericContext adds, which makes me think we should handle the formatting differently..)
Not sure I understand the bypassing part here, could you please elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @liggitt
This issue is biting us pretty hard in Cluster API, is there any chance to backport this to older releases of Kubernetes (as much as possible?) |
It's really hard to reason about the implications of the change, so doing that safely on master is the first step. It's too early to comment about the possibility of backports, but my inclination would be not to backport, since this isn't a regression (and the implications are super hard to reason about). |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
Yeah sounds good @liggitt @MadhavJivrajani Is there any other action here for this PR? |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Return a typed error that also passes as a "Missing Version Error"
so that server side apply updates are not blocked from happening on
custom resources that have a version that is no longer available.
This commit also adds an integration test to verify the same.
Which issue(s) this PR fixes:
Fixes #111937
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: