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

Add support for CRD ConversionReview types #999

Merged
merged 14 commits into from Sep 16, 2022
Merged

Conversation

MikailBag
Copy link
Contributor

Signed-off-by: Mikail Bagishov bagishov.mikail@yandex.ru

Motivation

Part of #992.

Solution

Compared to version in the old PR, I renamed low_level.rs -> types.rs, renamed module conversion.rs -> mod/conversion.rs to align with rest of the code base, and made submodule private.

@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2022

Codecov Report

Merging #999 (f03ec56) into master (15faafb) will decrease coverage by 0.30%.
The diff coverage is 49.25%.

@@            Coverage Diff             @@
##           master     #999      +/-   ##
==========================================
- Coverage   72.20%   71.89%   -0.31%     
==========================================
  Files          64       65       +1     
  Lines        4573     4637      +64     
==========================================
+ Hits         3302     3334      +32     
- Misses       1271     1303      +32     
Impacted Files Coverage Δ
kube-core/src/admission.rs 61.11% <0.00%> (ø)
kube-core/src/response.rs 31.03% <9.09%> (-68.97%) ⬇️
kube-core/src/conversion/types.rs 71.42% <71.42%> (ø)
kube-client/src/lib.rs 93.75% <100.00%> (ø)

Copy link
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.

minor comments on documentation and naming, but this part is starting to look good

/// Copied from the corresponding consructing [`ConversionReview`].
/// This field is not part of the Kubernetes API, it's consumed only by `kube`.
#[serde(skip)]
pub types: Option<TypeMeta>,
Copy link
Member

Choose a reason for hiding this comment

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

In admission we have this as a non-optional field for both Response and Request (with skip still), is there a reason to keep it optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No strong reason. It simplifies manual creation of ConversionRequest a little bit (i.e. it may be surprising for user to see non-optional field which is not set by apiserver).

kube-core/src/conversion/types.rs Outdated Show resolved Hide resolved
kube-core/src/conversion/types.rs Outdated Show resolved Hide resolved
kube-core/src/conversion/types.rs Outdated Show resolved Hide resolved
kube-core/src/conversion/types.rs Show resolved Hide resolved
kube-core/src/conversion/types.rs Show resolved Hide resolved
kube-core/src/conversion/types.rs Outdated Show resolved Hide resolved
kube-core/src/conversion/types.rs Outdated Show resolved Hide resolved
kube-core/src/response.rs Outdated Show resolved Hide resolved
kube-core/src/response.rs Show resolved Hide resolved
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
@MikailBag MikailBag force-pushed the conv-types branch 2 times, most recently from 1233492 to 1c6e382 Compare September 5, 2022 21:15
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
@MikailBag MikailBag marked this pull request as ready for review September 7, 2022 18:40
}

/// Returns an unsuccessful `Status`
pub fn failure(message: &str, reason: &str) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should split this up into a failure with message as the only param and have a with_reason(reason) function on mut self (or other way around if reason is the most important one - don't remember right now)

Copy link
Member

Choose a reason for hiding this comment

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

actually, these two are very linked, it is probably a mistake to let people do one and not the other. ignore this.

while i am a bit uncomfortable with the double &str argument (which can be swapped around accidentally), there are probably smarter stuff we can do down the line to convert an Error into a Status by taking advantage of the Display and Debug traits for the error to fill these in a less error prone way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can think of

fn from_error<E: Display>(err: &E, reason: &str) -> Self;

which uses e.to_string() as message (I don't see a way to infer reason from error, especially given guidelines that it shoud be short and PascalCase).

Copy link
Member

@clux clux Sep 10, 2022

Choose a reason for hiding this comment

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

Users could possibly do it in their app, if they did a convention like that if the Display was always PascalCase, and then they can take the Debug as the reason, but users would have to stay on top of their errors if so. We couldn't enforce that though, so there isn't much we can do in kube directly. We can experiment in controller-rs with some strategic error use in the future perhaps.

@clux clux added the changelog-add changelog added category for prs label Sep 7, 2022
@clux clux added this to the 0.75.0 milestone Sep 7, 2022
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
kube-core/src/admission.rs Outdated Show resolved Hide resolved
@clux
Copy link
Member

clux commented Sep 12, 2022

Only one tiny nit left on the admission code that was cleaned up, but am otherwise happy with merging this. Thanks for all the back and forth on this.

@MikailBag
Copy link
Contributor Author

CI is red, but this looks like issue with k3d action

Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
@clux
Copy link
Member

clux commented Sep 16, 2022

CI is red, but this looks like issue with k3d action

Yeah, had the same issue on the k8s-openapi bump PR, so probably not resolvable here without pinning k3d. I'll give it one last re-run as a check before merging.

@clux clux linked an issue Sep 16, 2022 that may be closed by this pull request
@clux clux changed the title CRD conversion: typings Add support for CRD ConversionReview types Sep 16, 2022
@clux clux added the core generic apimachinery style work label Sep 16, 2022
@clux
Copy link
Member

clux commented Sep 16, 2022

Yeah, consistently k3d action failing. I'll fix that in master with some pinning if necessary. Going to deal with this anyway in #1008.

Going to merge this. Thanks a lot for all the work on this!

@clux clux merged commit cc2a2b9 into kube-rs:master Sep 16, 2022
@MikailBag MikailBag deleted the conv-types branch September 18, 2022 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-add changelog added category for prs core generic apimachinery style work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants