From 692e440d6e9196544bfc0c67b8f2f49d21aec283 Mon Sep 17 00:00:00 2001 From: bprashanth Date: Fri, 21 Oct 2016 14:29:25 -0700 Subject: [PATCH] Allocate static-ip through cloudprovider library instead of gcloud --- test/e2e/ingress.go | 1 + test/e2e/ingress_utils.go | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/test/e2e/ingress.go b/test/e2e/ingress.go index 9f95bf8e13d..a9e05c6729c 100644 --- a/test/e2e/ingress.go +++ b/test/e2e/ingress.go @@ -119,6 +119,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7 [Feature:Ingress]", func() { }) It("shoud create ingress with given static-ip ", func() { + // ip released when the rest of lb resources are deleted in cleanupGCE ip := gceController.staticIP(ns) By(fmt.Sprintf("allocated static ip %v: %v through the GCE cloud provider", ns, ip)) diff --git a/test/e2e/ingress_utils.go b/test/e2e/ingress_utils.go index 1da02baf905..5eedfdd9ee4 100644 --- a/test/e2e/ingress_utils.go +++ b/test/e2e/ingress_utils.go @@ -590,24 +590,22 @@ func (cont *GCEIngressController) init() { } } +// staticIP allocates a random static ip with the given name. Returns a string +// representation of the ip. Caller is expected to manage cleanup of the ip. func (cont *GCEIngressController) staticIP(name string) string { - ExpectNoError(gcloudCreate("addresses", name, cont.cloud.ProjectID, "--global")) - cont.staticIPName = name - ipList := []compute.Address{} - if pollErr := wait.PollImmediate(5*time.Second, cloudResourcePollTimeout, func() (bool, error) { - gcloudList("addresses", name, cont.cloud.ProjectID, &ipList) - if len(ipList) != 1 { - framework.Logf("Failed to find static ip %v even though create call succeeded, found ips %+v", name, ipList) - return false, nil + gceCloud := cont.cloud.Provider.(*gcecloud.GCECloud) + ip, err := gceCloud.ReserveGlobalStaticIP(name, "") + if err != nil { + if delErr := gceCloud.DeleteGlobalStaticIP(name); delErr != nil { + if cont.isHTTPErrorCode(delErr, http.StatusNotFound) { + framework.Logf("Static ip with name %v was not allocated, nothing to delete", name) + } else { + framework.Logf("Failed to delete static ip %v: %v", name, delErr) + } } - return true, nil - }); pollErr != nil { - if err := gcloudDelete("addresses", name, cont.cloud.ProjectID, "--global"); err == nil { - framework.Logf("Failed to get AND delete address %v even though create call succeeded", name) - } - framework.Failf("Failed to find static ip %v even though create call succeeded, found ips %+v", name, ipList) + framework.Failf("Failed to allocated static ip %v: %v", name, err) } - return ipList[0].Address + return ip.Address } // gcloudList unmarshals json output of gcloud into given out interface.