From 481249f06de6e187e571b434c99dc9386cf82079 Mon Sep 17 00:00:00 2001 From: janiskemper Date: Mon, 13 Nov 2023 10:59:50 +0100 Subject: [PATCH] :sparkles: Add conditions for rootDeviceHint validation Add conditions to make validation of rootDeviceHints in the bare metal provisioning process easily visible to the user. small other change: remove second call to obtain storage devices, as the information is already specified in the object itself. --- api/v1beta1/conditions_const.go | 9 +++++++++ pkg/services/baremetal/host/host.go | 22 ++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/api/v1beta1/conditions_const.go b/api/v1beta1/conditions_const.go index 7068febb1..5aa2c43de 100644 --- a/api/v1beta1/conditions_const.go +++ b/api/v1beta1/conditions_const.go @@ -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" diff --git a/pkg/services/baremetal/host/host.go b/pkg/services/baremetal/host/host.go index a8b0fc4f4..2a099616d 100644 --- a/pkg/services/baremetal/host/host.go +++ b/pkg/services/baremetal/host/host.go @@ -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{} } @@ -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 {