Skip to content

Commit

Permalink
fixup! refactor: client.go file helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoshkin committed Jan 25, 2024
1 parent bac3fb4 commit d8b6f45
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/nutanixcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (ncl *NutanixCluster) SetConditions(conditions capiv1.Conditions) {
ncl.Status.Conditions = conditions
}

func (ncl *NutanixCluster) GetCredentialRefForCluster() (*credentialTypes.NutanixCredentialReference, error) {
func (ncl *NutanixCluster) GetPrismCentralCredentialRef() (*credentialTypes.NutanixCredentialReference, error) {
prismCentralInfo := ncl.Spec.PrismCentral
if prismCentralInfo == nil {
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/nutanixcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestGetCredentialRefForCluster(t *testing.T) {
tt := tt // Capture range variable.
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ref, err := tt.nutanixCluster.GetCredentialRefForCluster()
ref, err := tt.nutanixCluster.GetPrismCentralCredentialRef()
assert.Equal(t, tt.expectedCredentialsRef, ref)
assert.Equal(t, tt.expectedErr, err)
})
Expand Down
10 changes: 6 additions & 4 deletions controllers/nutanixcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (r *NutanixClusterReconciler) reconcileCategoriesDelete(rctx *nctx.ClusterC

func (r *NutanixClusterReconciler) reconcileCredentialRefDelete(ctx context.Context, nutanixCluster *infrav1.NutanixCluster) error {
log := ctrl.LoggerFrom(ctx)
credentialRef, err := mustGetCredentialRefForCluster(nutanixCluster)
credentialRef, err := getPrismCentralCredentialRefForCluster(nutanixCluster)
if err != nil {
log.Error(err, fmt.Sprintf("error occurred while getting credential ref for cluster %s", nutanixCluster.Name))
return err
Expand Down Expand Up @@ -372,7 +372,7 @@ func (r *NutanixClusterReconciler) reconcileCredentialRefDelete(ctx context.Cont

func (r *NutanixClusterReconciler) reconcileCredentialRef(ctx context.Context, nutanixCluster *infrav1.NutanixCluster) error {
log := ctrl.LoggerFrom(ctx)
credentialRef, err := mustGetCredentialRefForCluster(nutanixCluster)
credentialRef, err := getPrismCentralCredentialRefForCluster(nutanixCluster)
if err != nil {
return err
}
Expand Down Expand Up @@ -419,9 +419,11 @@ func (r *NutanixClusterReconciler) reconcileCredentialRef(ctx context.Context, n
return nil
}

func mustGetCredentialRefForCluster(nutanixCluster *infrav1.NutanixCluster) (*credentialTypes.NutanixCredentialReference, error) {
// getPrismCentralCredentialRefForCluster calls nutanixCluster.GetPrismCentralCredentialRef() function
// and returns an error if nutanixCluster is nil
func getPrismCentralCredentialRefForCluster(nutanixCluster *infrav1.NutanixCluster) (*credentialTypes.NutanixCredentialReference, error) {
if nutanixCluster == nil {
return nil, fmt.Errorf("cannot get credential reference if nutanix cluster object is nil")
}
return nutanixCluster.GetCredentialRefForCluster()
return nutanixCluster.GetPrismCentralCredentialRef()
}
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (n *NutanixClientHelper) buildProviderFromNutanixCluster(nutanixCluster *in
if prismCentralInfo.Port == 0 {
return nil, ErrPrismPortNotSet
}
credentialRef, err := nutanixCluster.GetCredentialRefForCluster()
credentialRef, err := nutanixCluster.GetPrismCentralCredentialRef()
if err != nil {
//nolint:wrapcheck // error is already wrapped
return nil, err
Expand Down

0 comments on commit d8b6f45

Please sign in to comment.