
All code must use the context from Ginkgo when doing API calls or polling for a change, otherwise the code would not return immediately when the test gets aborted.
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
/*
|
|
Copyright 2019 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package node
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl"
|
|
)
|
|
|
|
// WaitForSSHTunnels waits for establishing SSH tunnel to busybox pod.
|
|
func WaitForSSHTunnels(ctx context.Context, namespace string) {
|
|
framework.Logf("Waiting for SSH tunnels to establish")
|
|
e2ekubectl.RunKubectl(namespace, "run", "ssh-tunnel-test",
|
|
"--image=busybox",
|
|
"--restart=Never",
|
|
"--command", "--",
|
|
"echo", "Hello")
|
|
defer e2ekubectl.RunKubectl(namespace, "delete", "pod", "ssh-tunnel-test")
|
|
|
|
// allow up to a minute for new ssh tunnels to establish
|
|
wait.PollImmediateWithContext(ctx, 5*time.Second, time.Minute, func(ctx context.Context) (bool, error) {
|
|
_, err := e2ekubectl.RunKubectl(namespace, "logs", "ssh-tunnel-test")
|
|
return err == nil, nil
|
|
})
|
|
}
|