-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Conversation
Signed-off-by: goenning <[email protected]>
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.
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, ..] => { |
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.
a comment for these magic numbers would be helpful for a future person 😅
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.
would you prefer using encoding_rs
crate instead?
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.
Perhaps also putting a comment to use String::from_utf16le and friends when they become stable
Signed-off-by: goenning <[email protected]>
Test added |
Codecov ReportAttention: Patch coverage is
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
|
* 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]>
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