@@ -24,8 +24,8 @@ import (
2424 "time"
2525)
2626
27- const waitForCreationInterval = 200 * time .Millisecond
28- const waitForCreationTimeout = 3 * time .Second
27+ const waitForInterval = 200 * time .Millisecond
28+ const waitForTimeout = 3 * time .Second
2929
3030type ControllerManagerTestSuiteBase struct {
3131 suite.Suite
@@ -92,8 +92,8 @@ func (s *ControllerManagerTestSuiteBase) TearDownTest() {
9292// waitForObjectToBeCreated tries to get an object multiple times until it is available in the k8s API server
9393func (s * ControllerManagerTestSuiteBase ) waitForObjectToBeCreated (obj client.Object ) {
9494 s .Require ().NoError (wait .PollUntilContextTimeout (context .Background (),
95- waitForCreationInterval ,
96- waitForCreationTimeout ,
95+ waitForInterval ,
96+ waitForTimeout ,
9797 true ,
9898 func (ctx context.Context ) (done bool , err error ) {
9999 err = s .Mgr .GetClient ().Get (ctx , types.NamespacedName {Name : obj .GetName (), Namespace : obj .GetNamespace ()}, obj )
@@ -108,6 +108,24 @@ func (s *ControllerManagerTestSuiteBase) waitForObjectToBeCreated(obj client.Obj
108108 )
109109}
110110
111+ func (s * ControllerManagerTestSuiteBase ) WaitForObjectToBeDeleted (obj client.Object ) {
112+ s .Require ().NoError (wait .PollUntilContextTimeout (context .Background (),
113+ waitForInterval ,
114+ waitForTimeout ,
115+ true ,
116+ func (ctx context.Context ) (done bool , err error ) {
117+ err = s .Mgr .GetClient ().Get (ctx , types.NamespacedName {Name : obj .GetName (), Namespace : obj .GetNamespace ()}, obj )
118+ if k8serrors .IsNotFound (err ) {
119+ return true , nil
120+ }
121+ if err != nil {
122+ return false , errors .Wrap (err )
123+ }
124+ return false , nil
125+ }),
126+ )
127+ }
128+
111129func (s * ControllerManagerTestSuiteBase ) AddPod (name string , podIp string , labels map [string ]string , ownerRefs []metav1.OwnerReference ) * corev1.Pod {
112130 pod := & corev1.Pod {
113131 ObjectMeta : metav1.ObjectMeta {Name : name , Namespace : s .TestNamespace , Labels : labels },
@@ -305,8 +323,8 @@ func (s *ControllerManagerTestSuiteBase) AddIngress(name string, serviceName str
305323func (s * ControllerManagerTestSuiteBase ) GetAPIServerService () * corev1.Service {
306324 service := & corev1.Service {}
307325 s .Require ().NoError (wait .PollUntilContextTimeout (context .Background (),
308- waitForCreationInterval ,
309- waitForCreationTimeout ,
326+ waitForInterval ,
327+ waitForTimeout ,
310328 true ,
311329 func (ctx context.Context ) (done bool , err error ) {
312330 err = s .Mgr .GetClient ().Get (ctx , types.NamespacedName {Name : "kubernetes" , Namespace : "default" }, service )
@@ -325,8 +343,8 @@ func (s *ControllerManagerTestSuiteBase) GetAPIServerService() *corev1.Service {
325343func (s * ControllerManagerTestSuiteBase ) GetAPIServerEndpoints () * corev1.Endpoints {
326344 endpoints := & corev1.Endpoints {}
327345 s .Require ().NoError (wait .PollUntilContextTimeout (context .Background (),
328- waitForCreationInterval ,
329- waitForCreationTimeout ,
346+ waitForInterval ,
347+ waitForTimeout ,
330348 true ,
331349 func (ctx context.Context ) (done bool , err error ) {
332350 err = s .Mgr .GetClient ().Get (ctx , types.NamespacedName {Name : "kubernetes" , Namespace : "default" }, endpoints )
0 commit comments