Fixes wait for project creation (#2330)

* Fixes wait for project creation

* Fixes unit test

* Changes hardcoded string to corev1.NamespaceActive

* Removed Kcore package, added unit test and comments

* Uses helper.WaitForCmdOut to wait and get the desired output for project list
This commit is contained in:
Mrinal Das
2020-03-19 21:16:04 +05:30
committed by GitHub
parent 6112ed2833
commit 91534dd188
5 changed files with 139 additions and 12 deletions

View File

@@ -33,6 +33,12 @@ func Create(client *occlient.Client, projectName string, wait bool) error {
if err != nil {
return errors.Wrap(err, "unable to create new project")
}
if wait {
err = client.WaitForServiceAccountInNamespace(projectName, "default")
if err != nil {
return errors.Wrap(err, "unable to wait for service account")
}
}
return nil
}

View File

@@ -1,6 +1,7 @@
package project
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"reflect"
"testing"
@@ -66,12 +67,25 @@ func TestCreate(t *testing.T) {
})
go func() {
fkWatch.Add(testingutil.FakeProjectStatus(corev1.NamespacePhase(""), tt.projectName))
fkWatch.Add(testingutil.FakeProjectStatus(corev1.NamespacePhase("Active"), tt.projectName))
}()
fakeClientSet.ProjClientset.PrependWatchReactor("projects", func(action ktesting.Action) (handled bool, ret watch.Interface, err error) {
return true, fkWatch, nil
})
fkWatch2 := watch.NewFake()
go func() {
fkWatch2.Add(&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
})
}()
fakeClientSet.Kubernetes.PrependWatchReactor("serviceaccounts", func(action ktesting.Action) (handled bool, ret watch.Interface, err error) {
return true, fkWatch2, nil
})
// The function we are testing
err := Create(client, tt.projectName, true)