Skip to content

Commit

Permalink
Merge pull request #1051 from syself/rootdevicehints-condition
Browse files Browse the repository at this point in the history
✨ Add conditions for rootDeviceHint validation
  • Loading branch information
janiskemper authored Nov 14, 2023
2 parents 613b310 + 481249f commit ba26588
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
9 changes: 9 additions & 0 deletions api/v1beta1/conditions_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ const (
HostReadyCondition clusterv1.ConditionType = "HostReady"
)

const (
// RootDeviceHintsValidatedCondition reports on whether the root device hints could be validated.
RootDeviceHintsValidatedCondition clusterv1.ConditionType = "RootDeviceHintsValidated"
// ValidationFailedReason indicates that the specified root device hints could not be successfully validated.
ValidationFailedReason = "ValidationFailed"
// StorageDeviceNotFoundReason indicates that the storage device specified in the root device hints could not be found.
StorageDeviceNotFoundReason = "StorageDeviceNotFound"
)

const (
// TargetClusterReadyCondition reports on whether the kubeconfig in the target cluster is ready.
TargetClusterReadyCondition clusterv1.ConditionType = "TargetClusterReady"
Expand Down
22 changes: 16 additions & 6 deletions pkg/services/baremetal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,28 @@ func (s *Service) actionRegistering() actionResult {

if s.scope.HetznerBareMetalHost.Spec.RootDeviceHints == nil ||
!s.scope.HetznerBareMetalHost.Spec.RootDeviceHints.IsValid() {
conditions.MarkFalse(
s.scope.HetznerBareMetalHost,
infrav1.RootDeviceHintsValidatedCondition,
infrav1.ValidationFailedReason,
clusterv1.ConditionSeverityError,
"validation failed - check specified rootDeviceHints",
)
return s.recordActionFailure(infrav1.RegistrationError, infrav1.ErrorMessageMissingRootDeviceHints)
}

if err := validateRootDevices(s.scope.HetznerBareMetalHost.Spec.RootDeviceHints, s.scope.HetznerBareMetalHost.Spec.Status.HardwareDetails.Storage); err != nil {
conditions.MarkFalse(
s.scope.HetznerBareMetalHost,
infrav1.RootDeviceHintsValidatedCondition,
infrav1.StorageDeviceNotFoundReason,
clusterv1.ConditionSeverityError,
err.Error(),
)
return s.recordActionFailure(infrav1.RegistrationError, err.Error())
}

conditions.MarkTrue(s.scope.HetznerBareMetalHost, infrav1.RootDeviceHintsValidatedCondition)
s.scope.HetznerBareMetalHost.ClearError()
return actionComplete{}
}
Expand Down Expand Up @@ -1000,12 +1015,7 @@ func (s *Service) createAutoSetupInput(sshClient sshclient.Client) (autoSetupInp
}

// get device names from storage device
storageDevices, err := obtainHardwareDetailsStorage(sshClient)
if err != nil {
return autoSetupInput{}, actionError{err: fmt.Errorf("failed to obtain storage devices: %w", err)}
}

deviceNames := getDeviceNames(s.scope.HetznerBareMetalHost.Spec.RootDeviceHints.ListOfWWN(), storageDevices)
deviceNames := getDeviceNames(s.scope.HetznerBareMetalHost.Spec.RootDeviceHints.ListOfWWN(), s.scope.HetznerBareMetalHost.Spec.Status.HardwareDetails.Storage)

// we need at least one storage device
if len(deviceNames) == 0 {
Expand Down

0 comments on commit ba26588

Please sign in to comment.