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

Make types on AdmissionRequest and AdmissionResponse public #977

Merged
merged 2 commits into from Aug 9, 2022

Conversation

clux
Copy link
Member

@clux clux commented Aug 6, 2022

Was making writing serde-less unit tests for admission controller input more difficult then they had to
be. Oversight that it was left private. See #976

Was making writing serde-less unit tests more difficult then they had to
be. Oversight that it was left private. See #976

Signed-off-by: clux <sszynrae@gmail.com>
@clux clux added the changelog-add changelog added category for prs label Aug 6, 2022
@clux clux added this to the 0.75.0 milestone Aug 6, 2022
@clux
Copy link
Member Author

clux commented Aug 6, 2022

There is actually one slight downside to doing this though... By making these types pub, it is easier for users to construct invalid AdmissionResponse types in actual admission controller code whereas the builder flow would force the the logic to preserve the types field throughout when moving through the flow:

AdmissionReview input -> AdmissionRequest via TryInto -> AdmissionResponse via From/::invalid -> AdmissionReview via ::into_review

The TryInto and From impls preserves the types.

However, leaving them private means people can only unit test AdmissionReview with serde. Is that OK?
I don't think it is. While having tests in raw json sends a clear signal that this is a fixture and the data is verbatim from the apiserver, it also makes it awkward to obtain and distinguish between test cases when the user wants to cover all the bases manually. Maybe the solution here is more documentation on the intended flow 🤔

@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2022

Codecov Report

Merging #977 (9f91581) into master (050bf9d) will increase coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #977      +/-   ##
==========================================
+ Coverage   72.35%   72.37%   +0.02%     
==========================================
  Files          64       64              
  Lines        4438     4438              
==========================================
+ Hits         3211     3212       +1     
+ Misses       1227     1226       -1     
Impacted Files Coverage Δ
kube-core/src/admission.rs 61.11% <ø> (ø)
kube-runtime/src/wait.rs 71.69% <0.00%> (+1.88%) ⬆️

Signed-off-by: clux <sszynrae@gmail.com>
@clux
Copy link
Member Author

clux commented Aug 6, 2022

Have added a little more documentation on the admission flow, I think it's actually pretty good already. If people wishes to construct the types manually in controllers then it's going against what the documentation says (which now at every step mentions the main path). The documentation does not mention manually constructing types at all.

@clux clux changed the title Make AdmissionRequest::types public Make AdmissionRequest::types and AdmissionResponse::types public Aug 6, 2022
@clux clux changed the title Make AdmissionRequest::types and AdmissionResponse::types public Make types field on AdmissionRequest and AdmissionResponse public Aug 6, 2022
@clux clux changed the title Make types field on AdmissionRequest and AdmissionResponse public Make types on AdmissionRequest and AdmissionResponse public Aug 6, 2022
Copy link
Member

@nightkr nightkr left a comment

Choose a reason for hiding this comment

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

I think this sounds OK, we're already exposing all of K8s' usual objects in all their gory detail (via k8s-openapi).

@clux clux merged commit bf885f0 into master Aug 9, 2022
@clux clux deleted the admission-pub branch August 9, 2022 12:11
JuyunLee added a commit to JuyunLee/kube-rs that referenced this pull request Aug 12, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants