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

add open service mesh option for kuberentes service (public preview) #11189

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
29 changes: 29 additions & 0 deletions azurerm/internal/services/containers/kubernetes_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
kubernetesDashboardKey = "kubeDashboard"
httpApplicationRoutingKey = "httpApplicationRouting"
omsAgentKey = "omsagent"
openServiceMeshKey = "openServiceMesh"
)

// The AKS API hard-codes which add-ons are supported in which environment
Expand All @@ -34,11 +35,13 @@ var unsupportedAddonsForEnvironment = map[string][]string{
azurePolicyKey, // https://github.com/terraform-providers/terraform-provider-azurerm/issues/6462
httpApplicationRoutingKey, // https://github.com/terraform-providers/terraform-provider-azurerm/issues/5960
kubernetesDashboardKey, // https://github.com/terraform-providers/terraform-provider-azurerm/issues/7487
openServiceMeshKey, // Preview features are not supported in Azure China
},
azure.USGovernmentCloud.Name: {
azurePolicyKey, // https://github.com/terraform-providers/terraform-provider-azurerm/issues/6702
httpApplicationRoutingKey, // https://github.com/terraform-providers/terraform-provider-azurerm/issues/5960
kubernetesDashboardKey, // https://github.com/terraform-providers/terraform-provider-azurerm/issues/7136
openServiceMeshKey, // Preview features are not supported in Azure Government
},
}

Expand Down Expand Up @@ -154,6 +157,20 @@ func schemaKubernetesAddOnProfiles() *schema.Schema {
},
},
},

"open_service_mesh": {
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
},
},
},
},
}
Expand All @@ -170,6 +187,7 @@ func expandKubernetesAddOnProfiles(input []interface{}, env azure.Environment) (
kubernetesDashboardKey: &disabled,
httpApplicationRoutingKey: &disabled,
omsAgentKey: &disabled,
openServiceMeshKey: &disabled,
}

if len(input) == 0 {
Expand Down Expand Up @@ -248,6 +266,17 @@ func expandKubernetesAddOnProfiles(input []interface{}, env azure.Environment) (
}
}

openServiceMesh := profile[""].([]interface{})
yershalom marked this conversation as resolved.
Show resolved Hide resolved
if len(openServiceMesh) > 0 && openServiceMesh[0] != nil {
value := openServiceMesh[0].(map[string]interface{})
enabled := value["enabled"].(bool)

addonProfiles[openServiceMeshKey] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
Config: nil,
}
}

return filterUnsupportedKubernetesAddOns(addonProfiles, env)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var kubernetesAddOnTests = map[string]func(t *testing.T){
"addonProfileOMS": testAccKubernetesCluster_addonProfileOMS,
"addonProfileOMSToggle": testAccKubernetesCluster_addonProfileOMSToggle,
"addonProfileRouting": testAccKubernetesCluster_addonProfileRoutingToggle,
"addonProfileOpenServiceMesh": testAccKubernetesCluster_addonProfileOpenServiceMesh,
}

func TestAccKubernetesCluster_addonProfileAciConnectorLinux(t *testing.T) {
Expand Down Expand Up @@ -256,6 +257,28 @@ func testAccKubernetesCluster_addonProfileRoutingToggle(t *testing.T) {
})
}

func TestAccKubernetesCluster_addonProfileOpenServiceMesh(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccKubernetesCluster_addonProfileOpenServiceMesh(t)
}

func testAccKubernetesCluster_addonProfileOpenServiceMesh(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.addonProfileOpenServiceMeshConfig(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("addon_profile.0.open_service_mesh.#").HasValue("1"),
check.That(data.ResourceName).Key("addon_profile.0.open_service_mesh.0.enabled").HasValue("false"),
),
},
data.ImportStep(),
})
}

func (KubernetesClusterResource) addonProfileAciConnectorLinuxConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -727,3 +750,47 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) addonProfileOpenServiceMeshConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"

linux_profile {
admin_username = "acctestuser%d"

ssh_key {
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt [email protected]"
}
}

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

addon_profile {
open_service_mesh {
enabled = false
}
}

identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func dataSourceKubernetesCluster() *schema.Resource {
},
},
},

"open_service_mesh": {
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll also need to flatten this value for the Data Source, this is done in flattenKubernetesClusterDataSourceAddonProfiles (by parsing the add-on profile from the response and reading the enabled state)

},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var kubernetesDataSourceTests = map[string]func(t *testing.T){
"addOnProfileKubeDashboard": testAccDataSourceKubernetesCluster_addOnProfileKubeDashboard,
"addOnProfileAzurePolicy": testAccDataSourceKubernetesCluster_addOnProfileAzurePolicy,
"addOnProfileRouting": testAccDataSourceKubernetesCluster_addOnProfileRouting,
"addOnProfileOpenServiceMesh": testAccDataSourceKubernetesCluster_addOnProfileOpenServiceMesh,
"autoscalingNoAvailabilityZones": testAccDataSourceKubernetesCluster_autoscalingNoAvailabilityZones,
"autoscalingWithAvailabilityZones": testAccDataSourceKubernetesCluster_autoscalingWithAvailabilityZones,
"nodeLabels": testAccDataSourceKubernetesCluster_nodeLabels,
Expand Down Expand Up @@ -450,6 +451,27 @@ func testAccDataSourceKubernetesCluster_addOnProfileRouting(t *testing.T) {
})
}

func TestAccDataSourceKubernetesCluster_addOnProfileOpenServiceMesh(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccDataSourceKubernetesCluster_addOnProfileOpenServiceMesh(t)
}

func testAccDataSourceKubernetesCluster_addOnProfileOpenServiceMesh(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test")
r := KubernetesClusterDataSource{}

data.DataSourceTest(t, []resource.TestStep{
{
Config: r.addOnProfileOpenServiceMeshConfig(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("addon_profile.#").HasValue("1"),
check.That(data.ResourceName).Key("addon_profile.0.open_service_mesh.#").HasValue("1"),
check.That(data.ResourceName).Key("addon_profile.0.open_service_mesh.0.enabled").HasValue("false"),
),
},
})
}

func TestAccDataSourceKubernetesCluster_autoscalingNoAvailabilityZones(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccDataSourceKubernetesCluster_autoscalingNoAvailabilityZones(t)
Expand Down Expand Up @@ -713,6 +735,17 @@ data "azurerm_kubernetes_cluster" "test" {
`, KubernetesClusterResource{}.addonProfileRoutingConfig(data))
}

func (KubernetesClusterDataSource) addOnProfileOpenServiceMeshConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_kubernetes_cluster" "test" {
name = azurerm_kubernetes_cluster.test.name
resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name
}
`, KubernetesClusterResource{}.addonProfileOpenServiceMeshConfig(data))
}

func (KubernetesClusterDataSource) autoScalingNoAvailabilityZonesConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down