Rollback to Poll instead of PollImmediate

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-08-20 20:12:31 -04:00
parent 3d163e585a
commit 7fe5eccbc6
6 changed files with 28 additions and 27 deletions

View file

@ -321,15 +321,16 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.NewHttpbinDeployment()
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(context.TODO(), framework.HTTPBinService, metav1.GetOptions{})
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP = e.Subsets[0].Addresses[0].IP
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets), 1, "expected at least one endpoint")
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets[0].Addresses), 1, "expected at least one address ready in the endpoint")
httpbinIP := e.Subsets[0].Addresses[0].IP
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-url": fmt.Sprintf("http://%s/cookies/set/alma/armud", httpbinIP),
@ -361,15 +362,16 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
ginkgo.BeforeEach(func() {
f.NewHttpbinDeployment()
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(context.TODO(), framework.HTTPBinService, metav1.GetOptions{})
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP = e.Subsets[0].Addresses[0].IP
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets), 1, "expected at least one endpoint")
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets[0].Addresses), 1, "expected at least one address ready in the endpoint")
httpbinIP := e.Subsets[0].Addresses[0].IP
annotations = map[string]string{
"nginx.ingress.kubernetes.io/auth-url": fmt.Sprintf("http://%s/basic-auth/user/password", httpbinIP),
@ -439,8 +441,6 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
ginkgo.BeforeEach(func() {
f.NewHttpbinDeployment()
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
assert.Nil(ginkgo.GinkgoT(), err)
@ -452,7 +452,7 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets), 1, "expected at least one endpoint")
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets[0].Addresses), 1, "expected at least one address ready in the endpoint")
httpbinIP = e.Subsets[0].Addresses[0].IP
httpbinIP := e.Subsets[0].Addresses[0].IP
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-url": fmt.Sprintf("http://%s/basic-auth/user/password", httpbinIP),

View file

@ -205,21 +205,21 @@ func (f *Framework) GetURL(scheme RequestScheme) string {
// WaitForNginxServer waits until the nginx configuration contains a particular server section
func (f *Framework) WaitForNginxServer(name string, matcher func(cfg string) bool) {
err := wait.PollImmediate(Poll, DefaultTimeout, f.matchNginxConditions(name, matcher))
err := wait.Poll(Poll, DefaultTimeout, f.matchNginxConditions(name, matcher))
assert.Nil(ginkgo.GinkgoT(), err, "waiting for nginx server condition/s")
Sleep(1 * time.Second)
}
// WaitForNginxConfiguration waits until the nginx configuration contains a particular configuration
func (f *Framework) WaitForNginxConfiguration(matcher func(cfg string) bool) {
err := wait.PollImmediate(Poll, DefaultTimeout, f.matchNginxConditions("", matcher))
err := wait.Poll(Poll, DefaultTimeout, f.matchNginxConditions("", matcher))
assert.Nil(ginkgo.GinkgoT(), err, "waiting for nginx server condition/s")
Sleep(1 * time.Second)
}
// WaitForNginxCustomConfiguration waits until the nginx configuration given part (from, to) contains a particular configuration
func (f *Framework) WaitForNginxCustomConfiguration(from string, to string, matcher func(cfg string) bool) {
err := wait.PollImmediate(Poll, DefaultTimeout, f.matchNginxCustomConditions(from, to, matcher))
err := wait.Poll(Poll, DefaultTimeout, f.matchNginxCustomConditions(from, to, matcher))
assert.Nil(ginkgo.GinkgoT(), err, "waiting for nginx server condition/s")
}
@ -428,7 +428,7 @@ func (f *Framework) DeleteNGINXPod(grace int64) {
err = f.KubeClientSet.CoreV1().Pods(ns).Delete(context.TODO(), pod.GetName(), *metav1.NewDeleteOptions(grace))
assert.Nil(ginkgo.GinkgoT(), err, "deleting ingress nginx pod")
err = wait.PollImmediate(Poll, DefaultTimeout, func() (bool, error) {
err = wait.Poll(Poll, DefaultTimeout, func() (bool, error) {
pod, err := GetIngressNGINXPod(ns, f.KubeClientSet)
if err != nil || pod == nil {
return false, nil

View file

@ -172,7 +172,7 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
return nil
}
return wait.PollImmediate(Poll, timeout, func() (bool, error) {
return wait.Poll(Poll, timeout, func() (bool, error) {
endpoint, err := kubeClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), name, metav1.GetOptions{})
if k8sErrors.IsNotFound(err) {
return false, nil

View file

@ -355,7 +355,7 @@ func matchTLSServerName(url string, tlsConfig *tls.Config) wait.ConditionFunc {
Logf("Unexpected TLS error: %v", err)
return false, nil
}
conn.Close()
defer conn.Close()
return true, nil
}

View file

@ -93,7 +93,7 @@ func CreateKubeNamespace(baseName string, c kubernetes.Interface) (string, error
var got *corev1.Namespace
var err error
err = wait.PollImmediate(Poll, DefaultTimeout, func() (bool, error) {
err = wait.Poll(Poll, DefaultTimeout, func() (bool, error) {
got, err = c.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
if err != nil {
Logf("Unexpected error while creating namespace: %v", err)
@ -119,7 +119,7 @@ func deleteKubeNamespace(c kubernetes.Interface, namespace string) error {
// WaitForKubeNamespaceNotExist waits until a namespaces is not present in the cluster
func WaitForKubeNamespaceNotExist(c kubernetes.Interface, namespace string) error {
return wait.PollImmediate(Poll, DefaultTimeout, namespaceNotExist(c, namespace))
return wait.Poll(Poll, DefaultTimeout, namespaceNotExist(c, namespace))
}
func namespaceNotExist(c kubernetes.Interface, namespace string) wait.ConditionFunc {
@ -137,7 +137,7 @@ func namespaceNotExist(c kubernetes.Interface, namespace string) wait.ConditionF
// WaitForNoPodsInNamespace waits until there are no pods running in a namespace
func WaitForNoPodsInNamespace(c kubernetes.Interface, namespace string) error {
return wait.PollImmediate(Poll, DefaultTimeout, noPodsInNamespace(c, namespace))
return wait.Poll(Poll, DefaultTimeout, noPodsInNamespace(c, namespace))
}
func noPodsInNamespace(c kubernetes.Interface, namespace string) wait.ConditionFunc {
@ -167,12 +167,12 @@ func WaitForPodRunningInNamespace(c kubernetes.Interface, pod *corev1.Pod) error
}
func waitTimeoutForPodRunningInNamespace(c kubernetes.Interface, podName, namespace string, timeout time.Duration) error {
return wait.PollImmediate(Poll, DefaultTimeout, podRunning(c, podName, namespace))
return wait.Poll(Poll, DefaultTimeout, podRunning(c, podName, namespace))
}
// WaitForSecretInNamespace waits a default amount of time for the specified secret is present in a particular namespace
func WaitForSecretInNamespace(c kubernetes.Interface, namespace, name string) error {
return wait.PollImmediate(Poll, DefaultTimeout, secretInNamespace(c, namespace, name))
return wait.Poll(Poll, DefaultTimeout, secretInNamespace(c, namespace, name))
}
func secretInNamespace(c kubernetes.Interface, namespace, name string) wait.ConditionFunc {
@ -194,7 +194,7 @@ func secretInNamespace(c kubernetes.Interface, namespace, name string) wait.Cond
// WaitForFileInFS waits a default amount of time for the specified file is present in the filesystem
func WaitForFileInFS(file string) error {
return wait.PollImmediate(Poll, DefaultTimeout, fileInFS(file))
return wait.Poll(Poll, DefaultTimeout, fileInFS(file))
}
func fileInFS(file string) wait.ConditionFunc {
@ -218,7 +218,7 @@ func fileInFS(file string) wait.ConditionFunc {
// WaitForNoIngressInNamespace waits until there is no ingress object in a particular namespace
func WaitForNoIngressInNamespace(c kubernetes.Interface, namespace, name string) error {
return wait.PollImmediate(Poll, DefaultTimeout, noIngressInNamespace(c, namespace, name))
return wait.Poll(Poll, DefaultTimeout, noIngressInNamespace(c, namespace, name))
}
func noIngressInNamespace(c kubernetes.Interface, namespace, name string) wait.ConditionFunc {
@ -240,7 +240,7 @@ func noIngressInNamespace(c kubernetes.Interface, namespace, name string) wait.C
// WaitForIngressInNamespace waits until a particular ingress object exists namespace
func WaitForIngressInNamespace(c kubernetes.Interface, namespace, name string) error {
return wait.PollImmediate(Poll, DefaultTimeout, ingressInNamespace(c, namespace, name))
return wait.Poll(Poll, DefaultTimeout, ingressInNamespace(c, namespace, name))
}
func ingressInNamespace(c kubernetes.Interface, namespace, name string) wait.ConditionFunc {

View file

@ -98,18 +98,18 @@ var _ = framework.IngressNginxDescribe("[Flag] custom HTTP and HTTPS ports", fun
ginkgo.Context("when external authentication is configured", func() {
ginkgo.It("should set the X-Forwarded-Port header to 443", func() {
f.NewHttpbinDeployment()
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(context.TODO(), framework.HTTPBinService, metav1.GetOptions{})
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP = e.Subsets[0].Addresses[0].IP
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets), 1, "expected at least one endpoint")
assert.GreaterOrEqual(ginkgo.GinkgoT(), len(e.Subsets[0].Addresses), 1, "expected at least one address ready in the endpoint")
httpbinIP := e.Subsets[0].Addresses[0].IP
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-url": fmt.Sprintf("http://%s/basic-auth/user/password", httpbinIP),
@ -127,6 +127,7 @@ var _ = framework.IngressNginxDescribe("[Flag] custom HTTP and HTTPS ports", fun
assert.Nil(ginkgo.GinkgoT(), err)
framework.WaitForTLS(f.GetURL(framework.HTTPS), tlsConfig)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "server_name forwarded-headers")