Skip to content

Commit 3e6fd3e

Browse files
committed
inlined function which gets used only once.
1 parent b8ba0d3 commit 3e6fd3e

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

pkg/services/baremetal/host/host.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,49 @@ func (s *Service) actionRegistering(ctx context.Context) actionResult {
595595
}
596596
sshClient := s.scope.SSHClientFactory.NewClient(in)
597597

598-
ok, res := s.validateRescueSystemIsActive(ctx, sshClient)
599-
if !ok {
600-
return res
598+
// Check hostname with sshClient
599+
out := sshClient.GetHostName()
600+
hostName := trimLineBreak(out.StdOut)
601+
602+
if hostName != rescue {
603+
// give the reboot some time until it takes effect
604+
if s.hasJustRebooted() {
605+
return actionContinue{delay: 2 * time.Second}
606+
}
607+
608+
isSSHTimeoutError, isSSHConnectionRefusedError, err := s.analyzeSSHOutputRegistering(out)
609+
if err != nil {
610+
// This can happen if the bare-metal server was taken by another mgt-cluster.
611+
// Check in https://robot.hetzner.com/server for the "History" of the server.
612+
return actionError{err: fmt.Errorf("failed to handle incomplete boot - registering: %w", err)}
613+
}
614+
615+
failed, err := s.handleIncompleteBoot(ctx, true, isSSHTimeoutError, isSSHConnectionRefusedError)
616+
if failed {
617+
return s.recordActionFailure(infrav1.PermanentError, err.Error())
618+
}
619+
if err != nil {
620+
return actionError{err: fmt.Errorf(errMsgFailedHandlingIncompleteBoot, err)}
621+
}
622+
623+
if !isSSHTimeoutError && !isSSHConnectionRefusedError {
624+
msg := fmt.Sprintf("expected rescue system, but found different hostname %q", hostName)
625+
record.Warn(s.scope.HetznerBareMetalHost, "RegisteringFailed", msg)
626+
ctrl.LoggerFrom(ctx).Error(errors.New("RegisteringFailed"), msg)
627+
s.scope.HetznerBareMetalHost.SetError(infrav1.PermanentError, msg)
628+
return actionStop{}
629+
}
630+
631+
timeSinceReboot := "unknown"
632+
if s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated != nil {
633+
timeSinceReboot = time.Since(s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated.Time).String()
634+
}
635+
636+
s.scope.Logger.Info("Could not reach rescue system. Will retry some seconds later.", "out", out.String(), "hostName", hostName,
637+
"isSSHTimeoutError", isSSHTimeoutError, "isSSHConnectionRefusedError", isSSHConnectionRefusedError, "timeSinceReboot", timeSinceReboot)
638+
return actionContinue{delay: 10 * time.Second}
601639
}
640+
602641
output := sshClient.GetHardwareDetailsDebug()
603642
if output.Err != nil {
604643
return actionError{err: fmt.Errorf("failed to obtain hardware for debugging: %w", output.Err)}
@@ -686,45 +725,6 @@ func (s *Service) actionRegistering(ctx context.Context) actionResult {
686725
return actionComplete{}
687726
}
688727

689-
func (s *Service) validateRescueSystemIsActive(ctx context.Context, sshClient sshclient.Client) (ok bool, ar actionResult) {
690-
// Check hostname with sshClient
691-
out := sshClient.GetHostName()
692-
hostName := trimLineBreak(out.StdOut)
693-
if hostName == rescue {
694-
return true, actionContinue{}
695-
}
696-
// give the reboot some time until it takes effect
697-
if s.hasJustRebooted() {
698-
return false, actionContinue{delay: 2 * time.Second}
699-
}
700-
701-
isSSHTimeoutError, isSSHConnectionRefusedError, err := s.analyzeSSHOutputRegistering(out)
702-
if err != nil {
703-
// This can happen if the bare-metal server was taken by another mgt-cluster.
704-
// Check in https://robot.hetzner.com/server for the "History" of the server.
705-
return false, actionError{err: fmt.Errorf("failed to handle incomplete boot - registering: %w", err)}
706-
}
707-
708-
failed, err := s.handleIncompleteBoot(ctx, true, isSSHTimeoutError, isSSHConnectionRefusedError)
709-
if failed {
710-
return false, s.recordActionFailure(infrav1.PermanentError, err.Error())
711-
}
712-
if err != nil {
713-
return false, actionError{err: fmt.Errorf(errMsgFailedHandlingIncompleteBoot, err)}
714-
}
715-
timeSinceReboot := "unknown"
716-
if s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated != nil {
717-
timeSinceReboot = time.Since(s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated.Time).String()
718-
}
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-
}
723-
s.scope.Logger.Info("Could not reach rescue system. Will retry some seconds later.", "out", out.String(), "hostName", hostName,
724-
"isSSHTimeoutError", isSSHTimeoutError, "isSSHConnectionRefusedError", isSSHConnectionRefusedError, "timeSinceReboot", timeSinceReboot)
725-
return false, actionContinue{delay: 10 * time.Second}
726-
}
727-
728728
func validateRootDeviceWwnsAreSubsetOfExistingWwns(rootDeviceHints *infrav1.RootDeviceHints, storageDevices []infrav1.Storage) error {
729729
knownWWNs := make([]string, 0, len(storageDevices))
730730
for _, sd := range storageDevices {

0 commit comments

Comments
 (0)