@@ -624,6 +624,18 @@ func TestUpdate(t *testing.T) {
624624 serviceCheck ("adifferentsvc" , "test" ).check ,
625625 negativeServiceCheck ("mysvc" , "test" ),
626626 },
627+ }, {
628+ name : "listener service recreated when deleted" ,
629+ skupperObjects : []runtime.Object {
630+ f .site ("mysite" , "test" , "" , false , false ),
631+ f .listener ("mylistener" , "test" , "mysvc" , 8080 ),
632+ },
633+ functions : []WaitFunction {
634+ isListenerStatusConditionTrue ("mylistener" , "test" , skupperv2alpha1 .CONDITION_TYPE_CONFIGURED ),
635+ serviceCheck ("mysvc" , "test" ).check ,
636+ deleteListenerService ("mysvc" , "test" ),
637+ waitForService ("mysvc" , "test" ),
638+ },
627639 }, {
628640 name : "exposePodsByName handles pod delete" ,
629641 k8sObjects : []runtime.Object {
@@ -801,6 +813,41 @@ func TestUpdate(t *testing.T) {
801813 }
802814}
803815
816+ func TestListenerServiceRecreatedWhenDeleted (t * testing.T ) {
817+ runListenerServiceRecreatedWithFakeClient (t )
818+ }
819+
820+ func runListenerServiceRecreatedWithFakeClient (t * testing.T ) {
821+ t .Helper ()
822+ flags := flag .NewFlagSet ("" , flag .ContinueOnError )
823+ config , err := BoundConfig (flags )
824+ assert .NilError (t , err )
825+ clients , err := fakeclient .NewFakeClient ("test" , nil , []runtime.Object {
826+ f .site ("mysite" , "test" , "" , false , false ),
827+ f .listener ("mylistener" , "test" , "mysvc" , 8080 ),
828+ }, "" )
829+ assert .NilError (t , err )
830+ enableSSA (clients .GetDynamicClient ())
831+ ctrl , err := NewController (clients , config , func (e * watchers.EventProcessor ) { e .SetResyncShort (time .Second ) })
832+ assert .NilError (t , err )
833+ stopCh := make (chan struct {})
834+ err = ctrl .init (stopCh )
835+ assert .NilError (t , err )
836+ for i := 0 ; i < 2 ; i ++ {
837+ ctrl .eventProcessor .TestProcess ()
838+ }
839+ for ! isListenerStatusConditionTrue ("mylistener" , "test" , skupperv2alpha1 .CONDITION_TYPE_CONFIGURED )(t , clients ) {
840+ ctrl .eventProcessor .TestProcess ()
841+ }
842+ for ! serviceCheck ("mysvc" , "test" ).check (t , clients ) {
843+ ctrl .eventProcessor .TestProcess ()
844+ }
845+ deleteListenerService ("mysvc" , "test" )(t , clients )
846+ for ! waitForService ("mysvc" , "test" )(t , clients ) {
847+ ctrl .eventProcessor .TestProcess ()
848+ }
849+ }
850+
804851func deleteAttachedConnector (name string , namespace string ) WaitFunction {
805852 return func (t * testing.T , clients internalclient.Clients ) bool {
806853 err := clients .GetSkupperClient ().SkupperV2alpha1 ().AttachedConnectors (namespace ).Delete (context .Background (), name , metav1.DeleteOptions {})
@@ -1929,6 +1976,17 @@ func (s *ServiceCheck) checkAbsent(t *testing.T, clients internalclient.Clients)
19291976 return false
19301977}
19311978
1979+ func waitForService (name string , namespace string ) WaitFunction {
1980+ return func (t * testing.T , clients internalclient.Clients ) bool {
1981+ _ , err := clients .GetKubeClient ().CoreV1 ().Services (namespace ).Get (context .Background (), name , metav1.GetOptions {})
1982+ if errors .IsNotFound (err ) {
1983+ return false
1984+ }
1985+ assert .Assert (t , err )
1986+ return true
1987+ }
1988+ }
1989+
19321990func updateListener (name string , namespace string , host string , port int ) WaitFunction {
19331991 return func (t * testing.T , clients internalclient.Clients ) bool {
19341992 ctxt := context .Background ()
@@ -1951,6 +2009,14 @@ func negativeServiceCheck(name string, namespace string) WaitFunction {
19512009 }
19522010}
19532011
2012+ func deleteListenerService (serviceName string , namespace string ) WaitFunction {
2013+ return func (t * testing.T , clients internalclient.Clients ) bool {
2014+ err := clients .GetKubeClient ().CoreV1 ().Services (namespace ).Delete (context .Background (), serviceName , metav1.DeleteOptions {})
2015+ assert .Assert (t , err )
2016+ return true
2017+ }
2018+ }
2019+
19542020func deleteTargetPod (name string , namespace string ) WaitFunction {
19552021 return func (t * testing.T , clients internalclient.Clients ) bool {
19562022 ctxt := context .Background ()
0 commit comments