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

Added chef-server-ctl version functionality #1485

Merged
merged 1 commit into from
Apr 13, 2018

Conversation

thomascate
Copy link

Added basic functionality for chef-server-ctl to report the version from the version-manifest.txt file. If it detects it's running in Habitat it will derive the version from the IDENT file in the hab package.

Signed-off-by: Thomas Cate tcate@chef.io

@thomascate thomascate requested a review from a team April 10, 2018 21:14

# detect if running as a habitat service
if File.exist?('/hab/svc/chef-server-ctl/PID')
#code for populating version through /version endpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over comment artifact perhaps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

# detect if running as a habitat service
if File.exist?('/hab/svc/chef-server-ctl/PID')
#code for populating version through /version endpoint
puts "running in hab"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't really think this is necessary - seems like a left over debugging statement perhaps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

if File.exist?('/hab/svc/chef-server-ctl/PID')
#code for populating version through /version endpoint
puts "running in hab"
ident_file = File.read('../IDENT')
Copy link
Contributor

@jeremymv2 jeremymv2 Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I always like to use the File.expand_path('../../IDENT', __FILE__) pattern to ensure a more deterministic file path, otherwise the relative path thing can bite sometimes depending on the situation.

end

puts version

Copy link
Contributor

@jeremymv2 jeremymv2 Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps put an error handler after line 29 to handle any Errno::ENOENT?

rescue Errno::ENOENT => ex
  puts "Error determining version! #{ex.message}"

The rescue would line up with the add_command_under_category and end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding error checking, I'm going to use e as the var and log instead of puts, to match how errors are handled in other parts of chef-server-ctl. For example rotate_credentials.rb

@jeremymv2
Copy link
Contributor

Having this simple yet important feature would be nice!

Copy link
Contributor

@markan markan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very much in favor of this. Minor fix suggestion above, but otherwise +1

ident_file = File.read('../IDENT')
version = "chef-server #{ident_file.split('/')[2]}"
else
version = File.readlines('/opt/opscode/version-manifest.txt')[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might do JSON.parse(File.read('/opt/opscode/version-manifest.json'))['build_version'] instead. I suspect the json file might be more future proof that relying on the first line of the txt file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on the fence as to which file to use, I'll switch over to the json.

Copy link
Contributor

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good addition.

puts version
rescue Errno::ENOENT => e
puts "Error determining version!"
log(e.message, :error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor note] I think this depends on the glob-order loading of ctl-commands to work. The log command in omnibus-ctl takes 1 argument; however that function is overwritten by the definitions in these two commands:

omnibus/files/private-chef-ctl-commands/backup.rb
omnibus/files/private-chef-ctl-commands/rotate_credentials.rb

However, I don't think we should block a useful command on cleaning that up.

@markan
Copy link
Contributor

markan commented Apr 12, 2018

Once you have all the changes, please squash/rebase and make sure you have signed off on the commit (git commit -s --amend) will fixup missing signoffs.

@thomascate thomascate force-pushed the tc/add-version-command branch 2 times, most recently from fa44e11 to 53d2d3d Compare April 13, 2018 17:34
Signed-off-by: Thomas Cate <tcate@chef.io>
@thomascate thomascate merged commit f462cd7 into master Apr 13, 2018
@thomascate thomascate deleted the tc/add-version-command branch April 13, 2018 18:54
robbkidd added a commit to chef/supermarket that referenced this pull request May 16, 2019
Matches the one in Chef Server[1]

[1] chef/chef-server#1485

Signed-off-by: Robb Kidd <rkidd@chef.io>
robbkidd added a commit to chef/supermarket that referenced this pull request May 16, 2019
Matches the one in Chef Server[1]

[1] chef/chef-server#1485

Signed-off-by: Robb Kidd <rkidd@chef.io>
robbkidd added a commit to chef/supermarket that referenced this pull request Sep 18, 2019
Matches the one in Chef Server[1]

[1] chef/chef-server#1485

Signed-off-by: Robb Kidd <rkidd@chef.io>
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.

4 participants