Delete static-ip after ingress has cleaned up

pull/6/head
bprashanth 2016-12-12 19:06:08 -08:00
parent 12147a3cd6
commit fc57d76018
2 changed files with 45 additions and 18 deletions

View File

@ -120,7 +120,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", 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.createStaticIP(ns)
By(fmt.Sprintf("allocated static ip %v: %v through the GCE cloud provider", ns, ip))
jig.createIngress(filepath.Join(ingressManifestPath, "static-ip"), ns, map[string]string{

View File

@ -335,6 +335,23 @@ func cleanupGCE(gceController *GCEIngressController) {
}
return true, nil
})
// Static-IP allocated on behalf of the test, never deleted by the
// controller. Delete this IP only after the controller has had a chance
// to cleanup or it might interfere with the controller, causing it to
// throw out confusing events.
if ipErr := wait.Poll(5*time.Second, lbCleanupTimeout, func() (bool, error) {
if err := gceController.deleteStaticIPs(); err != nil {
framework.Logf("Failed to delete static-ip: %v\n", err)
return false, nil
}
return true, nil
}); ipErr != nil {
// If this is a persistent error, the suite will fail when we run out
// of quota anyway.
By(fmt.Sprintf("WARNING: possibly leaked static IP: %v\n", ipErr))
}
// Always try to cleanup even if pollErr == nil, because the cleanup
// routine also purges old leaked resources based on creation timestamp.
if cleanupErr := gceController.Cleanup(true); cleanupErr != nil {
@ -342,6 +359,8 @@ func cleanupGCE(gceController *GCEIngressController) {
} else {
By("No resources leaked.")
}
// Fail if the controller didn't cleanup
if pollErr != nil {
framework.Failf("L7 controller failed to delete all cloud resources on time. %v", pollErr)
}
@ -384,20 +403,6 @@ func (cont *GCEIngressController) deleteAddresses(del bool) string {
}
}
}
// If the test allocated a static ip, delete that regardless
if cont.staticIPName != "" {
if err := gcloudDelete("addresses", cont.staticIPName, cont.cloud.ProjectID, "--global"); err == nil {
cont.staticIPName = ""
}
} else {
e2eIPs := []compute.Address{}
gcloudList("addresses", "e2e-.*", cont.cloud.ProjectID, &e2eIPs)
ips := []string{}
for _, ip := range e2eIPs {
ips = append(ips, ip.Name)
}
framework.Logf("None of the remaining %d static-ips were created by this e2e: %v", len(ips), strings.Join(ips, ", "))
}
return msg
}
@ -664,9 +669,10 @@ 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 {
// createStaticIP 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 by
// invoking deleteStaticIPs.
func (cont *GCEIngressController) createStaticIP(name string) string {
gceCloud := cont.cloud.Provider.(*gcecloud.GCECloud)
ip, err := gceCloud.ReserveGlobalStaticIP(name, "")
if err != nil {
@ -684,6 +690,27 @@ func (cont *GCEIngressController) staticIP(name string) string {
return ip.Address
}
// deleteStaticIPs delets all static-ips allocated through calls to
// createStaticIP.
func (cont *GCEIngressController) deleteStaticIPs() error {
if cont.staticIPName != "" {
if err := gcloudDelete("addresses", cont.staticIPName, cont.cloud.ProjectID, "--global"); err == nil {
cont.staticIPName = ""
} else {
return err
}
} else {
e2eIPs := []compute.Address{}
gcloudList("addresses", "e2e-.*", cont.cloud.ProjectID, &e2eIPs)
ips := []string{}
for _, ip := range e2eIPs {
ips = append(ips, ip.Name)
}
framework.Logf("None of the remaining %d static-ips were created by this e2e: %v", len(ips), strings.Join(ips, ", "))
}
return nil
}
// gcloudList unmarshals json output of gcloud into given out interface.
func gcloudList(resource, regex, project string, out interface{}) {
// gcloud prints a message to stderr if it has an available update