Skip to content

Commit

Permalink
E2E: delete service if already exists (submariner-io#247)
Browse files Browse the repository at this point in the history
If you try to run a second service connectivity test in a spec it will
fail due to the service already existing. Modified CreateTCPService so if
it fails with IsAlreadyExists error, delete the service and try again.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
  • Loading branch information
tpantelis authored Dec 9, 2019
1 parent 5af08a8 commit 86cd26c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/e2e/framework/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package framework
import (
"fmt"

. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
Expand All @@ -31,11 +31,19 @@ func (f *Framework) CreateTCPService(cluster ClusterIndex, selectorName string,
},
}

kube := f.ClusterClients[cluster]
services := kube.CoreV1().Services(f.Namespace)
services := f.ClusterClients[cluster].CoreV1().Services(f.Namespace)

service, err := services.Create(&tcpService)
Expect(err).NotTo(HaveOccurred())
return AwaitUntil("create service", func() (interface{}, error) {
service, err := services.Create(&tcpService)
if errors.IsAlreadyExists(err) {
err = services.Delete(tcpService.Name, &metav1.DeleteOptions{})
if err != nil {
return nil, err
}

return service
service, err = services.Create(&tcpService)
}

return service, err
}, NoopCheckResult).(*v1.Service)
}

0 comments on commit 86cd26c

Please sign in to comment.