Skip to content
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

🐛 Fix provision condition time lag #1005

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions pkg/services/baremetal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (s *Service) Reconcile(ctx context.Context) (result reconcile.Result, err e

// reconcile state
actResult := hostStateMachine.ReconcileState()

result, err = actResult.Result()
if err != nil {
return reconcile.Result{Requeue: true}, fmt.Errorf("action %q failed: %w", initialState, err)
Expand Down Expand Up @@ -144,6 +145,8 @@ func SaveHostAndReturn(ctx context.Context, cl client.Client, host *infrav1.Hetz
}

func (s *Service) actionPreparing() actionResult {
markProvisionPending(s.scope.HetznerBareMetalHost, infrav1.StatePreparing)

server, err := s.scope.RobotClient.GetBMServer(s.scope.HetznerBareMetalHost.Spec.ServerID)
if err != nil {
s.handleRobotRateLimitExceeded(err, "GetBMServer")
Expand Down Expand Up @@ -498,6 +501,8 @@ func (s *Service) ensureRescueMode() error {
}

func (s *Service) actionRegistering() actionResult {
markProvisionPending(s.scope.HetznerBareMetalHost, infrav1.StateRegistering)

creds := sshclient.CredentialsFromSecret(s.scope.RescueSSHSecret, s.scope.HetznerCluster.Spec.SSHKeys.RobotRescueSecretRef)
in := sshclient.Input{
PrivateKey: creds.PrivateKey,
Expand Down Expand Up @@ -907,6 +912,8 @@ func validateStdOut(stdOut string) (string, error) {
}

func (s *Service) actionImageInstalling() actionResult {
markProvisionPending(s.scope.HetznerBareMetalHost, infrav1.StateImageInstalling)

creds := sshclient.CredentialsFromSecret(s.scope.RescueSSHSecret, s.scope.HetznerCluster.Spec.SSHKeys.RobotRescueSecretRef)
in := sshclient.Input{
PrivateKey: creds.PrivateKey,
Expand Down Expand Up @@ -1028,6 +1035,8 @@ func getDeviceNames(wwn []string, storageDevices []infrav1.Storage) []string {
}

func (s *Service) actionProvisioning() actionResult {
markProvisionPending(s.scope.HetznerBareMetalHost, infrav1.StateProvisioning)

host := s.scope.HetznerBareMetalHost

portAfterInstallImage := host.Spec.Status.SSHSpec.PortAfterInstallImage
Expand Down Expand Up @@ -1079,8 +1088,6 @@ func (s *Service) actionProvisioning() actionResult {
}

host.ClearError()
conditions.MarkTrue(host, infrav1.ProvisionSucceededCondition)

return actionComplete{}
}

Expand Down Expand Up @@ -1190,6 +1197,7 @@ func verifyConnectionRefused(sshClient sshclient.Client, port int) bool {
}

func (s *Service) actionEnsureProvisioned() (ar actionResult) {
markProvisionPending(s.scope.HetznerBareMetalHost, infrav1.StateEnsureProvisioned)
sshClient := s.scope.SSHClientFactory.NewClient(sshclient.Input{
PrivateKey: sshclient.CredentialsFromSecret(s.scope.OSSSHSecret, s.scope.HetznerBareMetalHost.Spec.Status.SSHSpec.SecretRef).PrivateKey,
Port: s.scope.HetznerBareMetalHost.Spec.Status.SSHSpec.PortAfterCloudInit,
Expand Down Expand Up @@ -1276,6 +1284,7 @@ func (s *Service) actionEnsureProvisioned() (ar actionResult) {
}
}

conditions.MarkTrue(s.scope.HetznerBareMetalHost, infrav1.ProvisionSucceededCondition)
s.scope.HetznerBareMetalHost.ClearError()
return actionComplete{}
}
Expand Down Expand Up @@ -1537,3 +1546,13 @@ func (s *Service) hasJustRebooted() bool {
s.scope.HetznerBareMetalHost.Spec.Status.ErrorType == infrav1.ErrorTypeHardwareRebootTriggered) &&
!hasTimedOut(s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated, rebootWaitTime)
}

func markProvisionPending(host *infrav1.HetznerBareMetalHost, state infrav1.ProvisioningState) {
conditions.MarkFalse(
host,
infrav1.ProvisionSucceededCondition,
infrav1.StillProvisioningReason,
clusterv1.ConditionSeverityInfo,
"host is still provisioning - state %q", state,
)
}
9 changes: 0 additions & 9 deletions pkg/services/baremetal/host/state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,6 @@ func (hsm *hostStateMachine) ReconcileState() (actionRes actionResult) {
// Assume credentials are ready for now. This can be changed while the state is handled.
conditions.MarkTrue(hsm.host, infrav1.CredentialsAvailableCondition)

// Set condition on false. It will be set on true if host is provisioned during reconcilement
conditions.MarkFalse(
hsm.host,
infrav1.ProvisionSucceededCondition,
infrav1.StillProvisioningReason,
clusterv1.ConditionSeverityInfo,
"host is provisioning - current state: %q", hsm.host.Spec.Status.ProvisioningState,
)

if stateHandler, found := hsm.handlers()[initialState]; found {
return stateHandler()
}
Expand Down
Loading