Skip to content

Merge ErrorResponse and Status#1875

Merged
clux merged 5 commits into
kube-rs:mainfrom
imp:imp-40-merge-error-response-and-status
Jan 2, 2026
Merged

Merge ErrorResponse and Status#1875
clux merged 5 commits into
kube-rs:mainfrom
imp:imp-40-merge-error-response-and-status

Conversation

@imp
Copy link
Copy Markdown
Contributor

@imp imp commented Dec 30, 2025

This addresses #40 and by extension #1862

Motivation

This is done in order to expose the entire API Status data as close as possible to the metav1::Status object.

Solution

The Status struct is used as a payload in kube::Error::Api variant effectively bringing all the data from the (failed) k8s API request.

Also a bunch of constants added for different values of reason field (the list of reasons is shamelessly stolen from the K8s Go code base) as well as a few Status methods for identifying a popular error situation.
The implementation is also inspired by that of the Kubernetes.

I'd like to solicit opinions if that feels like a correct approach?

For example I was not entirely sure whether to convert the reason field to Rust enum instead of String. Do folks think that would be a right thing to do? I mean usually it is a good thing in Rust world, but in this specific case it might be rather large addition of LoCs with relatively low value. Would love to hear your thoughts.

I didn't touch yet the original ErrorResponse struct, but it could be of course aliased to the Status or alternatively made From<Status> provided we agree on the rest.

@imp imp force-pushed the imp-40-merge-error-response-and-status branch 4 times, most recently from ec14000 to b56df67 Compare December 30, 2025 05:44
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 65.38462% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.0%. Comparing base (14b5010) to head (4dd3ce9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
kube-runtime/src/watcher.rs 0.0% 7 Missing ⚠️
kube-client/src/client/mod.rs 33.4% 6 Missing ⚠️
kube-core/src/response.rs 88.3% 4 Missing ⚠️
kube-client/src/api/core_methods.rs 50.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1875     +/-   ##
=======================================
+ Coverage   75.9%   76.0%   +0.2%     
=======================================
  Files         85      85             
  Lines       8237    8267     +30     
=======================================
+ Hits        6244    6276     +32     
+ Misses      1993    1991      -2     
Files with missing lines Coverage Δ
kube-client/src/api/entry.rs 77.6% <ø> (ø)
kube-core/src/watch.rs 57.2% <ø> (ø)
kube-client/src/api/core_methods.rs 79.0% <50.0%> (ø)
kube-core/src/response.rs 64.0% <88.3%> (+30.7%) ⬆️
kube-client/src/client/mod.rs 76.5% <33.4%> (+1.1%) ⬆️
kube-runtime/src/watcher.rs 43.8% <0.0%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@imp imp force-pushed the imp-40-merge-error-response-and-status branch from b56df67 to e41d35d Compare December 30, 2025 05:57
Copy link
Copy Markdown
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

Thanks a lot. I like this approach personally. Left some questions initially and my thoughts on enums/const strs here (tl;dr; i don't think it's worth making it more advanced, but we should document where we got the values from).

Comment thread kube-core/src/response.rs
Comment thread kube-core/src/response/reason.rs Outdated
Comment thread kube-core/src/response/reason.rs Outdated
Comment thread kube-core/src/response/reason.rs Outdated
Comment thread kube-runtime/src/watcher.rs
Comment thread examples/secret_syncer.rs
@clux clux added the changelog-change changelog change category for prs label Dec 30, 2025
@clux clux added this to the 3.0.0 milestone Dec 30, 2025
@imp
Copy link
Copy Markdown
Contributor Author

imp commented Dec 30, 2025

So the question now is what to do with the original ErrorResponse?

I can think of three options:

  • Drop it entirely
  • Make it a type alias
  • Keep it, mark as deprecated and provide impl From<Status> for ErrorResponse

Dropping it may be too drastic, type alias - I personally not a fan of it. My choice would be deprecating and removing in one of the followup releases.

Any feedback on that ?

@clux
Copy link
Copy Markdown
Member

clux commented Dec 31, 2025

Keep it, mark as deprecated and provide impl From for ErrorResponse

You could do this, and it would slightly help users who use the struct directly in unexpected ways, but it wouldn't help the match cases though?. It's probably better than a blind removal since that would result in a "type not found" type error from the compiler, but unless people get to carry on using ErrorResponse in match statements, it would break anyway for the majority use case? If that's the case, I don't think it's providing enough benefit.

Make it a type alias

This would cause a small extra break for the users actually making an ErrorResponse if they are constructing it from scratch (it does not impl Default), but the compiler error for that (missing field) is pretty helpful here. I also expect the number of people constructing an ErrorResponse to be way lower than people doing matching on api errors.

If people have to change the match syntax anyway, then an alias feels better to me; it lessons the blow with a better compiler error (and a #[deprecated] warning on the type alias can help guide them towards the new match syntax).

@imp
Copy link
Copy Markdown
Contributor Author

imp commented Dec 31, 2025

If people have to change the match syntax anyway, then an alias feels better to me; it lessons the blow with a better compiler error (and a #[deprecated] warning on the type alias can help guide them towards the new match syntax).

Agree. I'll make necessary changes.

@imp imp force-pushed the imp-40-merge-error-response-and-status branch 2 times, most recently from 5d94bb1 to bab55b0 Compare December 31, 2025 13:15
@doxxx93
Copy link
Copy Markdown
Member

doxxx93 commented Jan 2, 2026

Sorry, I accidentally clicked the "Update branch" button and created a merge commit (2910383).

If you prefer a clean rebase history, please feel free to force push to remove this merge commit. Apologies for the noise!

@imp
Copy link
Copy Markdown
Contributor Author

imp commented Jan 2, 2026

Sorry, I accidentally clicked the "Update branch" button and created a merge commit (2910383).

If you prefer a clean rebase history, please feel free to force push to remove this merge commit. Apologies for the noise!

No worries

@imp imp force-pushed the imp-40-merge-error-response-and-status branch from 2910383 to 36ad35c Compare January 2, 2026 08:30
Comment thread kube-core/src/lib.rs
Copy link
Copy Markdown
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

Looks great. Thank you.

clippy is red, but that's because you pushed literally a minute before it got fixed so nw :D

happy to merge if you are

@imp imp force-pushed the imp-40-merge-error-response-and-status branch from 36ad35c to 4dd3ce9 Compare January 2, 2026 09:18
@imp
Copy link
Copy Markdown
Contributor Author

imp commented Jan 2, 2026

Yay, all green!

@clux clux merged commit 10efa00 into kube-rs:main Jan 2, 2026
17 checks passed
@imp imp deleted the imp-40-merge-error-response-and-status branch January 2, 2026 09:35
@clux
Copy link
Copy Markdown
Member

clux commented Jan 2, 2026

Ah, quick addon, i noticed this actually does* present errors when referencing ErrorResponse in one of my controllers;

error[E0422]: cannot find struct, variant or union type `ErrorResponse` in module `kube::error`
   --> src/controller/reconcile.rs:129:39
    |
129 |         kube::Error::Api(kube::error::ErrorResponse { code: 403, .. }) => {
    |                                       ^^^^^^^^^^^^^ not found in `kube::error`

For more information about this error, try `rustc --explain E0422`.
error: could not compile `xctrl` (lib) due to 1 previous error

I think the ErrorResponse type alias also need to exist in the places we export Status now.
(obv this example would still fail, but with the deprecation warning it should be easier to understand)

EDIT: doing this in #1883

hugoponthieu pushed a commit to hugoponthieu/kube that referenced this pull request Jan 29, 2026
* Add more unit tests

Signed-off-by: Cyril Plisko <[email protected]>

* Replace kube::Error::Api playload with Status

Signed-off-by: Cyril Plisko <[email protected]>

* Box the Status object to make clippy happy

Signed-off-by: Cyril Plisko <[email protected]>

* Address code review comments

Signed-off-by: Cyril Plisko <[email protected]>

* Replace ErrorResponse with deprecated type alias

Signed-off-by: Cyril Plisko <[email protected]>

---------

Signed-off-by: Cyril Plisko <[email protected]>
cchndl pushed a commit to cchndl/kube that referenced this pull request Feb 19, 2026
* Add more unit tests

Signed-off-by: Cyril Plisko <[email protected]>

* Replace kube::Error::Api playload with Status

Signed-off-by: Cyril Plisko <[email protected]>

* Box the Status object to make clippy happy

Signed-off-by: Cyril Plisko <[email protected]>

* Address code review comments

Signed-off-by: Cyril Plisko <[email protected]>

* Replace ErrorResponse with deprecated type alias

Signed-off-by: Cyril Plisko <[email protected]>

---------

Signed-off-by: Cyril Plisko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-change changelog change category for prs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants