Package io.jenkins.plugins.kubevirt
Class SshAuthHelper
java.lang.Object
io.jenkins.plugins.kubevirt.SshAuthHelper
Shared utility for detecting and retrying SSH authentication failures.
Cloud-init may still be injecting authorized_keys even though sshd is already running. The Jenkins SSH launcher treats auth failure as permanent, so this helper adds a retry layer on top.
The detection works by scanning the agent's log output for messages produced by the SSH launcher (e.g. "Server rejected the N private key(s)…").
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA single SSH launch attempt. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetSshAuthError(Computer computer, long sincePosition) Reads a computer's log (from the given byte position) to detect SSH authentication errors.static voidlaunchWithAuthRetry(SlaveComputer computer, TaskListener listener, SshAuthHelper.SshLaunchAction launchAction, String nodeName) Launches SSH with automatic retry on authentication failures.
-
Method Details
-
getSshAuthError
Reads a computer's log (from the given byte position) to detect SSH authentication errors.- Parameters:
computer- the computer whose log to inspectsincePosition- byte offset to start reading from (0 for the entire log)- Returns:
- a description of the error if found, or
nullif no auth error was detected
-
launchWithAuthRetry
public static void launchWithAuthRetry(SlaveComputer computer, TaskListener listener, SshAuthHelper.SshLaunchAction launchAction, String nodeName) throws IOException, InterruptedException Launches SSH with automatic retry on authentication failures.The first attempt counts as attempt 1. If it fails with an auth error, up to
KubeVirtConfiguration.SSH_AUTH_MAX_RETRIESadditional attempts are made, sleepingKubeVirtConfiguration.SSH_AUTH_RETRY_INTERVAL_SECONDSseconds between each.Retries stop immediately when:
- The computer comes online (success)
- The failure is not an authentication error (different problem)
- The maximum number of attempts is reached
- Parameters:
computer- the agent computerlistener- task listener for user-facing log messageslaunchAction- callback invoked for each SSH launch attemptnodeName- node name used in log messages- Throws:
IOExceptionInterruptedException
-