Commit fecb7142 authored by Tim Hockin's avatar Tim Hockin

Demote static IPs ASAP for easier cleanup

This exposed bugs in the IP promotion/demotion logic.
parent 78322091
...@@ -486,15 +486,20 @@ var _ = Describe("Services", func() { ...@@ -486,15 +486,20 @@ var _ = Describe("Services", func() {
// Change the services to LoadBalancer. // Change the services to LoadBalancer.
requestedIP := "" requestedIP := ""
staticIPName := ""
if providerIs("gce", "gke") { if providerIs("gce", "gke") {
By("creating a static load balancer IP") By("creating a static load balancer IP")
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
staticIPName := fmt.Sprintf("e2e-external-lb-test-%d", rand.Intn(65535)) staticIPName = fmt.Sprintf("e2e-external-lb-test-%d", rand.Intn(65535))
requestedIP, err = createGCEStaticIP(staticIPName) requestedIP, err = createGCEStaticIP(staticIPName)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
defer func() { defer func() {
if staticIPName != "" {
// Release GCE static IP - this is not kube-managed and will not be automatically released. // Release GCE static IP - this is not kube-managed and will not be automatically released.
deleteGCEStaticIP(staticIPName) if err := deleteGCEStaticIP(staticIPName); err != nil {
Logf("failed to release static IP %s: %v", staticIPName, err)
}
}
}() }()
Logf("Allocated static load balancer IP: %s", requestedIP) Logf("Allocated static load balancer IP: %s", requestedIP)
} }
...@@ -523,6 +528,23 @@ var _ = Describe("Services", func() { ...@@ -523,6 +528,23 @@ var _ = Describe("Services", func() {
tcpIngressIP := getIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0]) tcpIngressIP := getIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0])
Logf("TCP load balancer: %s", tcpIngressIP) Logf("TCP load balancer: %s", tcpIngressIP)
By("waiting for the UDP service " + serviceName + " to have a load balancer")
if providerIs("gce", "gke") {
// Do this as early as possible, which overrides the `defer` above.
// This is mostly out of fear of leaking the IP in a timeout case
// (as of this writing we're not 100% sure where the leaks are
// coming from, so this is first-aid rather than surgery).
By("demoting the static IP to ephemeral")
if staticIPName != "" {
// Deleting it after it is attached "demotes" it to an
// ephemeral IP, which can be auto-released.
if err := deleteGCEStaticIP(staticIPName); err != nil {
Failf("failed to release static IP %s: %v", staticIPName, err)
}
staticIPName = ""
}
}
By("waiting for the UDP service to have a load balancer") By("waiting for the UDP service to have a load balancer")
// 2nd one should be faster since they ran in parallel. // 2nd one should be faster since they ran in parallel.
udpService = jig.WaitForLoadBalancerOrFail(ns2, udpService.Name) udpService = jig.WaitForLoadBalancerOrFail(ns2, udpService.Name)
...@@ -531,7 +553,7 @@ var _ = Describe("Services", func() { ...@@ -531,7 +553,7 @@ var _ = Describe("Services", func() {
Failf("UDP Spec.Ports[0].NodePort changed (%d -> %d) when not expected", udpNodePort, udpService.Spec.Ports[0].NodePort) Failf("UDP Spec.Ports[0].NodePort changed (%d -> %d) when not expected", udpNodePort, udpService.Spec.Ports[0].NodePort)
} }
udpIngressIP := getIngressPoint(&udpService.Status.LoadBalancer.Ingress[0]) udpIngressIP := getIngressPoint(&udpService.Status.LoadBalancer.Ingress[0])
Logf("UDP load balancer: %s", tcpIngressIP) Logf("UDP load balancer: %s", udpIngressIP)
By("verifying that TCP and UDP use different load balancers") By("verifying that TCP and UDP use different load balancers")
if tcpIngressIP == udpIngressIP { if tcpIngressIP == udpIngressIP {
...@@ -614,7 +636,6 @@ var _ = Describe("Services", func() { ...@@ -614,7 +636,6 @@ var _ = Describe("Services", func() {
if getIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0]) != tcpIngressIP { if getIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0]) != tcpIngressIP {
Failf("TCP Status.LoadBalancer.Ingress changed (%s -> %s) when not expected", tcpIngressIP, getIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0])) Failf("TCP Status.LoadBalancer.Ingress changed (%s -> %s) when not expected", tcpIngressIP, getIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0]))
} }
Logf("service port (TCP and UDP): %d", svcPort)
By("changing the UDP service's port") By("changing the UDP service's port")
udpService = jig.UpdateServiceOrFail(ns2, udpService.Name, func(s *api.Service) { udpService = jig.UpdateServiceOrFail(ns2, udpService.Name, func(s *api.Service) {
...@@ -631,6 +652,8 @@ var _ = Describe("Services", func() { ...@@ -631,6 +652,8 @@ var _ = Describe("Services", func() {
Failf("UDP Status.LoadBalancer.Ingress changed (%s -> %s) when not expected", udpIngressIP, getIngressPoint(&udpService.Status.LoadBalancer.Ingress[0])) Failf("UDP Status.LoadBalancer.Ingress changed (%s -> %s) when not expected", udpIngressIP, getIngressPoint(&udpService.Status.LoadBalancer.Ingress[0]))
} }
Logf("service port (TCP and UDP): %d", svcPort)
By("hitting the TCP service's NodePort") By("hitting the TCP service's NodePort")
jig.TestReachableHTTP(nodeIP, tcpNodePort, kubeProxyLagTimeout) jig.TestReachableHTTP(nodeIP, tcpNodePort, kubeProxyLagTimeout)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment