Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Gateway resource is deleted on shutdown #2356

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type componentsType struct {
gatewayPod *pod.GatewayPod
submSpec types.SubmarinerSpecification
stopCh <-chan struct{}
waitGroup sync.WaitGroup
}

const (
Expand Down Expand Up @@ -182,7 +183,7 @@ func main() {
components.gatewayPod, err = pod.NewGatewayPod(k8sClient)
logger.FatalOnError(err, "Error creating a handler to update the gateway pod")

components.cableEngineSyncer.Run(components.stopCh)
components.runAsync(components.cableEngineSyncer.Run)

if !airGapped {
components.initPublicIPWatcher(k8sClient, submarinerClient, localEndpoint)
Expand Down Expand Up @@ -214,6 +215,8 @@ func main() {
if err := httpServer.Shutdown(context.TODO()); err != nil {
logger.Errorf(err, "Error shutting down metrics HTTP server")
}

components.waitGroup.Wait()
}

func isAirGappedDeployment() bool {
Expand Down Expand Up @@ -317,6 +320,15 @@ func (c *componentsType) initPublicIPWatcher(k8sClient kubernetes.Interface, sub
c.publicIPWatcher = endpoint.NewPublicIPWatcher(publicIPConfig)
}

func (c *componentsType) runAsync(run func(<-chan struct{})) {
c.waitGroup.Add(1)

go func() {
defer c.waitGroup.Done()
run(c.stopCh)
}()
}

func submarinerClusterFrom(submSpec *types.SubmarinerSpecification) *types.SubmarinerCluster {
return &types.SubmarinerCluster{
ID: submSpec.ClusterID,
Expand Down
6 changes: 2 additions & 4 deletions pkg/cableengine/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ func NewGatewaySyncer(engine cableengine.Engine, client v1typed.GatewayInterface
}

func (gs *GatewaySyncer) Run(stopCh <-chan struct{}) {
go func() {
wait.Until(gs.syncGatewayStatus, GatewayUpdateInterval, stopCh)
gs.CleanupGatewayEntry()
}()
wait.Until(gs.syncGatewayStatus, GatewayUpdateInterval, stopCh)
gs.CleanupGatewayEntry()

logger.Info("CableEngine syncer started")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cableengine/syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func (t *testDriver) run() {
go informer.Run(t.stopInformer)
Expect(cache.WaitForCacheSync(t.stopInformer, informer.HasSynced)).To(BeTrue())

t.syncer.Run(t.stopSyncer)
go t.syncer.Run(t.stopSyncer)

Expect(t.healthChecker.Start(t.stopSyncer)).To(Succeed())
}
Expand Down
17 changes: 16 additions & 1 deletion test/e2e/redundancy/gateway_failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func testGatewayPodRestartScenario(f *subFramework.Framework) {
By(fmt.Sprintf("Found new submariner gateway pod %q", newGatewayPod.Name))

By(fmt.Sprintf("Waiting for the gateway to be up and connected %q", newGatewayPod.Name))
f.AwaitGatewayFullyConnected(framework.ClusterIndex(primaryCluster), resource.EnsureValidName(activeGateway.Name))
AwaitNewSubmarinerGatewayFullyConnected(f, framework.ClusterIndex(primaryCluster), activeGateway.Name, activeGateway.UID)

By(fmt.Sprintf("Verifying TCP connectivity from gateway node on %q to gateway node on %q", secondaryClusterName, primaryClusterName))
subFramework.VerifyDatapathConnectivity(tcp.ConnectivityTestParams{
Expand Down Expand Up @@ -147,6 +147,21 @@ func AwaitNewSubmarinerGatewayPod(f *subFramework.Framework, cluster framework.C
}).(*v1.Pod)
}

func AwaitNewSubmarinerGatewayFullyConnected(f *subFramework.Framework, cluster framework.ClusterIndex, name string,
prevPodUID types.UID,
) *subv1.Gateway {
return framework.AwaitUntil("await new submariner gateway", func() (interface{}, error) {
return f.AwaitGatewayFullyConnected(cluster, resource.EnsureValidName(name)), nil
}, func(result interface{}) (bool, string, error) {
gw := result.(*subv1.Gateway)
if gw.ObjectMeta.UID != prevPodUID {
return true, "", nil
}

return false, fmt.Sprintf("Expecting new gateway (UID %q matches previous instance)", prevPodUID), nil
}).(*subv1.Gateway)
}

func defaultEndpointType() tcp.EndpointType {
if framework.TestContext.GlobalnetEnabled {
return tcp.GlobalIP
Expand Down