Skip to content

Commit

Permalink
bmh: address return consistency (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 authored Dec 19, 2024
1 parent b649c94 commit ae9c02f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
46 changes: 21 additions & 25 deletions pkg/bmh/baremetalhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewBuilder(
return nil
}

builder := BmhBuilder{
builder := &BmhBuilder{
apiClient: apiClient.Client,
Definition: &bmhv1alpha1.BareMetalHost{
Spec: bmhv1alpha1.BareMetalHostSpec{
Expand All @@ -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.
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 != "" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/bmh/hfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ae9c02f

Please sign in to comment.