@@ -354,6 +354,9 @@ func (s *Service) ensureSSHKey(sshSecretRef infrav1.SSHSecretRef, sshSecret *cor
354
354
return sshKey , actionComplete {}
355
355
}
356
356
357
+ // handleIncompleteBoot checks if the reboot was successful.
358
+ // If it was not successful, it tries other reboot methods.
359
+ // Order: SSH -> Software -> Hardware.
357
360
func (s * Service ) handleIncompleteBoot (isRebootIntoRescue , isTimeout , isConnectionRefused bool ) (failed bool , err error ) {
358
361
// Connection refused error might be a sign that the ssh port is wrong - but might also come
359
362
// right after a reboot and is expected then. Therefore, we wait for some time and if the
@@ -713,7 +716,10 @@ func (s *Service) validateRescueSystemIsActive(sshClient sshclient.Client) (ok b
713
716
if s .scope .HetznerBareMetalHost .Spec .Status .LastUpdated != nil {
714
717
timeSinceReboot = time .Since (s .scope .HetznerBareMetalHost .Spec .Status .LastUpdated .Time ).String ()
715
718
}
716
-
719
+ if ! isSSHTimeoutError && ! isSSHConnectionRefusedError {
720
+ s .scope .Logger .Info ("Expected the rescue system, but got different hostname" , "hostName" , hostName , "timeSinceReboot" , timeSinceReboot )
721
+ return false , actionContinue {delay : 10 * time .Second }
722
+ }
717
723
s .scope .Logger .Info ("Could not reach rescue system. Will retry some seconds later." , "out" , out .String (), "hostName" , hostName ,
718
724
"isSSHTimeoutError" , isSSHTimeoutError , "isSSHConnectionRefusedError" , isSSHConnectionRefusedError , "timeSinceReboot" , timeSinceReboot )
719
725
return false , actionContinue {delay : 10 * time .Second }
@@ -1105,9 +1111,12 @@ func (s *Service) actionPreProvisioning(ctx context.Context) actionResult {
1105
1111
}
1106
1112
sshClient := s .scope .SSHClientFactory .NewClient (in )
1107
1113
1108
- ok , res := s .validateRescueSystemIsActive (sshClient )
1109
- if ! ok {
1110
- return res
1114
+ out := sshClient .GetHostName ()
1115
+ hostName := trimLineBreak (out .StdOut )
1116
+ if hostName != rescue {
1117
+ // This is unexpected. We should be in rescue mode.
1118
+ return actionError {err : fmt .Errorf ("expected rescue system, but got %q: %s" , hostName ,
1119
+ out .String ())}
1111
1120
}
1112
1121
1113
1122
exitStatus , output , err := sshClient .ExecutePreProvisionCommand (ctx , s .scope .PreProvisionCommand )
@@ -1141,9 +1150,12 @@ func (s *Service) actionImageInstalling(ctx context.Context) actionResult {
1141
1150
}
1142
1151
sshClient := s .scope .SSHClientFactory .NewClient (in )
1143
1152
1144
- ok , res := s .validateRescueSystemIsActive (sshClient )
1145
- if ! ok {
1146
- return res
1153
+ out := sshClient .GetHostName ()
1154
+ hostName := trimLineBreak (out .StdOut )
1155
+ if hostName != rescue {
1156
+ // This is unexpected. We should be in rescue mode.
1157
+ return actionError {err : fmt .Errorf ("expected rescue system, but got %q: %s" , hostName ,
1158
+ out .String ())}
1147
1159
}
1148
1160
1149
1161
state , err := sshClient .GetInstallImageState ()
0 commit comments