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

kubectl --kubeconfig cannot merge multiple files #468

Merged
merged 4 commits into from
Apr 22, 2019
Merged

Conversation

KnVerey
Copy link
Contributor

@KnVerey KnVerey commented Apr 18, 2019

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

@KnVerey KnVerey force-pushed the revert_config_flag branch 2 times, most recently from 7385fe8 to 75853c4 Compare April 18, 2019 19:05
@@ -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}"
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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?
Copy link
Contributor Author

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.

Copy link
Contributor

@RyanBrushett RyanBrushett left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@timothysmith0609 timothysmith0609 left a 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.

lib/kubernetes-deploy/kubeclient_builder.rb Outdated Show resolved Hide resolved
lib/kubernetes-deploy/kubeclient_builder.rb Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple kubeconfig files broken
3 participants