Skip to content

Commit

Permalink
storage: adjust return consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Jan 8, 2025
1 parent 0fc848c commit 8b72ad2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
12 changes: 8 additions & 4 deletions pkg/storage/objectbucketclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ func NewObjectBucketClaimBuilder(
glog.V(100).Infof("The name of the objectBucketClaim is empty")

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

return builder
}

if nsname == "" {
glog.V(100).Infof("The nsname of the objectBucketClaim is empty")

builder.errorMsg = "objectBucketClaim 'nsname' cannot be empty"

return builder
}

return builder
Expand All @@ -88,7 +92,7 @@ func PullObjectBucketClaim(apiClient *clients.Settings, name, nsname string) (*O
return nil, err
}

builder := ObjectBucketClaimBuilder{
builder := &ObjectBucketClaimBuilder{
apiClient: apiClient.Client,
Definition: &noobaav1alpha1.ObjectBucketClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -116,7 +120,7 @@ func PullObjectBucketClaim(apiClient *clients.Settings, name, nsname string) (*O

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get returns objectBucketClaim object if found.
Expand All @@ -138,7 +142,7 @@ func (builder *ObjectBucketClaimBuilder) Get() (*noobaav1alpha1.ObjectBucketClai
return nil, err
}

return objectBucketClaimObj, err
return objectBucketClaimObj, nil
}

// Create makes a objectBucketClaim in the cluster and stores the created object in struct.
Expand Down Expand Up @@ -226,7 +230,7 @@ func (builder *ObjectBucketClaimBuilder) Update() (*ObjectBucketClaimBuilder, er

builder.Object = builder.Definition

return builder, err
return builder, nil
}

// WithStorageClassName sets the objectBucketClaim operator's storageClassName configuration.
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/ocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func PullStorageCluster(apiClient *clients.Settings, name, namespace string) (*S
return nil, err
}

builder := StorageClusterBuilder{
builder := &StorageClusterBuilder{
apiClient: apiClient.Client,
Definition: &ocsoperatorv1.StorageCluster{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -121,7 +121,7 @@ func PullStorageCluster(apiClient *clients.Settings, name, namespace string) (*S

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get fetches existing storageCluster from cluster.
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/pv.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func PullPersistentVolume(apiClient *clients.Settings, name string) (*PVBuilder,
return nil, fmt.Errorf("persistentVolume 'apiClient' cannot be empty")
}

builder := PVBuilder{
builder := &PVBuilder{
apiClient: apiClient,
Definition: &corev1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -59,7 +59,7 @@ func PullPersistentVolume(apiClient *clients.Settings, name string) (*PVBuilder,

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Exists checks whether the given PersistentVolume exists.
Expand Down
29 changes: 12 additions & 17 deletions pkg/storage/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewPVCBuilder(apiClient *clients.Settings, name, nsname string) *PVCBuilder
return nil
}

builder := PVCBuilder{
builder := &PVCBuilder{
Definition: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -64,15 +64,19 @@ func NewPVCBuilder(apiClient *clients.Settings, name, nsname string) *PVCBuilder
glog.V(100).Infof("PVC name is empty")

builder.errorMsg = "PVC name is empty"

return builder
}

if nsname == "" {
glog.V(100).Infof("PVC namespace is empty")

builder.errorMsg = "PVC namespace is empty"

return builder
}

return &builder
return builder
}

// WithPVCAccessMode configure access mode for the PV.
Expand Down Expand Up @@ -118,15 +122,12 @@ func (builder *PVCBuilder) WithPVCCapacity(capacity string) (*PVCBuilder, error)
if capacity == "" {
glog.V(100).Infof("Capacity of the PersistentVolumeClaim is empty")

builder.errorMsg = "Capacity of the PersistentVolumeClaim is empty"

return builder, fmt.Errorf(builder.errorMsg)
return builder, fmt.Errorf("capacity of the PersistentVolumeClaim is empty")
}

defer func() (*PVCBuilder, error) {
if r := recover(); r != nil {
glog.V(100).Infof("Failed to parse %v", capacity)
builder.errorMsg = fmt.Sprintf("Failed to parse: %v", capacity)

return builder, fmt.Errorf("failed to parse: %v", capacity)
}
Expand All @@ -149,10 +150,8 @@ func (builder *PVCBuilder) WithStorageClass(storageClass string) (*PVCBuilder, e
if storageClass == "" {
glog.V(100).Infof("Empty storageClass requested for the PersistentVolumeClaim", storageClass)

builder.errorMsg = fmt.Sprintf("Empty storageClass requested for the PersistentVolumeClaim %s",
return builder, fmt.Errorf("empty storageClass requested for the PersistentVolumeClaim %s",
builder.Definition.Name)

return builder, fmt.Errorf(builder.errorMsg)
}

builder.Definition.Spec.StorageClassName = &storageClass
Expand All @@ -168,19 +167,15 @@ func (builder *PVCBuilder) WithVolumeMode(volumeMode string) (*PVCBuilder, error
glog.V(100).Infof(fmt.Sprintf("Empty volumeMode requested for the PersistentVolumeClaim %s in %s namespace",
builder.Definition.Name, builder.Definition.Namespace))

builder.errorMsg = fmt.Sprintf("Empty volumeMode requested for the PersistentVolumeClaim %s in %s namespace",
return builder, fmt.Errorf("empty volumeMode requested for the PersistentVolumeClaim %s in %s namespace",
builder.Definition.Name, builder.Definition.Namespace)

return builder, fmt.Errorf(builder.errorMsg)
}

if !validateVolumeMode(volumeMode) {
glog.V(100).Infof(fmt.Sprintf("Unsupported VolumeMode: %s", volumeMode))

builder.errorMsg = fmt.Sprintf("Unsupported VolumeMode %q requested for %s PersistentVolumeClaim in %s namespace",
return builder, fmt.Errorf("unsupported VolumeMode %q requested for %s PersistentVolumeClaim in %s namespace",
volumeMode, builder.Definition.Name, builder.Definition.Name)

return builder, fmt.Errorf(builder.errorMsg)
}

// volumeMode is string while Spec.VolumeMode requires pointer to corev1.PersistentVolumeMode,
Expand Down Expand Up @@ -295,7 +290,7 @@ func PullPersistentVolumeClaim(
return nil, fmt.Errorf("persistentVolumeClaim 'apiClient' cannot be empty")
}

builder := PVCBuilder{
builder := &PVCBuilder{
apiClient: apiClient,
Definition: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -324,7 +319,7 @@ func PullPersistentVolumeClaim(

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Exists checks whether the given PersistentVolumeClaim exists.
Expand Down

0 comments on commit 8b72ad2

Please sign in to comment.