Add missing test framework helper
This commit is contained in:
parent
e9a00ff916
commit
c5df325c98
1 changed files with 27 additions and 1 deletions
|
@ -32,6 +32,7 @@ import (
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"k8s.io/client-go/tools/clientcmd/api"
|
"k8s.io/client-go/tools/clientcmd/api"
|
||||||
|
"k8s.io/ingress-nginx/internal/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -97,9 +98,10 @@ var RunID = uuid.NewUUID()
|
||||||
|
|
||||||
// CreateKubeNamespace creates a new namespace in the cluster
|
// CreateKubeNamespace creates a new namespace in the cluster
|
||||||
func CreateKubeNamespace(baseName string, c kubernetes.Interface) (*v1.Namespace, error) {
|
func CreateKubeNamespace(baseName string, c kubernetes.Interface) (*v1.Namespace, error) {
|
||||||
|
ts := time.Now().UnixNano()
|
||||||
ns := &v1.Namespace{
|
ns := &v1.Namespace{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
GenerateName: fmt.Sprintf("e2e-tests-%v-", baseName),
|
GenerateName: fmt.Sprintf("e2e-tests-%v-%v-", baseName, ts),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Be robust about making the namespace creation call.
|
// Be robust about making the namespace creation call.
|
||||||
|
@ -207,6 +209,30 @@ 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, fs file.Filesystem) error {
|
||||||
|
return wait.PollImmediate(1*time.Second, time.Minute*2, fileInFS(file, fs))
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileInFS(file string, fs file.Filesystem) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
stat, err := fs.Stat(file)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat == nil {
|
||||||
|
return false, fmt.Errorf("file %v does not exists", file)
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat.Size() > 0 {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, fmt.Errorf("the file %v exists but it is empty", file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WaitForNoIngressInNamespace waits until there is no ingress object in a particular namespace
|
// WaitForNoIngressInNamespace waits until there is no ingress object in a particular namespace
|
||||||
func WaitForNoIngressInNamespace(c kubernetes.Interface, namespace, name string) error {
|
func WaitForNoIngressInNamespace(c kubernetes.Interface, namespace, name string) error {
|
||||||
return wait.PollImmediate(1*time.Second, time.Minute*2, noIngressInNamespace(c, namespace, name))
|
return wait.PollImmediate(1*time.Second, time.Minute*2, noIngressInNamespace(c, namespace, name))
|
||||||
|
|
Loading…
Reference in a new issue