Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions internal/authctx/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var RefreshUserAuthContext = func(config *TanzuContext, refreshCondition func(er
refreshSMUserAuthCtx(config)
return
}

refreshSaaSUserAuthCtx(config)
}
}
Expand Down
8 changes: 5 additions & 3 deletions internal/helper/request_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/stretchr/testify/require"
)

const testMultiPathWithQueryParams = "p1/p2/p3?k1=v1&k2=v2"

func TestConstructRequestURL(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -75,7 +77,7 @@ func TestAppendQueryParams(t *testing.T) {
"k1": []string{"v1"},
"k2": []string{"v2"},
},
expected: "p1/p2/p3?k1=v1&k2=v2",
expected: testMultiPathWithQueryParams,
},
}

Expand Down Expand Up @@ -103,8 +105,8 @@ func TestString(t *testing.T) {
},
{
name: "case for multiple paths and query parameters",
requestURL: "p1/p2/p3?k1=v1&k2=v2",
expected: "p1/p2/p3?k1=v1&k2=v2",
requestURL: testMultiPathWithQueryParams,
expected: testMultiPathWithQueryParams,
},
}

Expand Down
83 changes: 49 additions & 34 deletions internal/resources/akscluster/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/akscluster"
)

const (
test127001 = "127.0.0.1"
testAzure = "azure"
testEastus = "eastus"
testEnable = "enable"
testName = "name"
testResourceGroup = "resource-group"
testSubId = "sub-id"
testTestCluster = "test-cluster"
testTestCred = "test-cred"
testVal = "val"

test127002 = "127.0.0.2"
)

func dataDiffFrom(t *testing.T, original map[string]any, updated map[string]any) *schema.ResourceData {
originalData := schema.TestResourceDataRaw(t, akscluster.ClusterSchema, original)
originalData.SetId("test-uid")
Expand All @@ -36,10 +51,10 @@ func dataDiffFrom(t *testing.T, original map[string]any, updated map[string]any)

func expectedFullName() *models.VmwareTanzuManageV1alpha1AksclusterFullName {
return &models.VmwareTanzuManageV1alpha1AksclusterFullName{
CredentialName: "test-cred",
SubscriptionID: "sub-id",
ResourceGroupName: "resource-group",
Name: "test-cluster",
CredentialName: testTestCred,
SubscriptionID: testSubId,
ResourceGroupName: testResourceGroup,
Name: testTestCluster,
}
}

Expand Down Expand Up @@ -89,18 +104,18 @@ func enableCSI(c *models.VmwareTanzuManageV1alpha1AksCluster) {
func aTestCluster(w ...clusterWither) *models.VmwareTanzuManageV1alpha1AksCluster {
c := &models.VmwareTanzuManageV1alpha1AksCluster{
FullName: &models.VmwareTanzuManageV1alpha1AksclusterFullName{
CredentialName: "test-cred",
ResourceGroupName: "resource-group",
SubscriptionID: "sub-id",
Name: "test-cluster",
CredentialName: testTestCred,
ResourceGroupName: testResourceGroup,
SubscriptionID: testSubId,
Name: testTestCluster,
},
Meta: &objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta{
UID: "test-uid",
},
Spec: &models.VmwareTanzuManageV1alpha1AksclusterSpec{
ClusterGroupName: "my-cluster-group",
Config: &models.VmwareTanzuManageV1alpha1AksclusterClusterConfig{
Location: "eastus",
Location: testEastus,
Version: "1.26.0",
NodeResourceGroupName: "my-node-group",
DiskEncryptionSetID: "disk-encryption-set-id",
Expand All @@ -120,7 +135,7 @@ func aTestCluster(w ...clusterWither) *models.VmwareTanzuManageV1alpha1AksCluste
EnableRbac: true,
},
APIServerAccessConfig: &models.VmwareTanzuManageV1alpha1AksclusterAPIServerAccessConfig{
AuthorizedIPRanges: []string{"127.0.0.1", "127.0.0.2"},
AuthorizedIPRanges: []string{test127001, test127002},
EnablePrivateCluster: true,
},
LinuxConfig: &models.VmwareTanzuManageV1alpha1AksclusterLinuxConfig{
Expand All @@ -129,10 +144,10 @@ func aTestCluster(w ...clusterWither) *models.VmwareTanzuManageV1alpha1AksCluste
},
NetworkConfig: &models.VmwareTanzuManageV1alpha1AksclusterNetworkConfig{
DNSPrefix: "net-prefix",
DNSServiceIP: "127.0.0.1",
DockerBridgeCidr: "127.0.0.2",
DNSServiceIP: test127001,
DockerBridgeCidr: test127002,
LoadBalancerSku: "load-balancer",
NetworkPlugin: "azure",
NetworkPlugin: testAzure,
NetworkPolicy: "policy",
ServiceCidrs: []string{"127.0.0.4"},
},
Expand Down Expand Up @@ -261,7 +276,7 @@ func withNodepools(nps []any) mapWither {

func withName(name string) mapWither {
return func(m map[string]any) {
m["name"] = name
m[testName] = name
}
}

Expand Down Expand Up @@ -307,24 +322,24 @@ func withPodSubnetID(podSubnetID string) mapWither {

func aTestClusterDataMap(w ...mapWither) map[string]any {
m := map[string]any{
"credential_name": "test-cred",
"subscription_id": "sub-id",
"resource_group": "resource-group",
"name": "test-cluster",
"credential_name": testTestCred,
"subscription_id": testSubId,
"resource_group": testResourceGroup,
testName: testTestCluster,
"spec": []any{map[string]any{
"cluster_group": "my-cluster-group",
"proxy": "my-proxy",
"config": []any{map[string]any{
"location": "eastus",
"location": testEastus,
"kubernetes_version": "1.26.0",
"node_resource_group_name": "my-node-group",
"disk_encryption_set": "disk-encryption-set-id",
"tags": map[string]any{
"custom-tag": "tag-data",
},
"sku": []any{map[string]any{
"name": "BASIC",
"tier": "FREE",
testName: "BASIC",
"tier": "FREE",
}},
"access_config": []any{map[string]any{
"enable_rbac": true,
Expand All @@ -337,7 +352,7 @@ func aTestClusterDataMap(w ...mapWither) map[string]any {
}},
}},
"api_server_access_config": []any{map[string]any{
"authorized_ip_ranges": []any{"127.0.0.1", "127.0.0.2"},
"authorized_ip_ranges": []any{test127001, test127002},
"enable_private_cluster": true,
}},
"linux_config": []any{map[string]any{
Expand All @@ -346,11 +361,11 @@ func aTestClusterDataMap(w ...mapWither) map[string]any {
}},
"network_config": []any{map[string]any{
"load_balancer_sku": "load-balancer",
"network_plugin": "azure",
"network_plugin": testAzure,
"network_plugin_mode": "",
"network_policy": "policy",
"dns_service_ip": "127.0.0.1",
"docker_bridge_cidr": "127.0.0.2",
"dns_service_ip": test127001,
"docker_bridge_cidr": test127002,
"pod_cidr": nil,
"service_cidr": []any{"127.0.0.4"},
"dns_prefix": "net-prefix",
Expand All @@ -363,16 +378,16 @@ func aTestClusterDataMap(w ...mapWither) map[string]any {
}},
"addon_config": []any{map[string]any{
"azure_keyvault_secrets_provider_addon_config": []any{map[string]any{
"enable": true,
testEnable: true,
"enable_secret_rotation": true,
"rotation_poll_interval": "5m",
}},
"monitor_addon_config": []any{map[string]any{
"enable": true,
testEnable: true,
"log_analytics_workspace_id": "workspace-id",
}},
"azure_policy_addon_config": []any{map[string]any{
"enable": true,
testEnable: true,
}},
}},
"auto_upgrade_config": []any{map[string]any{
Expand Down Expand Up @@ -457,7 +472,7 @@ func aTestNodePool(w ...nodepoolWither) *models.VmwareTanzuManageV1alpha1Aksclus
},
EnableNodePublicIP: true,
MaxPods: 110,
NodeLabels: map[string]string{"label": "val"},
NodeLabels: map[string]string{"label": testVal},
NodeTaints: []*models.VmwareTanzuManageV1alpha1AksclusterNodepoolTaint{{
Effect: models.VmwareTanzuManageV1alpha1AksclusterNodepoolTaintEffectNOSCHEDULE.Pointer(),
Key: "tkey",
Expand All @@ -466,7 +481,7 @@ func aTestNodePool(w ...nodepoolWither) *models.VmwareTanzuManageV1alpha1Aksclus
OsDiskSizeGb: 30,
OsDiskType: models.VmwareTanzuManageV1alpha1AksclusterNodepoolOsDiskTypeEPHEMERAL.Pointer(),
OsType: models.VmwareTanzuManageV1alpha1AksclusterNodepoolOsTypeLINUX.Pointer(),
Tags: map[string]string{"tmc.node.tag": "val"},
Tags: map[string]string{"tmc.node.tag": testVal},
UpgradeConfig: &models.VmwareTanzuManageV1alpha1AksclusterNodepoolUpgradeConfig{
MaxSurge: "50%",
},
Expand All @@ -484,7 +499,7 @@ func aTestNodePool(w ...nodepoolWither) *models.VmwareTanzuManageV1alpha1Aksclus

func aTestNodepoolDataMap(w ...mapWither) map[string]any {
m := map[string]any{
"name": "system-np",
testName: "system-np",
"spec": []any{map[string]any{
"mode": "SYSTEM",
"node_image_version": "v1",
Expand All @@ -509,10 +524,10 @@ func aTestNodepoolDataMap(w ...mapWither) map[string]any {
},
"vnet_subnet_id": "vnet-1/subnets/subnet-1",
"pod_subnet_id": "vnet-1/subnets/subnet-2",
"node_labels": map[string]any{"label": "val"},
"tags": map[string]any{"tmc.node.tag": "val"},
"node_labels": map[string]any{"label": testVal},
"tags": map[string]any{"tmc.node.tag": testVal},
"auto_scaling_config": []any{map[string]any{
"enable": true,
testEnable: true,
"min_count": 1,
"max_count": 10,
}},
Expand Down
22 changes: 11 additions & 11 deletions internal/resources/akscluster/resource_akscluster_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ func testAKSCluster(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFullName) st
name = "%s"
spec {
config {
location = "eastus"
location = "%s"
kubernetes_version = "%s"
network_config {
network_plugin = "azure"
network_plugin = "%s"
dns_prefix = "dns-tf-test"
}
storage_config {
Expand All @@ -420,7 +420,7 @@ func testAKSCluster(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFullName) st
}
}
}
}`, fn.Name, fn.CredentialName, fn.SubscriptionID, fn.Name, aksKubernetesVersion)
}`, fn.Name, fn.CredentialName, fn.SubscriptionID, fn.Name, testEastus, aksKubernetesVersion, testAzure)
}

func testAKSClusterEnableCSI(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFullName) string {
Expand All @@ -431,10 +431,10 @@ func testAKSClusterEnableCSI(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFul
name = "%s"
spec {
config {
location = "eastus"
location = "%s"
kubernetes_version = "%s"
network_config {
network_plugin = "azure"
network_plugin = "%s"
dns_prefix = "dns-tf-test"
}
storage_config {
Expand All @@ -457,7 +457,7 @@ func testAKSClusterEnableCSI(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFul
}
}
}
}`, fn.Name, fn.CredentialName, fn.SubscriptionID, fn.Name, aksKubernetesVersion)
}`, fn.Name, fn.CredentialName, fn.SubscriptionID, fn.Name, testEastus, aksKubernetesVersion, testAzure)
}

func testAKSClusterAddUserNodepool(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFullName) string {
Expand All @@ -468,10 +468,10 @@ func testAKSClusterAddUserNodepool(fn *aksmodel.VmwareTanzuManageV1alpha1Aksclus
name = "%s"
spec {
config {
location = "eastus"
location = "%s"
kubernetes_version = "%s"
network_config {
network_plugin = "azure"
network_plugin = "%s"
dns_prefix = "dns-tf-test"
}
storage_config {
Expand Down Expand Up @@ -505,7 +505,7 @@ func testAKSClusterAddUserNodepool(fn *aksmodel.VmwareTanzuManageV1alpha1Aksclus
}
}
}
}`, fn.Name, fn.CredentialName, fn.SubscriptionID, fn.Name, aksKubernetesVersion)
}`, fn.Name, fn.CredentialName, fn.SubscriptionID, fn.Name, testEastus, aksKubernetesVersion, testAzure)
}

func testAKSClusterRemoveUserNodepool(fn *aksmodel.VmwareTanzuManageV1alpha1AksclusterFullName) string {
Expand All @@ -522,9 +522,9 @@ func mockCluster(w ...clusterWither) *aksmodel.VmwareTanzuManageV1alpha1AksClust
AgentName: "",
ClusterGroupName: "default",
Config: &aksmodel.VmwareTanzuManageV1alpha1AksclusterClusterConfig{
Location: "eastus",
Location: testEastus,
NetworkConfig: &aksmodel.VmwareTanzuManageV1alpha1AksclusterNetworkConfig{
NetworkPlugin: "azure",
NetworkPlugin: testAzure,
DNSPrefix: "dns-tf-test",
},
StorageConfig: &aksmodel.VmwareTanzuManageV1alpha1AksclusterStorageConfig{
Expand Down
8 changes: 4 additions & 4 deletions internal/resources/cluster/cluster_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func TestFlattenClusterFullname(t *testing.T) {
description: "normal scenario with complete cluster full name",
input: &clustermodel.VmwareTanzuManageV1alpha1ClusterFullName{
Name: "dummy",
ManagementClusterName: "attached",
ProvisionerName: "attached",
ManagementClusterName: attachedValue,
ProvisionerName: attachedValue,
},
expected: []interface{}{
map[string]interface{}{
NameKey: "dummy",
ManagementClusterNameKey: "attached",
ProvisionerNameKey: "attached",
ManagementClusterNameKey: attachedValue,
ProvisionerNameKey: attachedValue,
},
},
},
Expand Down
20 changes: 10 additions & 10 deletions internal/resources/cluster/cluster_spec_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func TestFlattenSpec(t *testing.T) {
{
description: "normal scenario with cluster group",
input: &clustermodel.VmwareTanzuManageV1alpha1ClusterSpec{
ClusterGroupName: "default",
ClusterGroupName: clusterGroupDefaultValue,
},
expected: []interface{}{
map[string]interface{}{
clusterGroupKey: "default",
clusterGroupKey: clusterGroupDefaultValue,
proxyNameKey: "",
imageRegistryNameKey: "",
},
Expand All @@ -41,28 +41,28 @@ func TestFlattenSpec(t *testing.T) {
{
description: "normal scenario with cluster group and proxy",
input: &clustermodel.VmwareTanzuManageV1alpha1ClusterSpec{
ClusterGroupName: "default",
ProxyName: "proxy",
ClusterGroupName: clusterGroupDefaultValue,
ProxyName: proxyNameKey,
},
expected: []interface{}{
map[string]interface{}{
clusterGroupKey: "default",
proxyNameKey: "proxy",
clusterGroupKey: clusterGroupDefaultValue,
proxyNameKey: proxyNameKey,
imageRegistryNameKey: "",
},
},
},
{
description: "normal scenario with cluster group, proxy and image registry",
input: &clustermodel.VmwareTanzuManageV1alpha1ClusterSpec{
ClusterGroupName: "default",
ProxyName: "proxy",
ClusterGroupName: clusterGroupDefaultValue,
ProxyName: proxyNameKey,
ImageRegistry: "image-registry",
},
expected: []interface{}{
map[string]interface{}{
clusterGroupKey: "default",
proxyNameKey: "proxy",
clusterGroupKey: clusterGroupDefaultValue,
proxyNameKey: proxyNameKey,
imageRegistryNameKey: "image-registry",
},
},
Expand Down
Loading
Loading