@@ -35,6 +35,7 @@ import (
3535 "github.com/skupperproject/skupper/internal/kube/resource"
3636 "github.com/skupperproject/skupper/internal/network"
3737 "github.com/skupperproject/skupper/internal/qdr"
38+ "github.com/skupperproject/skupper/internal/utils"
3839 "github.com/skupperproject/skupper/internal/version"
3940 skupperv2alpha1 "github.com/skupperproject/skupper/pkg/apis/skupper/v2alpha1"
4041)
@@ -663,6 +664,18 @@ func TestUpdate(t *testing.T) {
663664 serviceCheck ("adifferentsvc" , "test" ).check ,
664665 negativeServiceCheck ("mysvc" , "test" ),
665666 },
667+ }, {
668+ name : "listener service recreated when deleted" ,
669+ skupperObjects : []runtime.Object {
670+ f .site ("mysite" , "test" , "" , false , false ),
671+ f .listener ("mylistener" , "test" , "mysvc" , 8080 ),
672+ },
673+ functions : []WaitFunction {
674+ isListenerStatusConditionTrue ("mylistener" , "test" , skupperv2alpha1 .CONDITION_TYPE_CONFIGURED ),
675+ serviceCheck ("mysvc" , "test" ).check ,
676+ deleteListenerService ("mysvc" , "test" ),
677+ waitForService ("mysvc" , "test" ),
678+ },
666679 }, {
667680 name : "exposePodsByName handles pod delete" ,
668681 k8sObjects : []runtime.Object {
@@ -840,6 +853,47 @@ func TestUpdate(t *testing.T) {
840853 }
841854}
842855
856+ func TestListenerServiceRecreatedWhenDeleted (t * testing.T ) {
857+ runListenerServiceRecreatedWithFakeClient (t )
858+ }
859+
860+ func runListenerServiceRecreatedWithFakeClient (t * testing.T ) {
861+ t .Helper ()
862+ flags := flag .NewFlagSet ("" , flag .ContinueOnError )
863+ config , err := BoundConfig (flags )
864+ assert .NilError (t , err )
865+ clients , err := fakeclient .NewFakeClient ("test" , nil , []runtime.Object {
866+ f .site ("mysite" , "test" , "" , false , false ),
867+ f .listener ("mylistener" , "test" , "mysvc" , 8080 ),
868+ }, "" )
869+ assert .NilError (t , err )
870+ enableSSA (clients .GetDynamicClient ())
871+ ctrl , err := NewController (clients , config , func (e * watchers.EventProcessor ) { e .SetResyncShort (time .Second ) })
872+ assert .NilError (t , err )
873+ stopCh := make (chan struct {})
874+ err = ctrl .init (stopCh )
875+ assert .NilError (t , err )
876+ for i := 0 ; i < 2 ; i ++ {
877+ ctrl .eventProcessor .TestProcess ()
878+ }
879+ err = utils .Retry (100 * time .Millisecond , 50 , func () (bool , error ) {
880+ ctrl .eventProcessor .TestProcess ()
881+ return isListenerStatusConditionTrue ("mylistener" , "test" , skupperv2alpha1 .CONDITION_TYPE_CONFIGURED )(t , clients ), nil
882+ })
883+ assert .NilError (t , err )
884+ err = utils .Retry (100 * time .Millisecond , 50 , func () (bool , error ) {
885+ ctrl .eventProcessor .TestProcess ()
886+ return serviceCheck ("mysvc" , "test" ).check (t , clients ), nil
887+ })
888+ assert .NilError (t , err )
889+ deleteListenerService ("mysvc" , "test" )(t , clients )
890+ err = utils .Retry (100 * time .Millisecond , 50 , func () (bool , error ) {
891+ ctrl .eventProcessor .TestProcess ()
892+ return waitForService ("mysvc" , "test" )(t , clients ), nil
893+ })
894+ assert .NilError (t , err )
895+ }
896+
843897func deleteAttachedConnector (name string , namespace string ) WaitFunction {
844898 return func (t * testing.T , clients internalclient.Clients ) bool {
845899 err := clients .GetSkupperClient ().SkupperV2alpha1 ().AttachedConnectors (namespace ).Delete (context .Background (), name , metav1.DeleteOptions {})
@@ -1973,6 +2027,17 @@ func (s *ServiceCheck) checkAbsent(t *testing.T, clients internalclient.Clients)
19732027 return false
19742028}
19752029
2030+ func waitForService (name string , namespace string ) WaitFunction {
2031+ return func (t * testing.T , clients internalclient.Clients ) bool {
2032+ _ , err := clients .GetKubeClient ().CoreV1 ().Services (namespace ).Get (context .Background (), name , metav1.GetOptions {})
2033+ if errors .IsNotFound (err ) {
2034+ return false
2035+ }
2036+ assert .Assert (t , err )
2037+ return true
2038+ }
2039+ }
2040+
19762041func updateListener (name string , namespace string , host string , port int ) WaitFunction {
19772042 return func (t * testing.T , clients internalclient.Clients ) bool {
19782043 ctxt := context .Background ()
@@ -1995,6 +2060,14 @@ func negativeServiceCheck(name string, namespace string) WaitFunction {
19952060 }
19962061}
19972062
2063+ func deleteListenerService (serviceName string , namespace string ) WaitFunction {
2064+ return func (t * testing.T , clients internalclient.Clients ) bool {
2065+ err := clients .GetKubeClient ().CoreV1 ().Services (namespace ).Delete (context .Background (), serviceName , metav1.DeleteOptions {})
2066+ assert .Assert (t , err )
2067+ return true
2068+ }
2069+ }
2070+
19982071func deleteTargetPod (name string , namespace string ) WaitFunction {
19992072 return func (t * testing.T , clients internalclient.Clients ) bool {
20002073 ctxt := context .Background ()
0 commit comments