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

move chef -v to golang #2062

Merged
merged 12 commits into from
Aug 25, 2021
Merged

move chef -v to golang #2062

merged 12 commits into from
Aug 25, 2021

Conversation

i5pranay93
Copy link
Contributor

@i5pranay93 i5pranay93 commented Jun 10, 2021

Adding the option for the chef -v through go wrapper

Description

Provides the option to pass -v/--version through chef-main-wrapper in golang, with a function version() where all the logic from chef-cli with ruby code is pulled and switched with golang

Related Issue

fixes #656
Related PR which will replace this in future #1465

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@i5pranay93 i5pranay93 requested review from a team as code owners June 10, 2021 15:07
@netlify
Copy link

netlify bot commented Jun 10, 2021

👷 Deploy Preview for chef-workstation processing.

🔨 Explore the source changes: a80f130

🔍 Inspect the deploy log: https://app.netlify.com/sites/chef-workstation/deploys/611cebafbe381100087a6cb4

@tas50
Copy link
Contributor

tas50 commented Jun 10, 2021

Before:

image

After:

image

Copy link
Member

@marcparadise marcparadise left a comment

Choose a reason for hiding this comment

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

I think it would make sense to move the implementation here as well. Moving the flag itself but still invoking chef-cli won't get the improvements that are requested in the original issue.

An implementation written for this PR won't be invalidated by #1465, though it may need to be updated a bit

"path"
"io/ioutil"
"encoding/json"
"github.com/mnogu/go-dig"
Copy link
Member

Choose a reason for hiding this comment

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

This looks helpful, but I'm concerned because it looks like it was created over the course of 1-2 days and has not received any attention since then.

Copy link
Member

Choose a reason for hiding this comment

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

I think I saw some talk around defining a nested struct to unmarshal into. While we can't do that for the gem version manifest, is it possible to do it for the workstation versoin manifest? Or is the structure of that file problematic, eg there's no array of definitions under software, but rather a bunch of named json objects there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think we can unmarshall gem manifest since it seems structured,
eg-

"wmi-lite": [
   "1.0.5"
 ],
 "xmlrpc": [
   "0.3.0"
 ],

but the structure of the file version manifest under software is a bunch of JSON object so two different structures were there in both file.

So I made it into interface which made it easier for me.

Copy link
Contributor Author

@i5pranay93 i5pranay93 Jun 21, 2021

Choose a reason for hiding this comment

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

This looks helpful, but I'm concerned because it looks like it was created over the course of 1-2 days and has not received any attention since then.

are we talking about this "github.com/mnogu/go-dig"??, I think code was pretty straight. i could have written same for it saved time and space for me.
edited -Hm, Seems its failing in buildkite. i will write it manually

if omnibusInstall() == true {
showVersionViaVersionManifest()
} else {
// todo "5.1,0 is coming from #{ChefCLI::VERSION} in ruby, need to figure out how to do this "
Copy link
Member

@marcparadise marcparadise Jun 21, 2021

Choose a reason for hiding this comment

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

I think we can eliminate the branch that does not come from an omnibus install, or consider it an error. This wrapper is only supported in an omnibus install.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, i will raise error.

Copy link
Contributor Author

@i5pranay93 i5pranay93 left a comment

Choose a reason for hiding this comment

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

pushed changes in new commits

@marcparadise
Copy link
Member

This looks good, but let's add some level of testing for Dig as well.

func omnibusRoot()string {
omnibusroot, err := filepath.Abs(path.Join(ExpectedOmnibusRoot()))
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for Chef Workstation")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this error also use the dist file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as in Chef Workstation part from "Can not find omnibus installation directory for Chef Workstation" can be used from dist ile ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it with fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for", dist.WorkstationProduct)

@tas50
Copy link
Contributor

tas50 commented Jun 29, 2021

This should get rebased on master

@tas50
Copy link
Contributor

tas50 commented Jun 29, 2021

}

func ExpectedOmnibusRoot()string {
groot := os.Getenv("GEM_ROOT")
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can assume this will be present in the user's environment because we're no longer loading this in the context of the ruby environment.

Instead, we should look relative to the chef executable directory.

@i5pranay93 i5pranay93 requested a review from a team as a code owner June 30, 2021 12:15
if omnibusInstall() == true {
showVersionViaVersionManifest()
} else {
fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for", dist.WorkstationProduct)
Copy link
Member

Choose a reason for hiding this comment

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

This message won't necessarily mean much to the person using it, who doesn't really have awareness of 'omnibus'. Instead, maybe "$PRODUCT has not been installed via the platform-specific package provided by $DISTRIBUTOR-NAME. Version information is not available."?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to my understanding,
$PRODUCT - would be a dynamic value containing e.g (Chef-workstation)
what would be $DISTRIBUTOR-NAME?? or may be I am understanding it wrong

Copy link
Member

@marcparadise marcparadise left a comment

Choose a reason for hiding this comment

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

Comments are inline. Please delete your local branch before pulling this down to avoid conflicts/merge breakage.

@tas50
Copy link
Contributor

tas50 commented Jul 2, 2021

I ran an adhoc of this and it's failing to pull the version on my mac:

❰tsmith❙~❱✔≻ chef -v
open /gem-version-manifest.json: no such file or directory
open /version-manifest.json: no such file or directory
ERROR: Can not find omnibus installation directory for Chef Workstation

@kagarmoe kagarmoe removed the request for review from a team July 8, 2021 18:50
@marcparadise
Copy link
Member

This is looking good - we're almost there.

Two things remaining - let's check the caess where we have errors that we can't reasonably recover from, and exit at those locations or return the errors to the caller(s) so that they can exit gracefully.

Separately, please run go fmt to format the source files.

Copy link
Contributor Author

@i5pranay93 i5pranay93 left a comment

Choose a reason for hiding this comment

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

Reviwed

if omnibusInstall() == true {
showVersionViaVersionManifest()
} else {
fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for", dist.WorkstationProduct)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to my understanding,
$PRODUCT - would be a dynamic value containing e.g (Chef-workstation)
what would be $DISTRIBUTOR-NAME?? or may be I am understanding it wrong

Provides the option to pass -v/--version through chef-main-wrapper in golang, with a
function version() where all the logic from chef-cli with ruby code is pulled and
switched with golang

This removes the overhead of starting the ruby VM to report version ,
most of which is loaded from files distributed in the chef-workstation build.

Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
…ibutor name in constat

Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
@tas50 tas50 merged commit 971d42e into main Aug 25, 2021
@tas50 tas50 deleted the pranay/move_chef_v_to_go_656 branch August 25, 2021 15:37
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.

Move chef -v to go
3 participants