mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	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:
		@@ -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))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user