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

Hab based installation of chef-infra-client #2

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -117,6 +117,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 @@ -611,7 +621,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 @@ -102,14 +103,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 @@ -128,6 +130,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