Skip to content

Commit

Permalink
Revert "support chef image based on client version specified"
Browse files Browse the repository at this point in the history
This reverts commit f015bfb.
  • Loading branch information
Stromweld committed Feb 5, 2025
1 parent f015bfb commit 2ea8287
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ concurrency:
cancel-in-progress: true

jobs:
cookstyle:
chefstyle:
env:
BUNDLE_WITH: ${{ inputs.bundle_with }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: ["3.3"]
name: Cookstyle on Ruby
name: Chefstyle on Ruby
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -40,9 +40,9 @@ jobs:
bundler-cache: true
- uses: r7kamura/rubocop-problem-matchers-action@v1
if: steps.check.outputs.gemfile == 'true'
- name: Cookstyle
- name: Chef Style
if: steps.check.outputs.gemfile == 'true'
run: bundle exec cookstyle --chefstyle
run: bundle exec chefstyle

yamllint:
runs-on: ubuntu-latest
Expand Down
File renamed without changes.
21 changes: 12 additions & 9 deletions lib/kitchen/driver/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +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 do |driver|
version = driver[:chef_version].split(".").first
if version.match? /\A\d+\z/ && version.to_i < 19
"chef/chef"
else
"chef/chef-hab"
end
end
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 @@ -125,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 @@ -649,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
17 changes: 11 additions & 6 deletions lib/kitchen/provisioner/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
module Kitchen
module Provisioner
# @author Sean OMeara <[email protected]>
class Dokken < Kitchen::Provisioner::ChefInfra
class Dokken < Kitchen::Provisioner::ChefZero
kitchen_provisioner_api_version 2

plugin_version Kitchen::VERSION

default_config :root_path, "/opt/kitchen"
default_config :chef_binary, "#{chef_bin_path}/chef-client"
default_config :hab_binary, "/hab/bin/hab"
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 @@ -101,16 +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 << " --chef-license-key=#{config[:chef_license_key]}" if config[:chef_license_key]
cmd << " --chef-license-server=#{config[:chef_license_server]}" unless config[:chef_license_server].empty?
cmd << " --chef-license-key=#{config[:chef_license_key]}" if instance.driver.installer == "habitat" && config[:chef_license_key]

chef_cmd(cmd)
end
Expand All @@ -129,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 2ea8287

Please sign in to comment.