Skip to content

Commit

Permalink
nmstate: adjust return consistency (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 authored Jan 3, 2025
1 parent 826ff2e commit 3a57026
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
6 changes: 4 additions & 2 deletions pkg/nmstate/nmstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewBuilder(apiClient *clients.Settings, name string) *Builder {
return nil
}

builder := Builder{
builder := &Builder{
apiClient: apiClient.Client,
Definition: &nmstateV1.NMState{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -57,9 +57,11 @@ func NewBuilder(apiClient *clients.Settings, name string) *Builder {
glog.V(100).Infof("The name of the NMState is empty")

builder.errorMsg = "NMState 'name' cannot be empty"

return builder
}

return &builder
return builder
}

// Exists checks whether the given NMState exists.
Expand Down
8 changes: 4 additions & 4 deletions pkg/nmstate/nodenetworkstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func PullNodeNetworkState(apiClient *clients.Settings, name string) (*StateBuild
return nil, err
}

stateBuilder := StateBuilder{
stateBuilder := &StateBuilder{
apiClient: apiClient.Client,
Object: &nmstateV1alpha1.NodeNetworkState{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -214,7 +214,7 @@ func PullNodeNetworkState(apiClient *clients.Settings, name string) (*StateBuild
return nil, fmt.Errorf("nodeNetworkState object %s does not exist", name)
}

return &stateBuilder, nil
return stateBuilder, nil
}

// validate will check that the builder and builder definition are properly initialized before
Expand All @@ -231,13 +231,13 @@ func (builder *StateBuilder) validate() (bool, error) {
if builder.Object == 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("%s builder cannot have nil apiClient", resourceCRD)
}

if builder.errorMsg != "" {
Expand Down
20 changes: 10 additions & 10 deletions pkg/nmstate/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewPolicyBuilder(apiClient *clients.Settings, name string, nodeSelector map
return nil
}

builder := PolicyBuilder{
builder := &PolicyBuilder{
apiClient: apiClient.Client,
Definition: &nmstateV1.NodeNetworkConfigurationPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -78,6 +78,8 @@ func NewPolicyBuilder(apiClient *clients.Settings, name string, nodeSelector map
glog.V(100).Infof("The name of the NodeNetworkConfigurationPolicy is empty")

builder.errorMsg = "nodeNetworkConfigurationPolicy 'name' cannot be empty"

return builder
}

if len(nodeSelector) == 0 {
Expand All @@ -86,7 +88,7 @@ func NewPolicyBuilder(apiClient *clients.Settings, name string, nodeSelector map
builder.errorMsg = "nodeNetworkConfigurationPolicy 'nodeSelector' cannot be empty map"
}

return &builder
return builder
}

// Get returns NodeNetworkConfigurationPolicy object if found.
Expand Down Expand Up @@ -260,15 +262,15 @@ func (builder *PolicyBuilder) WithBondInterface(slavePorts []string, bondName, m
glog.V(100).Infof("error to add Bond mode %s, allowed modes are %v", mode, allowedBondModes)

builder.errorMsg = "invalid Bond mode parameter"

return builder
}

if bondName == "" {
glog.V(100).Infof("The bondName can not be empty string")

builder.errorMsg = "The bondName is empty sting"
}

if builder.errorMsg != "" {
return builder
}

Expand Down Expand Up @@ -298,13 +300,13 @@ func (builder *PolicyBuilder) WithVlanInterface(baseInterface string, vlanID uin
glog.V(100).Infof("The baseInterface can not be empty string")

builder.errorMsg = "nodenetworkconfigurationpolicy 'baseInterface' cannot be empty"

return builder
}

if vlanID > 4094 {
builder.errorMsg = "invalid vlanID, allowed vlanID values are between 0-4094"
}

if builder.errorMsg != "" {
return builder
}

Expand Down Expand Up @@ -405,9 +407,7 @@ func (builder *PolicyBuilder) WithAbsentInterface(interfaceName string) *PolicyB
glog.V(100).Infof("The interfaceName can not be empty string")

builder.errorMsg = "nodenetworkconfigurationpolicy 'interfaceName' cannot be empty"
}

if builder.errorMsg != "" {
return builder
}

Expand Down Expand Up @@ -493,13 +493,13 @@ func (builder *PolicyBuilder) 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("%s builder cannot have nil apiClient", resourceCRD)
}

if builder.errorMsg != "" {
Expand Down

0 comments on commit 3a57026

Please sign in to comment.