Merge pull request #35331 from bprashanth/ingress_gcloud

Automatic merge from submit-queue

Allocate static-ip through cloudprovider library instead of gcloud

Fixes https://github.com/kubernetes/kubernetes/issues/33840
https://github.com/kubernetes/kubernetes/issues/33840#issuecomment-255277349 for details
This commit is contained in:
Kubernetes Submit Queue 2016-10-21 18:58:29 -07:00 committed by GitHub
commit cf376e8b8f
2 changed files with 14 additions and 15 deletions

View File

@ -119,6 +119,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7 [Feature:Ingress]", func() {
}) })
It("shoud create ingress with given static-ip ", 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) ip := gceController.staticIP(ns)
By(fmt.Sprintf("allocated static ip %v: %v through the GCE cloud provider", ns, ip)) By(fmt.Sprintf("allocated static ip %v: %v through the GCE cloud provider", ns, ip))

View File

@ -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 { func (cont *GCEIngressController) staticIP(name string) string {
ExpectNoError(gcloudCreate("addresses", name, cont.cloud.ProjectID, "--global")) gceCloud := cont.cloud.Provider.(*gcecloud.GCECloud)
cont.staticIPName = name ip, err := gceCloud.ReserveGlobalStaticIP(name, "")
ipList := []compute.Address{} if err != nil {
if pollErr := wait.PollImmediate(5*time.Second, cloudResourcePollTimeout, func() (bool, error) { if delErr := gceCloud.DeleteGlobalStaticIP(name); delErr != nil {
gcloudList("addresses", name, cont.cloud.ProjectID, &ipList) if cont.isHTTPErrorCode(delErr, http.StatusNotFound) {
if len(ipList) != 1 { framework.Logf("Static ip with name %v was not allocated, nothing to delete", name)
framework.Logf("Failed to find static ip %v even though create call succeeded, found ips %+v", name, ipList) } else {
return false, nil 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. // gcloudList unmarshals json output of gcloud into given out interface.