Repository: submariner-io/lighthouse
Pull request #483 (2021-03-05 15:04:29)

Adjust unit tests to EndpointSlice DeleteCollection change
The `EndpointController` now explicitly deletes `EndpointSlices` via `DeleteCollection` so remove the explicit deletion in the unit tests so we can properly verify `EndpointSlice` cleanup. Also the admiral fake DynamicClient now implements `DeleteCollection` internally so no need to add the reactor.



Patch:
diff --git a/go.mod b/go.mod
index 1fbdd5d..8b23327 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,7 @@ require (
 	github.com/onsi/gomega v1.11.0
 	github.com/pkg/errors v0.9.1
 	github.com/prometheus/client_golang v1.9.0
-	github.com/submariner-io/admiral v0.9.0-m1
+	github.com/submariner-io/admiral v0.9.0-m1.0.20210303181719-5bb1de3368b5
 	github.com/submariner-io/shipyard v0.9.0-m1
 	go.uber.org/zap v1.15.0 // indirect
 	golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
diff --git a/go.sum b/go.sum
index f06a42c..5b06a3a 100644
--- a/go.sum
+++ b/go.sum
@@ -726,6 +726,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/submariner-io/admiral v0.9.0-m1 h1:7QSdxC2eiX6bbuHOr8+fAzoOA49h35Q3v2mSwr5sk4Y=
 github.com/submariner-io/admiral v0.9.0-m1/go.mod h1:NFsFrk2CDac2ekq+EDqgPiyh9Tu4f6crh01HJJv2+M4=
+github.com/submariner-io/admiral v0.9.0-m1.0.20210303181719-5bb1de3368b5 h1:Iups7HVvWOBc3BZGkTZo07Iar3dLAukbTgR2gB0dt1M=
+github.com/submariner-io/admiral v0.9.0-m1.0.20210303181719-5bb1de3368b5/go.mod h1:NFsFrk2CDac2ekq+EDqgPiyh9Tu4f6crh01HJJv2+M4=
 github.com/submariner-io/shipyard v0.9.0-m1 h1:UILEZrgtugmDUxOFnWmeGmMk0NTxcavsEXgzptxAKNg=
 github.com/submariner-io/shipyard v0.9.0-m1/go.mod h1:XL69zONy2SW6O9duwGX3riLC04GWtx+JwGn5ZtqLu6U=
 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
diff --git a/pkg/agent/controller/agent.go b/pkg/agent/controller/agent.go
index 4bee305..c01efe8 100644
--- a/pkg/agent/controller/agent.go
+++ b/pkg/agent/controller/agent.go
@@ -22,6 +22,7 @@ import (
 	"github.com/pkg/errors"
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/submariner-io/admiral/pkg/log"
+	"github.com/submariner-io/admiral/pkg/resource"
 	"github.com/submariner-io/admiral/pkg/syncer"
 	"github.com/submariner-io/admiral/pkg/syncer/broker"
 	"github.com/submariner-io/admiral/pkg/util"
@@ -387,7 +388,7 @@ func (a *Controller) updateExportedServiceStatus(name, namespace string, condTyp
 			toUpdate.Status.Conditions = append(toUpdate.Status.Conditions, exportCondition)
 		}
 
-		raw, err := util.ToUnstructured(toUpdate)
+		raw, err := resource.ToUnstructured(toUpdate)
 		if err != nil {
 			return err
 		}


Test patch:
diff --git a/pkg/agent/controller/agent_test.go b/pkg/agent/controller/agent_test.go
index d062146..a5301ba 100644
--- a/pkg/agent/controller/agent_test.go
+++ b/pkg/agent/controller/agent_test.go
@@ -508,8 +508,6 @@ func (c *cluster) init(syncerConfig broker.SyncerConfig) {
 	fakeCS := fakeKubeClient.NewSimpleClientset()
 	c.endpointsReactor = fake.NewFailingReactorForResource(&fakeCS.Fake, "endpoints")
 	c.localKubeClient = fakeCS
-
-	fake.AddDeleteCollectionReactor(&fakeCS.Fake, "EndpointSlice")
 }
 
 func (c *cluster) start(t *testDriver, syncerConfig broker.SyncerConfig) {
@@ -896,9 +894,6 @@ func (t *testDriver) awaitServiceUnexported() {
 func (t *testDriver) awaitHeadlessServiceUnexported() {
 	t.awaitServiceUnexported()
 
-	// In a real k8s env, the EndpointSlice would be deleted via k8s GC as it is owned by the ServiceImport.
-	Expect(t.cluster1.localEndpointSliceClient.Delete(t.endpoints.Name+"-"+clusterID1, nil)).To(Succeed())
-
 	t.awaitNoEndpointSlice(t.cluster1.localEndpointSliceClient)
 	t.awaitNoEndpointSlice(t.brokerEndpointSliceClient)
 	t.awaitNoEndpointSlice(t.cluster2.localEndpointSliceClient)