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 UTF-16 encoded kubeconfig files #1654

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Conversation

goenning
Copy link
Contributor

Motivation

Windows PowerShell uses the Unicode UTF-16LE encoding by default, which means that kubeconfig files may be encoded as UTF16 if they're being generated by Windows PS.

kubectl can parse UTF16 kubeconfig files, so I thought we could add this directly into kube-rs

Solution

This PR basically adds support for UTF-16LE, UTF-16BE, UTF-8 with BOM and UTF-8

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.

thanks for this. on the face of it, it seems sensible. if you have time for a unit test or some comments that would also be appreciated. put a few quick questions.

fn read_path<P: AsRef<Path>>(path: P) -> io::Result<String> {
let bytes = fs::read(&path)?;
match bytes.as_slice() {
[0xFF, 0xFE, ..] => {
Copy link
Member

Choose a reason for hiding this comment

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

a comment for these magic numbers would be helpful for a future person 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would you prefer using encoding_rs crate instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps also putting a comment to use String::from_utf16le and friends when they become stable

kube-client/src/config/file_config.rs Show resolved Hide resolved
@clux clux added the changelog-fix changelog fix category for prs label Dec 5, 2024
@clux clux added this to the 0.98.0 milestone Dec 5, 2024
@goenning
Copy link
Contributor Author

goenning commented Dec 5, 2024

Test added

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.

Project coverage is 75.6%. Comparing base (60d3ebc) to head (37b5e39).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
kube-client/src/config/file_config.rs 77.8% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1654     +/-   ##
=======================================
+ Coverage   75.6%   75.6%   +0.1%     
=======================================
  Files         82      82             
  Lines       7405    7430     +25     
=======================================
+ Hits        5591    5611     +20     
- Misses      1814    1819      +5     
Files with missing lines Coverage Δ
kube-client/src/config/file_config.rs 75.7% <77.8%> (+0.6%) ⬆️

@clux clux merged commit 9265aa2 into kube-rs:main Dec 11, 2024
16 of 17 checks passed
Danil-Grigorev pushed a commit to Danil-Grigorev/kube that referenced this pull request Dec 18, 2024
* support for utf16 files

Signed-off-by: goenning <[email protected]>

* add test cases for utf16

Signed-off-by: goenning <[email protected]>

---------

Signed-off-by: goenning <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-fix changelog fix category for prs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants