-
Notifications
You must be signed in to change notification settings - Fork 115
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
kubectl --kubeconfig cannot merge multiple files #468
Conversation
7385fe8
to
75853c4
Compare
@@ -28,13 +28,14 @@ def test_build_client_from_multiple_config_files | |||
Kubeclient::Client.any_instance.stubs(:discover) | |||
# Set KUBECONFIG to include multiple config files | |||
dummy_config = File.join(__dir__, '../../fixtures/kube-config/dummy_config.yml') | |||
kubeconfig = "#{ENV['KUBECONFIG']}:#{dummy_config}" |
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.
This wasn't providing great multi-config coverage in our CI, which doesn't set the env var.
@@ -27,7 +26,6 @@ def run(*args, log_failure: nil, use_context: true, use_namespace: true, output: | |||
output_is_sensitive = @output_is_sensitive_default if output_is_sensitive.nil? | |||
|
|||
args = args.unshift("kubectl") | |||
args.push("--kubeconfig=#{@kubeconfig}") |
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.
def build_kubeclient(api_version:, context:, endpoint_path: nil) | ||
# Find a context defined in kube conf files that matches the input context by name | ||
configs = config_files.map { |f| KubeConfig.read(f) } | ||
config = configs.find { |c| c.contexts.include?(context) } | ||
raise TaskConfigurationError, "No kubeconfig files found in #{@kubeconfig_files}" if kubeclient_configs.empty? |
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.
This is new. As CI pointed out, without it, if you try to build a kubeclient without validating the config files, and one of them is missing, we would 💥 with an Errno::ENOENT
. My thinking with the way I addressed this is:
- We don't need to be re-reading the config files every time we build a new client, hence the new memoization above
- If for whatever reason the code did not run the validation before building a client, and we have both a valid config containing the desired context and a missing file, we should go ahead and do what the user wanted. If we can't do what the user wanted, we should throw our own more helpful error, not
Errno::ENOENT
.
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.
lgtm
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.
LGTM. One small question about repeated validation of file existence but I don't mind the fact that we do it twice.
966ffe7
to
4b14166
Compare
255432c
to
a67a4ea
Compare
What are you trying to accomplish with this PR?
Revert only the problematic part of #428, i.e. https://github.com/Shopify/kubernetes-deploy/pull/428/files#diff-f5478b2ac59d4babc30470442f3a8656. I still like the Class refactor, but
--kubeconfig
cannot merge multiple files, so if we want to use it we'll need to be more clever about what we pass through. Ironically the test we removed would have caught this regression. I'm sorry I did not catch that. I added it back verbatim (after confirming it does reproduce the bug on master).Fixes #463
How is this accomplished?
Making the
kubectl
class go back to depending on the env var.As a bonus, make it proactively validate this dependency.after CI showed this broke default location support, I removed it to keep this PR the smallest viable fix.I think there is a nicer way to deal with this, but I wasn't able to put together a proposal as quickly as I wanted to. I think we should merge something really simple like this so we have time to discuss the right refactor to do.
What could go wrong?
If somebody consuming this project as a gem switched away from the environment variable, they'll need to switch back (it is still effectively mandatory for CLI usage).
@Shopify/cloudx