Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderboltsid committed May 6, 2024
1 parent 87f0011 commit 5e3954f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ func getPrismCentralClientForCluster(ctx context.Context, k8sClient client.Clien
conditions.MarkTrue(cluster, infrav1.CredentialRefSecretOwnerSetCondition)

clientHelper := nutanixClient.NewHelper(secretInformer, mapInformer)
mep, err := clientHelper.BuildManagementEndpoint(ctx, cluster)
managementEndpoint, err := clientHelper.BuildManagementEndpoint(ctx, cluster)
if err != nil {
log.Error(err, fmt.Sprintf("error occurred while getting management endpoint for cluster %q", cluster.GetNamespacedName()))
conditions.MarkFalse(cluster, infrav1.PrismCentralClientCondition, infrav1.PrismCentralClientInitializationFailed, capiv1.ConditionSeverityError, err.Error())
Expand All @@ -837,7 +837,7 @@ func getPrismCentralClientForCluster(ctx context.Context, k8sClient client.Clien

v3Client, err := nutanixClient.NutanixClientCache.GetOrCreate(&nutanixClient.CacheParams{
NutanixCluster: cluster,
PrismManagementEndpoint: mep,
PrismManagementEndpoint: managementEndpoint,
})
if err != nil {
log.Error(err, "error occurred while getting nutanix prism client from cache")
Expand Down
44 changes: 22 additions & 22 deletions controllers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"testing"

"github.com/golang/mock/gomock"
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
nutanixClientV3 "github.com/nutanix-cloud-native/prism-go-client/v3"
credentialtypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
prismclientv3 "github.com/nutanix-cloud-native/prism-go-client/v3"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
Expand All @@ -38,7 +38,7 @@ import (
infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
mockctlclient "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/mocks/ctlclient"
mockk8sclient "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/mocks/k8sclient"
nutanixClient "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/pkg/client"
nutanixclient "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/pkg/client"
)

func TestControllerHelpers(t *testing.T) {
Expand All @@ -63,7 +63,7 @@ func TestControllerHelpers(t *testing.T) {
Namespace: "default",
},
Spec: infrav1.NutanixClusterSpec{
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
// Adding port info to override default value (0)
Port: 9440,
},
Expand Down Expand Up @@ -151,9 +151,9 @@ func TestReconcileCredentialRefWithValidCredentialRef(t *testing.T) {
fakeClient := mockctlclient.NewMockClient(ctrl)
nutanixCluster := &infrav1.NutanixCluster{
Spec: infrav1.NutanixClusterSpec{
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
CredentialRef: &credentialTypes.NutanixCredentialReference{
Kind: credentialTypes.SecretKind,
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
CredentialRef: &credentialtypes.NutanixCredentialReference{
Kind: credentialtypes.SecretKind,
Name: "test-credential",
Namespace: "test-ns",
},
Expand Down Expand Up @@ -182,9 +182,9 @@ func TestReconcileCredentialRefWithValidCredentialRefFailedUpdate(t *testing.T)
fakeClient := mockctlclient.NewMockClient(ctrl)
nutanixCluster := &infrav1.NutanixCluster{
Spec: infrav1.NutanixClusterSpec{
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
CredentialRef: &credentialTypes.NutanixCredentialReference{
Kind: credentialTypes.SecretKind,
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
CredentialRef: &credentialtypes.NutanixCredentialReference{
Kind: credentialtypes.SecretKind,
Name: "test-credential",
Namespace: "test-ns",
},
Expand Down Expand Up @@ -212,11 +212,11 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
capiCluster := &v1beta1.Cluster{}
cluster := &infrav1.NutanixCluster{
Spec: infrav1.NutanixClusterSpec{
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
Address: "prismcentral.nutanix.com",
Port: 9440,
CredentialRef: &credentialTypes.NutanixCredentialReference{
Kind: credentialTypes.SecretKind,
CredentialRef: &credentialtypes.NutanixCredentialReference{
Kind: credentialtypes.SecretKind,
Name: "test-credential",
Namespace: "test-ns",
},
Expand Down Expand Up @@ -258,17 +258,17 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
fakeClient.EXPECT().Get(ctx, gomock.Any(), gomock.Any()).Return(nil)
fakeClient.EXPECT().Update(ctx, gomock.Any()).Return(nil)

creds := []credentialTypes.Credential{
creds := []credentialtypes.Credential{
{
Type: credentialTypes.BasicAuthCredentialType,
Type: credentialtypes.BasicAuthCredentialType,
Data: []byte(`{"prismCentral":{"username":"user","password":"password"}}`),
},
}
credsMarshal, err := json.Marshal(creds)
require.NoError(t, err)
secret := &corev1.Secret{
Data: map[string][]byte{
credentialTypes.KeyName: credsMarshal,
credentialtypes.KeyName: credsMarshal,
},
}
secretNamespaceLister := mockk8sclient.NewMockSecretNamespaceLister(ctrl)
Expand All @@ -284,29 +284,29 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
})

t.Run("GetOrCreate succeeds", func(t *testing.T) {
oldNutanixClientCache := nutanixClient.NutanixClientCache
oldNutanixClientCache := nutanixclient.NutanixClientCache
defer func() {
nutanixClient.NutanixClientCache = oldNutanixClientCache
nutanixclient.NutanixClientCache = oldNutanixClientCache
}()
// Create a new client cache with session auth disabled to avoid network calls in tests
nutanixClient.NutanixClientCache = nutanixClientV3.NewClientCache()
nutanixclient.NutanixClientCache = prismclientv3.NewClientCache()

ctrl := gomock.NewController(t)
fakeClient := mockctlclient.NewMockClient(ctrl)
fakeClient.EXPECT().Get(ctx, gomock.Any(), gomock.Any()).Return(nil)
fakeClient.EXPECT().Update(ctx, gomock.Any()).Return(nil)

creds := []credentialTypes.Credential{
creds := []credentialtypes.Credential{
{
Type: credentialTypes.BasicAuthCredentialType,
Type: credentialtypes.BasicAuthCredentialType,
Data: []byte(`{"prismCentral":{"username":"user","password":"password"}}`),
},
}
credsMarshal, err := json.Marshal(creds)
require.NoError(t, err)
secret := &corev1.Secret{
Data: map[string][]byte{
credentialTypes.KeyName: credsMarshal,
credentialtypes.KeyName: credsMarshal,
},
}
secretNamespaceLister := mockk8sclient.NewMockSecretNamespaceLister(ctrl)
Expand Down

0 comments on commit 5e3954f

Please sign in to comment.