mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Fix the services namespace test to wait for the services' load balancers
to be created.
This commit is contained in:
parent
ccc300289f
commit
7b647c5dbc
@ -287,14 +287,9 @@ var _ = Describe("Services", func() {
|
|||||||
}(ns, serviceName)
|
}(ns, serviceName)
|
||||||
|
|
||||||
// Wait for the load balancer to be created asynchronously, which is
|
// Wait for the load balancer to be created asynchronously, which is
|
||||||
// (unfortunately) currently indicated by a public IP address being
|
// currently indicated by a public IP address being added to the spec.
|
||||||
// added to the spec.
|
result, err = waitForPublicIPs(c, serviceName, ns)
|
||||||
for t := time.Now(); time.Since(t) < 4*time.Minute; time.Sleep(5 * time.Second) {
|
Expect(err).NotTo(HaveOccurred())
|
||||||
result, _ = c.Services(ns).Get(serviceName)
|
|
||||||
if len(result.Spec.PublicIPs) == 1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(result.Spec.PublicIPs) != 1 {
|
if len(result.Spec.PublicIPs) != 1 {
|
||||||
Failf("got unexpected number (%d) of public IPs for externally load balanced service: %v", result.Spec.PublicIPs, result)
|
Failf("got unexpected number (%d) of public IPs for externally load balanced service: %v", result.Spec.PublicIPs, result)
|
||||||
}
|
}
|
||||||
@ -378,13 +373,19 @@ var _ = Describe("Services", func() {
|
|||||||
service.ObjectMeta.Name = serviceName
|
service.ObjectMeta.Name = serviceName
|
||||||
service.ObjectMeta.Namespace = namespace
|
service.ObjectMeta.Namespace = namespace
|
||||||
By("creating service " + serviceName + " in namespace " + namespace)
|
By("creating service " + serviceName + " in namespace " + namespace)
|
||||||
result, err := c.Services(namespace).Create(service)
|
_, err := c.Services(namespace).Create(service)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
defer func(namespace, serviceName string) { // clean up when we're done
|
defer func(namespace, serviceName string) { // clean up when we're done
|
||||||
By("deleting service " + serviceName + " in namespace " + namespace)
|
By("deleting service " + serviceName + " in namespace " + namespace)
|
||||||
err := c.Services(namespace).Delete(serviceName)
|
err := c.Services(namespace).Delete(serviceName)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}(namespace, serviceName)
|
}(namespace, serviceName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, namespace := range namespaces {
|
||||||
|
for _, serviceName := range serviceNames {
|
||||||
|
result, err := waitForPublicIPs(c, serviceName, namespace)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
publicIPs = append(publicIPs, result.Spec.PublicIPs...) // Save 'em to check uniqueness
|
publicIPs = append(publicIPs, result.Spec.PublicIPs...) // Save 'em to check uniqueness
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,6 +393,24 @@ var _ = Describe("Services", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
func waitForPublicIPs(c *client.Client, serviceName, namespace string) (*api.Service, error) {
|
||||||
|
const timeout = 4 * time.Minute
|
||||||
|
var service *api.Service
|
||||||
|
By(fmt.Sprintf("waiting up to %v for service %s in namespace %s to have a public IP", timeout, serviceName, namespace))
|
||||||
|
for start := time.Now(); time.Since(start) < timeout; time.Sleep(5 * time.Second) {
|
||||||
|
service, err := c.Services(namespace).Get(serviceName)
|
||||||
|
if err != nil {
|
||||||
|
Logf("Get service failed, ignoring for 5s: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(service.Spec.PublicIPs) > 0 {
|
||||||
|
return service, nil
|
||||||
|
}
|
||||||
|
Logf("Waiting for service %s in namespace %s to have a public IP (%v)", serviceName, namespace, time.Since(start))
|
||||||
|
}
|
||||||
|
return service, fmt.Errorf("service %s in namespace %s to have a public IP after %.2f seconds", nil, serviceName, namespace, podStartTimeout.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
func validateUniqueOrFail(s []string) {
|
func validateUniqueOrFail(s []string) {
|
||||||
By(fmt.Sprintf("validating unique: %v", s))
|
By(fmt.Sprintf("validating unique: %v", s))
|
||||||
sort.Strings(s)
|
sort.Strings(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user