Skip to content

Commit d3da558

Browse files
authored
add test for loadbalanceingress IP/Hostname check (#1797)
* add test for loadbalanceingress IP/Hostname check * update loadIngress test * remove no_rollout_wait test * update test to check for GKE label in node * update gke condition check
1 parent 82a1035 commit d3da558

File tree

2 files changed

+26
-78
lines changed

2 files changed

+26
-78
lines changed

kubernetes/resource_kubernetes_deployment_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -856,26 +856,6 @@ func TestAccKubernetesDeployment_with_share_process_namespace(t *testing.T) {
856856
})
857857
}
858858

859-
func TestAccKubernetesDeployment_no_rollout_wait(t *testing.T) {
860-
deploymentName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
861-
imageName := nginxImageVersion
862-
863-
resource.Test(t, resource.TestCase{
864-
PreCheck: func() { testAccPreCheck(t) },
865-
ProviderFactories: testAccProviderFactories,
866-
CheckDestroy: testAccCheckKubernetesDeploymentDestroy,
867-
Steps: []resource.TestStep{
868-
{
869-
Config: testAccKubernetesDeploymentConfigWithWaitForRolloutFalse(deploymentName, imageName),
870-
Check: resource.ComposeAggregateTestCheckFunc(
871-
testAccCheckKubernetesDeploymentRollingOut("kubernetes_deployment.test"),
872-
resource.TestCheckResourceAttr("kubernetes_deployment.test", "wait_for_rollout", "false"),
873-
),
874-
},
875-
},
876-
})
877-
}
878-
879859
func TestAccKubernetesDeployment_with_deployment_strategy_rollingupdate_max_surge_30perc_max_unavailable_40perc(t *testing.T) {
880860
var conf appsv1.Deployment
881861

@@ -1212,21 +1192,6 @@ func testAccCheckKubernetesDeploymentExists(n string, obj *appsv1.Deployment) re
12121192
}
12131193
}
12141194

1215-
func testAccCheckKubernetesDeploymentRollingOut(n string) resource.TestCheckFunc {
1216-
return func(s *terraform.State) error {
1217-
d, err := getDeploymentFromResourceName(s, n)
1218-
if err != nil {
1219-
return err
1220-
}
1221-
1222-
if d.Status.Replicas == d.Status.ReadyReplicas {
1223-
return fmt.Errorf("deployment has already rolled out")
1224-
}
1225-
1226-
return nil
1227-
}
1228-
}
1229-
12301195
func testAccKubernetesDeploymentConfig_minimal(name, imageName string) string {
12311196
return fmt.Sprintf(`resource "kubernetes_deployment" "test" {
12321197
metadata {
@@ -2642,48 +2607,6 @@ func testAccKubernetesDeploymentConfigWithAutomountServiceAccountToken(deploymen
26422607
`, deploymentName, imageName)
26432608
}
26442609

2645-
func testAccKubernetesDeploymentConfigWithWaitForRolloutFalse(deploymentName, imageName string) string {
2646-
return fmt.Sprintf(`resource "kubernetes_deployment" "test" {
2647-
metadata {
2648-
name = %q
2649-
}
2650-
spec {
2651-
replicas = 5
2652-
selector {
2653-
match_labels = {
2654-
"app" = "test"
2655-
}
2656-
}
2657-
template {
2658-
metadata {
2659-
name = "test-automount"
2660-
labels = {
2661-
"app" = "test"
2662-
}
2663-
}
2664-
spec {
2665-
container {
2666-
name = "nginx"
2667-
image = %q
2668-
port {
2669-
container_port = 80
2670-
}
2671-
readiness_probe {
2672-
initial_delay_seconds = 5
2673-
http_get {
2674-
path = "/"
2675-
port = 80
2676-
}
2677-
}
2678-
}
2679-
}
2680-
}
2681-
}
2682-
wait_for_rollout = false
2683-
}
2684-
`, deploymentName, nginxImageVersion)
2685-
}
2686-
26872610
func testAccKubernetesDeploymentConfigLocal(provider, name, imageName string) string {
26882611
return fmt.Sprintf(`resource "kubernetes_deployment" "test" {
26892612
provider = %s

kubernetes/resource_kubernetes_service_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestAccKubernetesService_loadBalancer(t *testing.T) {
157157
resource.TestCheckResourceAttr(resourceName, "spec.0.selector.%", "1"),
158158
resource.TestCheckResourceAttr(resourceName, "spec.0.selector.App", "MyApp"),
159159
resource.TestCheckResourceAttr(resourceName, "spec.0.type", "LoadBalancer"),
160-
resource.TestCheckResourceAttrSet(resourceName, "status.0.load_balancer.0.ingress.0.hostname"),
160+
testAccCheckloadBalancerIngressCheck(resourceName),
161161
testAccCheckServicePorts(&conf, []api.ServicePort{
162162
{
163163
Port: int32(8888),
@@ -811,6 +811,31 @@ func testAccCheckServicePorts(svc *api.Service, expected []api.ServicePort) reso
811811
}
812812
}
813813

814+
func testAccCheckloadBalancerIngressCheck(resourceName string) resource.TestCheckFunc {
815+
return func(s *terraform.State) error {
816+
rs, ok := s.RootModule().Resources[resourceName]
817+
if !ok {
818+
return fmt.Errorf("Not found: %s", resourceName)
819+
}
820+
821+
lb := "status.0.load_balancer.0.ingress.0"
822+
823+
if ok, _ := isRunningInGke(); ok {
824+
ip := fmt.Sprintf("%s.ip", lb)
825+
if rs.Primary.Attributes[ip] != "" {
826+
return nil
827+
}
828+
return fmt.Errorf("Attribute '%s' expected to be set for GKE cluster", ip)
829+
} else {
830+
hostname := fmt.Sprintf("%s.hostname", lb)
831+
if rs.Primary.Attributes[hostname] != "" {
832+
return nil
833+
}
834+
return fmt.Errorf("Attribute '%s' expected to be set for EKS cluster", hostname)
835+
}
836+
}
837+
}
838+
814839
func testAccCheckKubernetesServiceDestroy(s *terraform.State) error {
815840
conn, err := testAccProvider.Meta().(KubeClientsets).MainClientset()
816841

0 commit comments

Comments
 (0)