-
Notifications
You must be signed in to change notification settings - Fork 244
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
refactor (shell) : detect shell on windows using gopsutil too (#4588) #4591
base: main
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
8bb4473
to
9f7677b
Compare
pkg/os/util.go
Outdated
@@ -127,3 +127,12 @@ func RemoveFileGlob(glob string) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func IsPresentInList(arr []string, str string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already exists as Contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I was going to use this but I noticed a unit test is failing on Windows due to these changes. This line was returning bash on Windows powershells:
Line 41 in 6d72284
userShell, err := shell.GetShell("") |
On checking the process tree during unit test execution, it shows processes like this:
cmd.test.exe
-> go.exe
-> bash.exe
I've added another utility method in order to just match the prefix instead of matching entire string.
pkg/os/shell/shell.go
Outdated
if err != nil { | ||
return "" | ||
} | ||
if crcos.IsPresentInList(supportedShell, processName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be easier to review if it did not mix code movement with functional changes. I'd suggest having a commit where this code is moved to shell.go
without any changes, and then a commit porting the Windows code to use detectShellByCheckingProcessTree
with these crcos.IsPresentInList
and such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've split the PR into two commits with first commit containing code reorganization and second including actual change
1d18663
to
9e42792
Compare
pkg/strings/strings.go
Outdated
}) | ||
} | ||
|
||
func IsPresentInListSatisfying(input []string, toMatch string, matchingPredicate func(string, string) bool) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While looking for naming ideas in go standard packages (usual name for such a function is ContainsFunc
), I realized the slices
package has both Contains
and ContainsFunc
, we can use these instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks a lot! I'm sorry I should've checked this.
9e42792
to
6864d0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an outdated + Add a utility method in strings for verifying a slice contains an element matching the provided predicate.
in the commit log of the second commit, otherwise looks good to me!
6864d0e
to
1d5be39
Compare
@cfergeau : Thanks for noticing! I've updated the commit message. I'll also create a follow up PR to make use of slice.Contains to replace the equivalent method in crcstrings.Contains |
…ows refactor Related to crc-org#4588 Move shell detection related methods from shell_unix.go to shell.go so that they can be accessed from Windows code as well Signed-off-by: Rohan Kumar <rohaan@redhat.com>
+ Update `shell_windows.go` to use detectShellByCheckingProcessTree instead of relying on SHELL environment variable. + Remove hardcoded check from detectShellByCheckingProcessTree for shell types, use already present supportedShell slice. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
1d5be39
to
8398309
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfergeau The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@rohanKanojia: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Description
As a follow up to #4572, updating shell detection logic on windows to also rely on gopsutil library to detect the shell name by inspecting parent processes of
crc.exe
process.Fixes: #4588
Relates to: PR #4572
Type of change
test, version modification, documentation, etc.)
Proposed changes
This PR mostly includes moving some methods so that they become accessible in windows environments too.
gopsutil
logic fromshell_unix.go
->shell.go
so that it can be reused inshell_windows.go
as wellshell_linux.go
/shell_darwin.go
as they only contained a single constant that I moved toshell_unix.go
getProcessEntry
and related methods fromshell_windows.go
as we're reusing gopsutil approach that is working well on WindowsTesting
crc oc-env
is working as expected inContribution Checklist