Skip to content

Commit

Permalink
Hab based installation of chef-infra-client
Browse files Browse the repository at this point in the history
Signed-off-by: Ashique Saidalavi <[email protected]>
  • Loading branch information
ashiqueps committed Oct 22, 2024
1 parent 88d3e52 commit 4170a16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
25 changes: 19 additions & 6 deletions lib/kitchen/driver/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class Dokken < Kitchen::Driver::Base
default_config :cap_add, nil
default_config :cap_drop, nil
default_config :cgroupns_host, false
default_config :hab_installation, true
default_config :chef_image, "chef/chef"
default_config :chef_version, "latest"
default_config :habitat_image, "ashiqueps/chef-habitat"
default_config :habitat_version, "19.0.35"
default_config :data_image, "dokken/kitchen-cache:latest"
default_config :dns, nil
default_config :dns_search, nil
Expand Down Expand Up @@ -117,6 +120,14 @@ def destroy(_state)
dokken_delete_sandbox
end

def installer
@installer ||= if config[:hab_installation]
"habitat"
else
"chef"
end
end

private

class PartialHash < Hash
Expand Down Expand Up @@ -401,11 +412,11 @@ def create_chef_container(state)
rescue ::Docker::Error::NotFoundError
debug "Chef container does not exist, creating a new Chef container"
with_retries do
debug "driver - creating volume container #{chef_container_name} from #{chef_image}"
debug "driver - creating volume container #{chef_container_name} from #{installer_image}"
config = {
"name" => chef_container_name,
"Cmd" => "true",
"Image" => registry_image_path(chef_image),
"Image" => registry_image_path(installer_image),
"HostConfig" => {
"NetworkMode" => self[:network_mode],
},
Expand Down Expand Up @@ -474,8 +485,8 @@ def pull_platform_image
end

def pull_chef_image
debug "driver - pulling #{short_image_path(chef_image)}"
config[:pull_chef_image] ? pull_image(chef_image) : pull_if_missing(chef_image)
debug "driver - pulling #{short_image_path(installer_image)}"
config[:pull_chef_image] ? pull_image(installer_image) : pull_if_missing(installer_image)
end

def delete_image(name)
Expand Down Expand Up @@ -611,10 +622,12 @@ 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
def installer_image
return "#{config[:habitat_image]}:#{config[:habitat_version]}" if installer == "habitat"

"#{config[:chef_image]}:#{chef_version}"
end

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_bin"
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 ashiqueps/chef-infra-client -- chef-client " if instance.driver.installer == "habitat"

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

0 comments on commit 4170a16

Please sign in to comment.