Skip to content

Commit

Permalink
nad: adjust return consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Dec 19, 2024
1 parent 75a2d0c commit 9d60f49
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 28 deletions.
22 changes: 16 additions & 6 deletions pkg/nad/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewBuilder(apiClient *clients.Settings, name, nsname string) *Builder {
return nil
}

builder := Builder{
builder := &Builder{
apiClient: apiClient,
Definition: &nadV1.NetworkAttachmentDefinition{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -64,15 +64,19 @@ func NewBuilder(apiClient *clients.Settings, name, nsname string) *Builder {
glog.V(100).Infof("The name of the NetworkAttachmentDefinition is empty")

builder.errorMsg = "NAD name is empty"

return builder
}

if builder.Definition.Namespace == "" {
glog.V(100).Infof("The namespace of the NetworkAttachmentDefinition is empty")

builder.errorMsg = "NAD namespace is empty"

return builder
}

return &builder
return builder
}

// Pull pulls existing networkattachmentdefinition from cluster.
Expand All @@ -93,7 +97,7 @@ func Pull(apiClient *clients.Settings, name, nsname string) (*Builder, error) {
return nil, fmt.Errorf("failed to add nad v1 scheme to client schemes")
}

builder := Builder{
builder := &Builder{
apiClient: apiClient,
Definition: &nadV1.NetworkAttachmentDefinition{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -121,7 +125,7 @@ func Pull(apiClient *clients.Settings, name, nsname string) (*Builder, error) {

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get returns CatalogSource object if found.
Expand Down Expand Up @@ -324,12 +328,16 @@ func (builder *Builder) WithMasterPlugin(masterPlugin *MasterPlugin) *Builder {

if builder.Definition.Spec != emptyNadConfig {
builder.errorMsg = "error to redefine predefine NAD"

return builder
}

masterPluginSting, err := json.Marshal(masterPlugin)

if err != nil {
builder.errorMsg = err.Error()

return builder
}

builder.Definition.Spec.Config = string(masterPluginSting)
Expand All @@ -355,6 +363,8 @@ func (builder *Builder) WithPlugins(name string, plugins *[]Plugin) *Builder {

if err != nil {
builder.errorMsg = err.Error()

return builder
}

builder.Definition.Spec.Config = string(pluginsConfigString)
Expand Down Expand Up @@ -383,13 +393,13 @@ func (builder *Builder) 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
Loading

0 comments on commit 9d60f49

Please sign in to comment.