Skip to content

Commit

Permalink
nvidiagpu: adjust return consistency (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 authored Jan 3, 2025
1 parent 15c7ecd commit 6cd17c3
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/nvidiagpu/clusterpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewBuilderFromObjectString(apiClient *clients.Settings, almExample string)
"Initializing new Builder structure from almExample string with clusterPolicy name: %s",
clusterPolicy.Name)

builder := Builder{
builder := &Builder{
apiClient: apiClient.Client,
Definition: clusterPolicy,
}
Expand All @@ -71,9 +71,11 @@ func NewBuilderFromObjectString(apiClient *clients.Settings, almExample string)
glog.V(100).Infof("The ClusterPolicy object definition is nil")

builder.errorMsg = "ClusterPolicy 'Object.Definition' is nil"

return builder
}

return &builder
return builder
}

// Pull loads an existing clusterPolicy into Builder struct.
Expand All @@ -93,7 +95,7 @@ func Pull(apiClient *clients.Settings, name string) (*Builder, error) {
return nil, err
}

builder := Builder{
builder := &Builder{
apiClient: apiClient.Client,
Definition: &nvidiagpuv1.ClusterPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -114,7 +116,7 @@ func Pull(apiClient *clients.Settings, name string) (*Builder, error) {

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get returns clusterPolicy object if found.
Expand Down Expand Up @@ -191,16 +193,18 @@ func (builder *Builder) Create() (*Builder, error) {

glog.V(100).Infof("Creating the ClusterPolicy %s", builder.Definition.Name)

var err error
if !builder.Exists() {
err = builder.apiClient.Create(context.TODO(), builder.Definition)
if builder.Exists() {
return builder, nil
}

if err == nil {
builder.Object = builder.Definition
}
err := builder.apiClient.Create(context.TODO(), builder.Definition)
if err != nil {
return builder, err
}

return builder, err
builder.Object = builder.Definition

return builder, nil
}

// Update renovates the existing ClusterPolicy object with the definition in builder.
Expand Down Expand Up @@ -230,7 +234,7 @@ func (builder *Builder) Update(force bool) (*Builder, error) {
}
}

return builder, err
return builder, nil
}

// validate will check that the builder and builder definition are properly initialized before
Expand All @@ -247,13 +251,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

0 comments on commit 6cd17c3

Please sign in to comment.