-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
fix: align kube-rs with client-go config parsing #1077
Conversation
Signed-off-by: goenning <me@goenning.net>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1077 +/- ##
==========================================
+ Coverage 72.62% 72.66% +0.03%
==========================================
Files 65 65
Lines 4819 4832 +13
==========================================
+ Hits 3500 3511 +11
- Misses 1319 1321 +2
|
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
let current_context_name = &config.current_context.clone().unwrap_or_default(); | ||
let context_name = if let Some(name) = context { | ||
name | ||
} else if let Some(name) = &config.current_context { | ||
name | ||
} else { | ||
return Err(KubeconfigError::CurrentContextNotSet); | ||
current_context_name | ||
}; |
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.
Why was this changed?
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.
I think we can clean this up to:
let context_name = context
.or_else(|| config.current_context.as_ref())
.ok_or(KubeconfigError::CurrentContextNotSet)?;
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.
That was removed because current-context can be null/empty, at least that's how it works on kubectl. Do you think we should not change this in kube-rs?
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.
It can be null/empty when parsing, but should return an error when using the config, right?
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.
It depends, if we want similar behavior as client-go/kubectl, then an empty current-context is a valid value, because context names can be empty too.
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.
Confirmed kubectl works with a context with empty name when current context is empty.
We should align with client-go (library), and not kubectl (app), though.
- client-go's
Config
struct. (The link infile_config.rs
is pointing to the struct after the conversion.) - conversion from array of named objects to map. Errors on duplicate name. Missing name defaults to empty string because it's Go (nullable uses a pointer type).
- client-go has a validation to reject empty string context name. kubectl seems to work.
- What to do when there's no matching context. client-go has a validation to reject? kubectl seems to use a deprecated default?
We should probably use default value when missing instead of Option
to align with client-go's Config
as much as possible. Existing Option<String>
fields should be fixed if it doesn't match client-go for consistency (not in this PR). We should also follow omitempty
tags and skip serializing empty.
The problem is allowing null
. Do we really need to? It just feels weird to me, and I don't think this happens in practice.
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.
Maybe kubectl doesn't call ConfirmUsable?
I think this topic requires a bit more discussion and I don't want to rush into a solution, but I'd like to get the other changes on this PR merged soon.
As empty/null names are very edge cases scenarios, I'd like to propose that:
- revert changes to "name" fields and keep them as required Strings
- create an issue to discuss how do we want to handle those scenarios and implement that on a subsequent PR
What you think?
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.
Yeah, let's do that.
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.
It's possible that all this lax parsing is due to supporting config merges. Configs that are invalid in isolation (e.g. no current context) are fine in the merged setting (where another file sets the current-context).
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.
OK, I've reverted a bunch of changes so the PR is a lot simpler now. Still open for feedback! Thanks
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning <me@goenning.net>
Signed-off-by: goenning me@goenning.net
Motivation
Fixes #1076
Solution
I went through each field on my kubeconfig and removed it / set it to null, then I tried both kubectl and cube-rs example kubectl. If it succeeded on kubectl but failed on kube-rs, I added a default and moved to the next field.
The part I struggled with was parsing of null values, such as
I couldn't find how to do it with serve alone, so I had to add the serde_with crate.
Some properties like
cluster.server
are useless when empty, but the user might not be interacting with that cluster/context, so it should not be causing errors for something that might not impact its usage. If they try to use that cluster, they'll then have an error somewhere else.Note: I'll add a unit test as well, but I want to get it out here for feedback early on in case someone disagree with the solution.