Skip to content

Commit 2b1ff07

Browse files
committed
use retryable http client to test ingress
1 parent 7cd1829 commit 2b1ff07

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,20 @@ No modules.
238238
| [azurerm_log_analytics_solution.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_solution) | resource |
239239
| [azurerm_log_analytics_workspace.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_workspace) | resource |
240240
| [azurerm_role_assignment.acr](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
241+
| [azurerm_role_assignment.application_gateway_contributor](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
242+
| [azurerm_role_assignment.application_gateway_resource_group_reader](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
243+
| [azurerm_role_assignment.application_gateway_vnet_network_contributor](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
241244
| [azurerm_role_assignment.network_contributor](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
242245
| [azurerm_role_assignment.network_contributor_on_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
243246
| [null_resource.kubernetes_version_keeper](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
244247
| [null_resource.pool_name_keeper](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
245248
| [tls_private_key.ssh](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
249+
| [azurerm_client_config.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
246250
| [azurerm_log_analytics_workspace.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/log_analytics_workspace) | data source |
251+
| [azurerm_resource_group.ingress_appgw](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
247252
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
248253
| [azurerm_user_assigned_identity.cluster_identity](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/user_assigned_identity) | data source |
254+
| [azurerm_virtual_network.application_gateway_vnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |
249255

250256
## Inputs
251257

@@ -271,6 +277,7 @@ No modules.
271277
| <a name="input_agents_type"></a> [agents\_type](#input\_agents\_type) | (Optional) The type of Node Pool which should be created. Possible values are AvailabilitySet and VirtualMachineScaleSets. Defaults to VirtualMachineScaleSets. | `string` | `"VirtualMachineScaleSets"` | no |
272278
| <a name="input_api_server_authorized_ip_ranges"></a> [api\_server\_authorized\_ip\_ranges](#input\_api\_server\_authorized\_ip\_ranges) | (Optional) The IP ranges to allow for incoming traffic to the server nodes. | `set(string)` | `null` | no |
273279
| <a name="input_api_server_subnet_id"></a> [api\_server\_subnet\_id](#input\_api\_server\_subnet\_id) | (Optional) The ID of the Subnet where the API server endpoint is delegated to. | `string` | `null` | no |
280+
| <a name="input_application_gateway_for_ingress"></a> [application\_gateway\_for\_ingress](#input\_application\_gateway\_for\_ingress) | * `id` - (Required) The ID of the Application Gateway that be used as cluster ingress.<br>* `subnet_id` - (Optional) The ID of the Subnet which the Application Gateway is connected to. Must be set when `create_role_assignments` is `true`.<br>* `create_role_assignments` - (Optional) Whether to create the corresponding role assignments or not. Defaults to `true`. | <pre>object({<br> id = string<br> subnet_id = optional(string)<br> create_role_assignments = optional(bool, true)<br> })</pre> | `null` | no |
274281
| <a name="input_attached_acr_id_map"></a> [attached\_acr\_id\_map](#input\_attached\_acr\_id\_map) | Azure Container Registry ids that need an authentication mechanism with Azure Kubernetes Service (AKS). Map key must be static string as acr's name, the value is acr's resource id. Changing this forces some new resources to be created. | `map(string)` | `{}` | no |
275282
| <a name="input_auto_scaler_profile_balance_similar_node_groups"></a> [auto\_scaler\_profile\_balance\_similar\_node\_groups](#input\_auto\_scaler\_profile\_balance\_similar\_node\_groups) | Detect similar node groups and balance the number of nodes between them. Defaults to `false`. | `bool` | `false` | no |
276283
| <a name="input_auto_scaler_profile_empty_bulk_delete_max"></a> [auto\_scaler\_profile\_empty\_bulk\_delete\_max](#input\_auto\_scaler\_profile\_empty\_bulk\_delete\_max) | Maximum number of empty nodes that can be deleted at the same time. Defaults to `10`. | `number` | `10` | no |
@@ -310,7 +317,6 @@ No modules.
310317
| <a name="input_image_cleaner_enabled"></a> [image\_cleaner\_enabled](#input\_image\_cleaner\_enabled) | (Optional) Specifies whether Image Cleaner is enabled. | `bool` | `false` | no |
311318
| <a name="input_image_cleaner_interval_hours"></a> [image\_cleaner\_interval\_hours](#input\_image\_cleaner\_interval\_hours) | (Optional) Specifies the interval in hours when images should be cleaned up. Defaults to `48`. | `number` | `48` | no |
312319
| <a name="input_ingress_application_gateway_enabled"></a> [ingress\_application\_gateway\_enabled](#input\_ingress\_application\_gateway\_enabled) | Whether to deploy the Application Gateway ingress controller to this Kubernetes Cluster? | `bool` | `false` | no |
313-
| <a name="input_ingress_application_gateway_id"></a> [ingress\_application\_gateway\_id](#input\_ingress\_application\_gateway\_id) | The ID of the Application Gateway to integrate with the ingress controller of this Kubernetes Cluster. | `string` | `null` | no |
314320
| <a name="input_ingress_application_gateway_name"></a> [ingress\_application\_gateway\_name](#input\_ingress\_application\_gateway\_name) | The name of the Application Gateway to be used or created in the Nodepool Resource Group, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. | `string` | `null` | no |
315321
| <a name="input_ingress_application_gateway_subnet_cidr"></a> [ingress\_application\_gateway\_subnet\_cidr](#input\_ingress\_application\_gateway\_subnet\_cidr) | The subnet CIDR to be used to create an Application Gateway, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. | `string` | `null` | no |
316322
| <a name="input_ingress_application_gateway_subnet_id"></a> [ingress\_application\_gateway\_subnet\_id](#input\_ingress\_application\_gateway\_subnet\_id) | The ID of the subnet on which to create an Application Gateway, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. | `string` | `null` | no |

locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
22
# Application Gateway ID: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/applicationGateways/myGateway1
3-
application_gateway_for_ingress_id = var.application_gateway_for_ingress == null ? null : var.application_gateway_for_ingress.id
3+
application_gateway_for_ingress_id = try(var.application_gateway_for_ingress.id, null)
44
application_gateway_resource_group_for_ingress = var.application_gateway_for_ingress == null ? null : local.application_gateway_segments_for_ingress[4]
55
application_gateway_segments_for_ingress = var.application_gateway_for_ingress == null ? null : split("/", local.application_gateway_for_ingress_id)
66
application_gateway_subnet_resource_group_name = try(local.application_gateway_subnet_segments[4], null)

test/e2e/terraform_aks_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package e2e
22

33
import (
44
"io"
5-
"net/http"
65
"os"
76
"regexp"
87
"strings"
98
"testing"
10-
"time"
119

10+
"github.com/hashicorp/go-retryablehttp"
1211
"github.com/stretchr/testify/require"
1312

1413
test_helper "github.com/Azure/terraform-module-test-helper"
@@ -131,22 +130,18 @@ func TestExamples_applicationGatewayIngress(t *testing.T) {
131130
}, func(t *testing.T, output test_helper.TerraformOutput) {
132131
url, ok := output["ingress_endpoint"].(string)
133132
require.True(t, ok)
134-
var html string
135-
var err error
136-
for i := 0; i < 10; i++ {
137-
html, err = getHTML(url)
138-
require.NoError(t, err)
139-
if strings.Contains(html, "Welcome to .NET") {
140-
return
141-
}
142-
time.Sleep(5 * time.Second)
133+
html, err := getHTML(url)
134+
require.NoError(t, err)
135+
if strings.Contains(html, "Welcome to .NET") {
136+
return
143137
}
144-
assert.Failf(t, "incorrect response from ingress: %s", html)
145138
})
146139
}
147140

148141
func getHTML(url string) (string, error) {
149-
resp, err := http.Get(url) // #nosec G107
142+
client := retryablehttp.NewClient()
143+
client.RetryMax = 10
144+
resp, err := client.Get(url)
150145
if err != nil {
151146
return "", err
152147
}

test/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.21.2
77
require (
88
github.com/Azure/terraform-module-test-helper v0.17.0
99
github.com/gruntwork-io/terratest v0.46.1
10+
github.com/hashicorp/go-retryablehttp v0.7.5
1011
github.com/stretchr/testify v1.8.4
1112
)
1213

0 commit comments

Comments
 (0)