summaryrefslogtreecommitdiff
path: root/lib/chef/knife
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2015-12-22 12:56:08 -0800
committerMatt Wrock <matt@mattwrock.com>2015-12-22 12:56:08 -0800
commit7983e70b7d80ac5063fd7b9182d6fd41ff39c5c3 (patch)
tree53501d8ee5dc4837e3fb15a7f93944ee48f6a21f /lib/chef/knife
parente41ae9e7f407e8fa139bb154813805b46c0b5d1f (diff)
downloadchef-7983e70b7d80ac5063fd7b9182d6fd41ff39c5c3.tar.gz
no longer wait on node search to refresh vault but pass created ApiClient instead
Diffstat (limited to 'lib/chef/knife')
-rw-r--r--lib/chef/knife/bootstrap.rb2
-rw-r--r--lib/chef/knife/bootstrap/chef_vault_handler.rb31
-rw-r--r--lib/chef/knife/bootstrap/client_builder.rb4
3 files changed, 16 insertions, 21 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 30ea3cac6c..d958ddf336 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -377,7 +377,7 @@ class Chef
client_builder.run
- chef_vault_handler.run(node_name: config[:chef_node_name])
+ chef_vault_handler.run(client_builder.client)
bootstrap_context.client_pem = client_builder.client_path
else
diff --git a/lib/chef/knife/bootstrap/chef_vault_handler.rb b/lib/chef/knife/bootstrap/chef_vault_handler.rb
index f658957499..9d0dfec621 100644
--- a/lib/chef/knife/bootstrap/chef_vault_handler.rb
+++ b/lib/chef/knife/bootstrap/chef_vault_handler.rb
@@ -28,8 +28,8 @@ class Chef
# @return [Chef::Knife::UI] ui object for output
attr_accessor :ui
- # @return [String] name of the node (technically name of the client)
- attr_reader :node_name
+ # @return [Chef::ApiClient] vault client
+ attr_reader :client
# @param knife_config [Hash] knife merged config, typically @config
# @param ui [Chef::Knife::UI] ui object for output
@@ -38,18 +38,15 @@ class Chef
@ui = ui
end
- # Updates the chef vault items for the newly created node.
+ # Updates the chef vault items for the newly created client.
#
- # @param node_name [String] name of the node (technically name of the client)
- # @todo: node_name should be mandatory (ruby 2.0 compat)
- def run(node_name: nil)
+ # @param client [Chef::ApiClient] vault client
+ def run(client)
return unless doing_chef_vault?
sanity_check
- @node_name = node_name
-
- ui.info("Updating Chef Vault, waiting for client to be searchable..") while wait_for_client
+ @client = client
update_bootstrap_vault_json!
end
@@ -126,7 +123,7 @@ class Chef
def update_vault(vault, item)
require_chef_vault!
bootstrap_vault_item = load_chef_bootstrap_vault_item(vault, item)
- bootstrap_vault_item.clients("name:#{node_name}")
+ bootstrap_vault_item.clients(client)
bootstrap_vault_item.save
end
@@ -141,22 +138,18 @@ class Chef
public :load_chef_bootstrap_vault_item # for stubbing
- # Helper used to spin waiting for the client to appear in search.
- #
- # @return [Boolean] true if the client is searchable
- def wait_for_client
- sleep 1
- !Chef::Search::Query.new.search(:client, "name:#{node_name}")[0]
- end
-
# Helper to very lazily require the chef-vault gem
def require_chef_vault!
@require_chef_vault ||=
begin
+ error_message = "Knife bootstrap needs version 2.6.0 or higher of the chef-vault gem to configure chef vault items"
require 'chef-vault'
+ if Gem::Version.new(ChefVault::VERSION) < Gem::Version.new('2.6.0')
+ raise error_message
+ end
true
rescue LoadError
- raise "Knife bootstrap cannot configure chef vault items when the chef-vault gem is not installed"
+ raise error_message
end
end
diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb
index 7eb1e22628..6414ac5c72 100644
--- a/lib/chef/knife/bootstrap/client_builder.rb
+++ b/lib/chef/knife/bootstrap/client_builder.rb
@@ -34,6 +34,8 @@ class Chef
attr_accessor :chef_config
# @return [Chef::Knife::UI] ui object for output
attr_accessor :ui
+ # @return [Chef::ApiClient] client saved on run
+ attr_reader :client
# @param knife_config [Hash] Hash of knife config settings
# @param chef_config [Hash] Hash of chef config settings
@@ -51,7 +53,7 @@ class Chef
ui.info("Creating new client for #{node_name}")
- create_client!
+ @client = create_client!
ui.info("Creating new node for #{node_name}")