Skip to content

Commit

Permalink
Adjust OVN TransitSwitchIP initialization
Browse files Browse the repository at this point in the history
We've observed E2E failures on route agent restart that was caused by
the addition of the TransitSwitchIP refactoring. On code inspection,
there's a potential timing issue related to initialization of the
TransitSwitchIP. The Init method is called by
NonGatewayRouteHandler.Init however the NewNonGatewayRouteController
is started before that in Handler.Init so, depending on timing,
nonGatewayRouteCreatedOrUpdated could get invoked prior to
initialization of the TransitSwitchIP, in which case it would observe
an empty IP.

To avoid this, move the TransitSwitchIP.Init call to Handler.Init prior
to starting the NewNonGatewayRouteController.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
  • Loading branch information
tpantelis committed Oct 18, 2024
1 parent 3d249ba commit 5b70b1e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
7 changes: 6 additions & 1 deletion pkg/routeagent_driver/handlers/ovn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type HandlerConfig struct {
DynClient dynamic.Interface
WatcherConfig *watcher.Config
NewOVSDBClient NewOVSDBClientFn
TransitSwitchIP TransitSwitchIPGetter
TransitSwitchIP TransitSwitchIP
}

type Handler struct {
Expand Down Expand Up @@ -114,6 +114,11 @@ func (ovn *Handler) Init() error {
return errors.Wrapf(err, "error getting connection handler to connect to OvnDB")
}

err = ovn.TransitSwitchIP.Init(ovn.K8sClient)
if err != nil {
return errors.Wrap(err, "error initializing TransitSwitchIP")
}

gatewayRouteController, err := NewGatewayRouteController(*ovn.WatcherConfig, connectionHandler, ovn.Namespace)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/routeagent_driver/handlers/ovn/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ var _ = Describe("Handler", func() {
}))

Expect(ovsdbClient.Connected()).To(BeTrue())
Expect(transitSwitchIP.Init(t.k8sClient)).To(Succeed())
})

When("a remote Endpoint is created, updated, and deleted", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,26 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

type NonGatewayRouteHandler struct {
event.HandlerBase
event.NodeHandlerBase
smClient submarinerClientset.Interface
k8sClient kubernetes.Interface
transitSwitchIP TransitSwitchIP
}

func NewNonGatewayRouteHandler(smClient submarinerClientset.Interface, k8sClient kubernetes.Interface, transitSwitchIP TransitSwitchIP,
func NewNonGatewayRouteHandler(smClient submarinerClientset.Interface, transitSwitchIP TransitSwitchIP,
) *NonGatewayRouteHandler {
return &NonGatewayRouteHandler{
smClient: smClient,
k8sClient: k8sClient,
transitSwitchIP: transitSwitchIP,
}
}

func (h *NonGatewayRouteHandler) Init() error {
logger.Info("Starting NonGatewayRouteHandler")
return errors.Wrap(h.transitSwitchIP.Init(h.k8sClient), "error initializing TransitSwitchIP")
return nil
}

func (h *NonGatewayRouteHandler) GetName() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ var _ = Describe("NonGatewayRouteHandler", func() {
t := newTestDriver()

JustBeforeEach(func() {
t.Start(ovn.NewNonGatewayRouteHandler(t.submClient, t.k8sClient, ovn.NewTransitSwitchIP()))
tsIP := ovn.NewTransitSwitchIP()
t.Start(ovn.NewNonGatewayRouteHandler(t.submClient, tsIP))
Expect(tsIP.Init(t.k8sClient)).To(Succeed())
})

awaitNonGatewayRoute := func(ep *submarinerv1.Endpoint) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/routeagent_driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func main() {
TransitSwitchIP: transitSwitchIP,
}),
ovn.NewGatewayRouteHandler(smClientset),
ovn.NewNonGatewayRouteHandler(smClientset, k8sClientSet, transitSwitchIP),
ovn.NewNonGatewayRouteHandler(smClientset, transitSwitchIP),
cabledriver.NewXRFMCleanupHandler(),
cabledriver.NewVXLANCleanup(),
mtu.NewMTUHandler(env.ClusterCidr, len(env.GlobalCidr) != 0, getTCPMssValue(localNode)),
Expand Down

0 comments on commit 5b70b1e

Please sign in to comment.