Skip to content

Commit

Permalink
Merge pull request #2 from ashiqueps/CHEF-14239-dokken-hab-installation
Browse files Browse the repository at this point in the history
Hab based installation of chef-infra-client
  • Loading branch information
ashiqueps authored Nov 26, 2024
2 parents b308b8a + 95b77e7 commit 85b60ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/kitchen/driver/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Dokken < Kitchen::Driver::Base
default_config :cap_add, nil
default_config :cap_drop, nil
default_config :cgroupns_host, false
default_config :chef_image, "chef/chef"
default_config :chef_image, "chef/chef-hab"
default_config :chef_version, "latest"
default_config :data_image, "dokken/kitchen-cache:latest"
default_config :dns, nil
Expand Down Expand Up @@ -118,6 +118,16 @@ def destroy(_state)
dokken_delete_sandbox
end

# TODO: This method currently checks if the installer is a hab or omnibus based on the image name.
# Find a better way to determine the installer.
def installer
@installer ||= if config[:chef_image].include?("hab")
"habitat"
else
"chef"
end
end

private

class PartialHash < Hash
Expand Down Expand Up @@ -642,7 +652,7 @@ def wait_running_state(name, v)
end

def chef_container_name
config[:platform] != "" ? "chef-#{chef_version}-" + config[:platform].sub("/", "-") : "chef-#{chef_version}"
config[:platform] != "" ? "#{installer}-#{chef_version}-" + config[:platform].sub("/", "-") : "#{installer}-#{chef_version}"
end

def chef_image
Expand Down
14 changes: 11 additions & 3 deletions lib/kitchen/provisioner/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Dokken < Kitchen::Provisioner::ChefZero

default_config :root_path, "/opt/kitchen"
default_config :chef_binary, "/opt/chef/bin/chef-client"
default_config :hab_chef_binary, "/hab/hab"
default_config :chef_options, " -z"
default_config :chef_log_level, "warn"
default_config :chef_output_format, "doc"
Expand Down Expand Up @@ -100,14 +101,15 @@ def validate_config
# patching Kitchen::Provisioner::ChefZero#run_command
def run_command
validate_config
cmd = config[:chef_binary]
cmd = chef_executable
cmd << config[:chef_options].to_s
cmd << " -l #{config[:chef_log_level]}"
cmd << " -F #{config[:chef_output_format]}"
cmd << " -c /opt/kitchen/client.rb"
cmd << " -j /opt/kitchen/dna.json"
cmd << "--profile-ruby" if config[:profile_ruby]
cmd << "--slow-report" if config[:slow_resource_report]
cmd << " --profile-ruby" if config[:profile_ruby]
cmd << " --slow-report" if config[:slow_resource_report]
cmd << " --chef-license-key=#{config[:chef_license_key]}" if instance.driver.installer == "habitat" && config[:chef_license_key]

chef_cmd(cmd)
end
Expand All @@ -126,6 +128,12 @@ def cleanup_dokken_sandbox
debug("Cleaning up local sandbox in #{sandbox_path}")
FileUtils.rmtree(Dir.glob("#{sandbox_path}/*"))
end

def chef_executable
return "HAB_LICENSE='accept-no-persist' #{config[:hab_chef_binary]} pkg exec chef/chef-infra-client -- chef-client " if instance.driver.installer == "habitat"

"#{config[:chef_binary]}"
end
end
end
end

0 comments on commit 85b60ff

Please sign in to comment.