-
Notifications
You must be signed in to change notification settings - Fork 51
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
Improve job hostname detection on Windows #448
Improve job hostname detection on Windows #448
Conversation
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.
Dropped some comments
return hostname; | ||
if (computer != null) { | ||
try { | ||
EnvVars computerEnvironment = computer.getEnvironment(); |
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.
What's the difference between EnvVars
coming as the method parameter and the EnvVars
coming from the Computer
object? Are those not the same?
Also, how do we know the "computer" envvars have prevalence over "global?" envvars?
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.
The ones coming from the computer are relevant for that specific node (could be either the controller or a worker node). The ones coming as method parameter are the ones associated with the job. Debugging shows they're different.
String envVarsHostname = getNodeHostname(envVars); | ||
if (isValidHostname(envVarsHostname)) { | ||
return envVarsHostname; | ||
} | ||
|
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 seems we're duplicating this piece of logic with computer EnvVars and other EnvVars.
Have we considered the following approach to avoid this duplicated code?
EnvVars finalEnvVars = computer != null ? compute.getEnvironment() : envVars
...
String envVarsHostname = getNodeHostname(envVars);
if (isValidHostname(envVarsHostname)) {
return envVarsHostname;
}
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.
I would like to examine both, as I couldn't find a clear definition of what the "job-level" vars are: I suspect they might include whatever's being set in the Job config UI or in the pipeline DSL. The computer-level ones, however, include variables set externally on the worker node that executes the job.
if (isUnix(rootPath)) { | ||
command = new String[]{"hostname", "-f"}; | ||
} else { | ||
command = new String[]{"hostname"}; |
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.
Does this command work in all Windows environments? If not, what would happen in that case? Would it throw an exception?
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.
Not sure about every possible version, but it does seem to be a standard command. If it doesn't work an exception will be thrown, then caught in this method and logged. null
hostname will be returned. Given that this is the last possible fallback, seems like an acceptable outcome
Requirements for Contributing to this repository
What does this PR do?
Improves job hostname detection logic:
Computer
are examined to see if manually set hostname is providedhostname
shell command is executed remotely (now for Windows machines too, as Windows shell support this command)Description of the Change
Alternate Designs
Possible Drawbacks
Verification Process
Additional Notes
Release Notes
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.