Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvidiagpu: adjust return consistency #850

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
klaskosk marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
Loading