Skip to content

Conversation

@PrajaktaPurohit
Copy link

@PrajaktaPurohit PrajaktaPurohit commented Mar 5, 2025

Description

This update modifies plan.sh and introduces a bin/kitchen executable that can intelligently determine whether it is being executed within a Habitat (hab) environment or as a binlinked binary. The script will automatically call the appropriate executables with the correct paths based on its execution context.

This change eliminates the need to manually set or modify environment variables related to the user’s Ruby environment (GEM_HOME, GEM_PATH, PATH) within the plan file or executable scripts.

Issues Resolved

  • No longer necessary to modify GEM_HOME, GEM_PATH, or PATH variables within wrapper scripts.
  • tke will always use the version of chef-cli that is packaged with it, regardless of any other installed or binlinked versions from a dke installation.
  • Ensures tke remains stable by always using its bundled dependencies, preventing conflicts with external versions

Type of Change

This change refines the Habitat packaging process for the individual components included in dke.

Check List

Testing & Acceptance Criteria

  • Any required dependencies (chef-cli) should be included in the tke Habitat package. No additional packages need to be installed for standalone tke to function.
  • tke should exclusively use the version of chef-cli shipped within its package, even when installed as part of dke.
  • External versions of chef-cli (whether binlinked or not) should not affect tke's functionality, ensuring stability after installation.
  • tke should not binlink any of its dependencies (chef-cli) when tke itself is binlinked.

Standalone tke Scenarios

  • Binlinked, with KITCHEN_VERSION set in the environment.
  • Binlinked, without KITCHEN_VERSION in the environment.
  • Run via hab pkg exec, with KITCHEN_VERSION set.
  • Run via hab pkg exec, without KITCHEN_VERSION set.
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ ls -la /usr/bin/kitchen
lrwxrwxrwx 1 root root 77 Mar  5 14:20 /usr/bin/kitchen -> /hab/pkgs/praj/chef-test-kitchen-enterprise/1.0.15/20250303150825/bin/kitchen
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ echo $KITCHEN_VERSION

ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ kitchen list
KITCHEN_VERSION is not set in the environment; The script is running as a binlinked script (Not in the hab context)
KITCHEN_VERSION is not set in the environment; The script is running as hab pkg exec or calling itself recursively from the binlinked script (In the hab context)
Instance             Driver  Provisioner  Verifier  Transport  Last Action  Last Error
default-ubuntu-2204  Dokken  Dokken       Inspec    Dokken     Converged    <None>
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ ls -la /usr/bin/kitchen
lrwxrwxrwx 1 root root 77 Mar  5 14:20 /usr/bin/kitchen -> /hab/pkgs/praj/chef-test-kitchen-enterprise/1.0.15/20250303150825/bin/kitchen
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ export KITCHEN_VERSION=1.0.15/20250303150825
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ echo $KITCHEN_VERSION
1.0.15/20250303150825
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ kitchen list
KITCHEN_VERSION: 1.0.15/20250303150825 set in the environment; The script is running as a binlinked script (Not in the hab context)
KITCHEN_VERSION: 1.0.15/20250303150825 set in the environment; The script is running as hab pkg exec or calling itself recursively from the binlinked script (In the hab context)
Instance             Driver  Provisioner  Verifier  Transport  Last Action  Last Error
default-ubuntu-2204  Dokken  Dokken       Inspec    Dokken     Converged    <None>
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ rm -fr /usr/bin/kitchen
rm: cannot remove '/usr/bin/kitchen': Permission denied
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ sudo rm -fr /usr/bin/kitchen
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ ls -la /usr/bin/
Display all 1028 possibilities? (y or n)
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ ls -la /usr/bin/kitchen
ls: cannot access '/usr/bin/kitchen': No such file or directory
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ echo $KITCHEN_VERSION
1.0.15/20250303150825
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ hab pkg exec praj/chef-test-kitchen-enterprise kitchen list
KITCHEN_VERSION: 1.0.15/20250303150825 set in the environment; The script is running as hab pkg exec or calling itself recursively from the binlinked script (In the hab context)
Instance             Driver  Provisioner  Verifier  Transport  Last Action  Last Error
default-ubuntu-2204  Dokken  Dokken       Inspec    Dokken     Converged    <None>
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ unset KITCHEN_VERSION
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ ls -la /usr/bin/kitchen
ls: cannot access '/usr/bin/kitchen': No such file or directory
ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ echo $KITCHEN_VERSION

ubuntu@ip-172-31-16-236:~/chef-repo/cookbooks/my_cookbook$ hab pkg exec praj/chef-test-kitchen-enterprise kitchen list
KITCHEN_VERSION is not set in the environment; The script is running as hab pkg exec or calling itself recursively from the binlinked script (In the hab context)
Instance             Driver  Provisioner  Verifier  Transport  Last Action  Last Error
default-ubuntu-2204  Dokken  Dokken       Inspec    Dokken     Converged    <None>

dke Integration Tests ( chef-cli related testing could be done with the Policyfile use for tke)

  • Install dke alongside a standalone binlinked tke, test when:
    • dke is not binlinked (tke should use its own chef-cli).
    • dke is binlinked (tke should use its own chef-cli).
  • Install dke alongside a standalone non-binlinked tke, test when:
    • dke is not binlinked (tke should use its own chef-cli).
    • dke is binlinked (tke should use its own chef-cli).

tke Integration Tests with dke Binlinking ( chef-cli related testing could be done with the Policyfile use for tke)

  • Install tke within a binlinked dke setup, test when:
    • tke is not binlinked (it should still use its own chef-cli).
    • tke is binlinked (it should still use its own chef-cli).
  • Install tke within a non-binlinked dke setup, test when:
    • tke is not binlinked (it should still use its own chef-cli).
    • tke is binlinked (it should still use its own chef-cli).

Version Stability Test

  • Install both tke and dke, then upgrade chef-cli to the latest version:
    • dke should use the latest or pinned version.
    • tke should continue using the chef-cli version it was packaged with.

Additional Considerations

  • Do we need a test case for a system with a different Ruby version installed?

Assumptions

  • The release process must ensure that all dependent components (tke, dke) are rebuilt and released whenever chef-cli is updated.
    • Example: If a new version of chef-cli is released, an automated process should trigger builds and releases for tke and dke to maintain compatibility.

@PrajaktaPurohit PrajaktaPurohit requested review from a team as code owners March 5, 2025 16:32
… as a part of the runtime_env in the setup. Also include TKE_VERSION to help identify running in the hab context. Since the PATH is set to include the tke/vendor directory in the hab context, it eliminates the need to create a wrapper script to call the kitchen executables.

fix: include the bin/kitchen executable. This identifies if kitchen is called in the hab context or as a binlinked command and appropriately calls the kitchen binary. It will also use the KITCHEN_VERSION of the kitchen hab conponent if set in the env. It uses the ruby bundled with tke to execute kitchen.
fix: include the bin/kitchen_gem executable. This will set an install path for kitchen custom plugins outside of the vendor dire, so they do not become unused by  a new tke install.

Signed-off-by: Prajakta Purohit <[email protected]>
@PrajaktaPurohit PrajaktaPurohit force-pushed the praj/include_chef_cli_as_a_hab_dep_bak branch from 8b8de9b to 7b8b216 Compare March 5, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants