diff --git a/pkg/bmh/baremetalhost.go b/pkg/bmh/baremetalhost.go index 620609f04..c9c6beb08 100644 --- a/pkg/bmh/baremetalhost.go +++ b/pkg/bmh/baremetalhost.go @@ -47,7 +47,7 @@ func NewBuilder( return nil } - builder := BmhBuilder{ + builder := &BmhBuilder{ apiClient: apiClient.Client, Definition: &bmhv1alpha1.BareMetalHost{ Spec: bmhv1alpha1.BareMetalHostSpec{ @@ -73,36 +73,50 @@ func NewBuilder( glog.V(100).Infof("The name of the baremetalhost is empty") builder.errorMsg = "BMH 'name' cannot be empty" + + return builder } if nsname == "" { glog.V(100).Infof("The namespace of the baremetalhost is empty") builder.errorMsg = "BMH 'nsname' cannot be empty" + + return builder } if bmcAddress == "" { glog.V(100).Infof("The bootmacaddress of the baremetalhost is empty") builder.errorMsg = "BMH 'bmcAddress' cannot be empty" + + return builder } if bmcSecretName == "" { glog.V(100).Infof("The bmcsecret of the baremetalhost is empty") builder.errorMsg = "BMH 'bmcSecretName' cannot be empty" + + return builder } bootModeAcceptable := []string{"UEFI", "UEFISecureBoot", "legacy"} if !slices.Contains(bootModeAcceptable, bootMode) { builder.errorMsg = "not acceptable 'bootMode' value" + + return builder } if bootMacAddress == "" { + glog.V(100).Infof("The bootmacaddress of the baremetalhost is empty") + builder.errorMsg = "BMH 'bootMacAddress' cannot be empty" + + return builder } - return &builder + return builder } // WithRootDeviceDeviceName sets rootDeviceHints DeviceName to specified value. @@ -115,9 +129,7 @@ func (builder *BmhBuilder) WithRootDeviceDeviceName(deviceName string) *BmhBuild glog.V(100).Infof("The baremetalhost rootDeviceHint deviceName is empty") builder.errorMsg = "the baremetalhost rootDeviceHint deviceName cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -140,9 +152,7 @@ func (builder *BmhBuilder) WithRootDeviceHTCL(hctl string) *BmhBuilder { glog.V(100).Infof("The baremetalhost rootDeviceHint hctl is empty") builder.errorMsg = "the baremetalhost rootDeviceHint hctl cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -165,9 +175,7 @@ func (builder *BmhBuilder) WithRootDeviceModel(model string) *BmhBuilder { glog.V(100).Infof("The baremetalhost rootDeviceHint model is empty") builder.errorMsg = "the baremetalhost rootDeviceHint model cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -190,9 +198,7 @@ func (builder *BmhBuilder) WithRootDeviceVendor(vendor string) *BmhBuilder { glog.V(100).Infof("The baremetalhost rootDeviceHint vendor is empty") builder.errorMsg = "the baremetalhost rootDeviceHint vendor cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -215,9 +221,7 @@ func (builder *BmhBuilder) WithRootDeviceSerialNumber(serialNumber string) *BmhB glog.V(100).Infof("The baremetalhost rootDeviceHint serialNumber is empty") builder.errorMsg = "the baremetalhost rootDeviceHint serialNumber cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -240,9 +244,7 @@ func (builder *BmhBuilder) WithRootDeviceMinSizeGigabytes(size int) *BmhBuilder glog.V(100).Infof("The baremetalhost rootDeviceHint size is less than 0") builder.errorMsg = "the baremetalhost rootDeviceHint size cannot be less than 0" - } - if builder.errorMsg != "" { return builder } @@ -265,9 +267,7 @@ func (builder *BmhBuilder) WithRootDeviceWWN(wwn string) *BmhBuilder { glog.V(100).Infof("The baremetalhost rootDeviceHint wwn is empty") builder.errorMsg = "the baremetalhost rootDeviceHint wwn cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -290,9 +290,7 @@ func (builder *BmhBuilder) WithRootDeviceWWNWithExtension(wwnWithExtension strin glog.V(100).Infof("The baremetalhost rootDeviceHint wwnWithExtension is empty") builder.errorMsg = "the baremetalhost rootDeviceHint wwnWithExtension cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -315,9 +313,7 @@ func (builder *BmhBuilder) WithRootDeviceWWNVendorExtension(wwnVendorExtension s glog.V(100).Infof("The baremetalhost rootDeviceHint wwnVendorExtension is empty") builder.errorMsg = "the baremetalhost rootDeviceHint wwnVendorExtension cannot be empty" - } - if builder.errorMsg != "" { return builder } @@ -387,7 +383,7 @@ func Pull(apiClient *clients.Settings, name, nsname string) (*BmhBuilder, error) return nil, err } - builder := BmhBuilder{ + builder := &BmhBuilder{ apiClient: apiClient.Client, Definition: &bmhv1alpha1.BareMetalHost{ ObjectMeta: metav1.ObjectMeta{ @@ -415,7 +411,7 @@ func Pull(apiClient *clients.Settings, name, nsname string) (*BmhBuilder, error) builder.Definition = builder.Object - return &builder, nil + return builder, nil } // Create makes a bmh in the cluster and stores the created object in struct. @@ -486,7 +482,7 @@ func (builder *BmhBuilder) Get() (*bmhv1alpha1.BareMetalHost, error) { return nil, err } - return bmh, err + return bmh, nil } // Exists checks whether the given bmh exists. @@ -713,13 +709,13 @@ func (builder *BmhBuilder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf(fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD)) } if builder.errorMsg != "" { diff --git a/pkg/bmh/hfs.go b/pkg/bmh/hfs.go index 0835e2299..a3a49452a 100644 --- a/pkg/bmh/hfs.go +++ b/pkg/bmh/hfs.go @@ -40,7 +40,7 @@ func PullHFS(apiClient *clients.Settings, name, nsname string) (*HFSBuilder, err return nil, err } - builder := HFSBuilder{ + builder := &HFSBuilder{ apiClient: apiClient.Client, Definition: &bmhv1alpha1.HostFirmwareSettings{ ObjectMeta: metav1.ObjectMeta{ @@ -68,7 +68,7 @@ func PullHFS(apiClient *clients.Settings, name, nsname string) (*HFSBuilder, err builder.Definition = builder.Object - return &builder, nil + return builder, nil } // Get returns the HostFirmwareSettings object if found. @@ -132,7 +132,7 @@ func (builder *HFSBuilder) Create() (*HFSBuilder, error) { builder.Object = builder.Definition - return builder, err + return builder, nil } // Delete removes a HostFirmwareSettings from the cluster if it exists.