Skip to content

Commit 6ac9266

Browse files
aswinsuryantpantelis
authored andcommitted
Revert "Handle updates to the node OVN transit switch IP"
This reverts commit c57b883. Signed-off-by: Aswin Suryanarayanan <[email protected]>
1 parent 9bf6a60 commit 6ac9266

10 files changed

+104
-424
lines changed

pkg/routeagent_driver/handlers/ovn/handler.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ import (
4343
type NewOVSDBClientFn func(_ model.ClientDBModel, _ ...libovsdbclient.Option) (libovsdbclient.Client, error)
4444

4545
type HandlerConfig struct {
46-
Namespace string
47-
ClusterCIDR []string
48-
ServiceCIDR []string
49-
SubmClient clientset.Interface
50-
K8sClient kubernetes.Interface
51-
DynClient dynamic.Interface
52-
WatcherConfig *watcher.Config
53-
NewOVSDBClient NewOVSDBClientFn
54-
TransitSwitchIP TransitSwitchIPGetter
46+
Namespace string
47+
ClusterCIDR []string
48+
ServiceCIDR []string
49+
SubmClient clientset.Interface
50+
K8sClient kubernetes.Interface
51+
DynClient dynamic.Interface
52+
WatcherConfig *watcher.Config
53+
NewOVSDBClient NewOVSDBClientFn
5554
}
5655

5756
type Handler struct {
@@ -125,7 +124,7 @@ func (ovn *Handler) Init() error {
125124
return err
126125
}
127126

128-
nonGatewayRouteController, err := NewNonGatewayRouteController(*ovn.WatcherConfig, connectionHandler, ovn.Namespace, ovn.TransitSwitchIP)
127+
nonGatewayRouteController, err := NewNonGatewayRouteController(*ovn.WatcherConfig, connectionHandler, ovn.K8sClient, ovn.Namespace)
129128
if err != nil {
130129
return err
131130
}

pkg/routeagent_driver/handlers/ovn/handler_test.go

+19-78
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ const (
5151
var _ = Describe("Handler", func() {
5252
t := newTestDriver()
5353

54-
var (
55-
ovsdbClient *fakeovn.OVSDBClient
56-
transitSwitchIP ovn.TransitSwitchIP
57-
)
54+
var ovsdbClient *fakeovn.OVSDBClient
5855

5956
BeforeEach(func() {
6057
ovsdbClient = fakeovn.NewOVSDBClient()
@@ -82,8 +79,6 @@ var _ = Describe("Handler", func() {
8279

8380
restMapper := test.GetRESTMapperFor(&submarinerv1.GatewayRoute{}, &submarinerv1.NonGatewayRoute{})
8481

85-
transitSwitchIP = ovn.NewTransitSwitchIP()
86-
8782
t.Start(ovn.NewHandler(&ovn.HandlerConfig{
8883
Namespace: testing.Namespace,
8984
ClusterCIDR: []string{clusterCIDR},
@@ -98,11 +93,9 @@ var _ = Describe("Handler", func() {
9893
NewOVSDBClient: func(_ model.ClientDBModel, _ ...libovsdbclient.Option) (libovsdbclient.Client, error) {
9994
return ovsdbClient, nil
10095
},
101-
TransitSwitchIP: transitSwitchIP,
10296
}))
10397

10498
Expect(ovsdbClient.Connected()).To(BeTrue())
105-
Expect(transitSwitchIP.Init(t.k8sClient)).To(Succeed())
10699
})
107100

108101
When("a remote Endpoint is created, updated, and deleted", func() {
@@ -261,89 +254,37 @@ var _ = Describe("Handler", func() {
261254
})
262255
})
263256

264-
When("NonGatewayRoutes are created, updated and deleted", func() {
265-
verifyLogicalRouterPolicies := func(ngr *submarinerv1.NonGatewayRoute, nextHop string) {
266-
for _, cidr := range ngr.RoutePolicySpec.RemoteCIDRs {
267-
ovsdbClient.AwaitModel(&nbdb.LogicalRouterPolicy{
268-
Match: cidr,
269-
Nexthop: ptr.To(nextHop),
270-
})
271-
}
272-
}
273-
274-
verifyNoLogicalRouterPolicies := func(ngr *submarinerv1.NonGatewayRoute, nextHop string) {
275-
for _, cidr := range ngr.RoutePolicySpec.RemoteCIDRs {
276-
ovsdbClient.AwaitNoModel(&nbdb.LogicalRouterPolicy{
277-
Match: cidr,
278-
Nexthop: ptr.To(nextHop),
279-
})
280-
}
281-
}
282-
257+
When("a NonGatewayRoute is created and deleted", func() {
283258
It("should correctly reconcile OVN router policies", func() {
284259
client := t.dynClient.Resource(submarinerv1.SchemeGroupVersion.WithResource("nongatewayroutes")).Namespace(testing.Namespace)
285260

286-
By("Creating first NonGatewayRoute")
287-
288-
nextHop := "172.1.1.1"
289-
290-
nonGWRoute1 := &submarinerv1.NonGatewayRoute{
261+
nonGWRoute := &submarinerv1.NonGatewayRoute{
291262
ObjectMeta: metav1.ObjectMeta{
292-
Name: "test-nongateway-route1",
263+
Name: "test-nongateway-route",
293264
},
294265
RoutePolicySpec: submarinerv1.RoutePolicySpec{
295-
NextHops: []string{nextHop},
296-
RemoteCIDRs: []string{"111.0.1.0/24", "111.0.2.0/24"},
266+
NextHops: []string{"111.1.1.1"},
267+
RemoteCIDRs: []string{"192.0.1.0/24", "192.0.2.0/24"},
297268
},
298269
}
299270

300-
test.CreateResource(client, nonGWRoute1)
301-
302-
verifyLogicalRouterPolicies(nonGWRoute1, nextHop)
271+
test.CreateResource(client, nonGWRoute)
303272

304-
By("Creating second NonGatewayRoute")
305-
306-
nonGWRoute2 := &submarinerv1.NonGatewayRoute{
307-
ObjectMeta: metav1.ObjectMeta{
308-
Name: "test-nongateway-route2",
309-
},
310-
RoutePolicySpec: submarinerv1.RoutePolicySpec{
311-
NextHops: []string{nextHop},
312-
RemoteCIDRs: []string{"222.0.1.0/24", "222.0.2.0/24"},
313-
},
273+
for _, cidr := range nonGWRoute.RoutePolicySpec.RemoteCIDRs {
274+
ovsdbClient.AwaitModel(&nbdb.LogicalRouterPolicy{
275+
Match: cidr,
276+
Nexthop: ptr.To(nonGWRoute.RoutePolicySpec.NextHops[0]),
277+
})
314278
}
315279

316-
test.CreateResource(client, nonGWRoute2)
317-
318-
verifyLogicalRouterPolicies(nonGWRoute1, nextHop)
319-
verifyLogicalRouterPolicies(nonGWRoute2, nextHop)
320-
321-
By("Updating NextHop for first NonGatewayRoute")
322-
323-
prevNextHop := nextHop
324-
nextHop = "172.1.1.2"
325-
nonGWRoute1.RoutePolicySpec.NextHops[0] = nextHop
326-
327-
test.UpdateResource(client, nonGWRoute1)
328-
329-
verifyLogicalRouterPolicies(nonGWRoute1, nextHop)
330-
verifyNoLogicalRouterPolicies(nonGWRoute1, prevNextHop)
331-
verifyNoLogicalRouterPolicies(nonGWRoute2, prevNextHop)
332-
333-
By("Updating NextHop for second NonGatewayRoute")
280+
Expect(client.Delete(context.Background(), nonGWRoute.Name, metav1.DeleteOptions{})).To(Succeed())
334281

335-
nonGWRoute2.RoutePolicySpec.NextHops[0] = nextHop
336-
337-
test.UpdateResource(client, nonGWRoute2)
338-
339-
verifyLogicalRouterPolicies(nonGWRoute1, nextHop)
340-
verifyLogicalRouterPolicies(nonGWRoute2, nextHop)
341-
342-
By("Deleting first NonGatewayRoute")
343-
344-
Expect(client.Delete(context.Background(), nonGWRoute1.Name, metav1.DeleteOptions{})).To(Succeed())
345-
346-
verifyNoLogicalRouterPolicies(nonGWRoute1, nextHop)
282+
for _, cidr := range nonGWRoute.RoutePolicySpec.RemoteCIDRs {
283+
ovsdbClient.AwaitNoModel(&nbdb.LogicalRouterPolicy{
284+
Match: cidr,
285+
Nexthop: ptr.To(nonGWRoute.RoutePolicySpec.NextHops[0]),
286+
})
287+
}
347288
})
348289
})
349290

pkg/routeagent_driver/handlers/ovn/non_gateway_route_controller.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@ import (
2222
"github.com/pkg/errors"
2323
"github.com/submariner-io/admiral/pkg/watcher"
2424
submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
25+
nodeutil "github.com/submariner-io/submariner/pkg/node"
2526
"k8s.io/apimachinery/pkg/runtime"
2627
"k8s.io/apimachinery/pkg/util/sets"
28+
clientset "k8s.io/client-go/kubernetes"
2729
)
2830

2931
type NonGatewayRouteController struct {
3032
nonGatewayRouteWatcher watcher.Interface
3133
connectionHandler *ConnectionHandler
3234
remoteSubnets sets.Set[string]
3335
stopCh chan struct{}
34-
transitSwitchIP TransitSwitchIPGetter
36+
transitSwitchIP string
3537
}
3638

3739
//nolint:gocritic // Ignore hugeParam
3840
func NewNonGatewayRouteController(config watcher.Config, connectionHandler *ConnectionHandler,
39-
namespace string, transitSwitchIP TransitSwitchIPGetter,
41+
k8sClientSet clientset.Interface, namespace string,
4042
) (*NonGatewayRouteController, error) {
4143
// We'll panic if config is nil, this is intentional
4244
var err error
@@ -45,7 +47,6 @@ func NewNonGatewayRouteController(config watcher.Config, connectionHandler *Conn
4547
connectionHandler: connectionHandler,
4648
remoteSubnets: sets.New[string](),
4749
stopCh: make(chan struct{}),
48-
transitSwitchIP: transitSwitchIP,
4950
}
5051

5152
config.ResourceConfigs = []watcher.ResourceConfig{
@@ -61,6 +62,25 @@ func NewNonGatewayRouteController(config watcher.Config, connectionHandler *Conn
6162
},
6263
}
6364

65+
node, err := nodeutil.GetLocalNode(k8sClientSet)
66+
if err != nil {
67+
return nil, errors.Wrap(err, "error getting the local node info")
68+
}
69+
70+
annotations := node.GetAnnotations()
71+
72+
transitSwitchIP := annotations["k8s.ovn.org/node-transit-switch-port-ifaddr"]
73+
if transitSwitchIP == "" {
74+
// This is a non-IC setup , so this controller will not be started.
75+
logger.Infof("No transit switch IP configured on node %q", node.Name)
76+
return controller, nil
77+
}
78+
79+
controller.transitSwitchIP, err = jsonToIP(transitSwitchIP)
80+
if err != nil {
81+
return nil, errors.Wrapf(err, "error parsing transit switch IP")
82+
}
83+
6484
controller.nonGatewayRouteWatcher, err = watcher.New(&config)
6585
if err != nil {
6686
return nil, errors.Wrap(err, "error creating resource watcher")
@@ -109,7 +129,7 @@ func (g *NonGatewayRouteController) reconcileRemoteSubnets(submNonGWRoute *subma
109129
}
110130

111131
// If this node belongs to same zone as gateway node, ignore the event.
112-
if submNonGWRoute.RoutePolicySpec.NextHops[0] != g.transitSwitchIP.Get() {
132+
if submNonGWRoute.RoutePolicySpec.NextHops[0] != g.transitSwitchIP {
113133
for _, subnet := range submNonGWRoute.RoutePolicySpec.RemoteCIDRs {
114134
if addSubnet {
115135
g.remoteSubnets.Insert(subnet)
@@ -125,5 +145,7 @@ func (g *NonGatewayRouteController) reconcileRemoteSubnets(submNonGWRoute *subma
125145
}
126146

127147
func (g *NonGatewayRouteController) stop() {
128-
close(g.stopCh)
148+
if g.transitSwitchIP != "" {
149+
close(g.stopCh)
150+
}
129151
}

pkg/routeagent_driver/handlers/ovn/non_gateway_route_handler.go

+30-47
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,47 @@ import (
2828
submarinerClientset "github.com/submariner-io/submariner/pkg/client/clientset/versioned"
2929
"github.com/submariner-io/submariner/pkg/cni"
3030
"github.com/submariner-io/submariner/pkg/event"
31-
corev1 "k8s.io/api/core/v1"
31+
nodeutil "github.com/submariner-io/submariner/pkg/node"
32+
"github.com/submariner-io/submariner/pkg/routeagent_driver/constants"
3233
apierrors "k8s.io/apimachinery/pkg/api/errors"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34-
"k8s.io/client-go/kubernetes"
35+
clientset "k8s.io/client-go/kubernetes"
3536
)
3637

3738
type NonGatewayRouteHandler struct {
3839
event.HandlerBase
39-
event.NodeHandlerBase
4040
smClient submarinerClientset.Interface
41-
k8sClient kubernetes.Interface
42-
transitSwitchIP TransitSwitchIP
41+
k8sClient clientset.Interface
42+
transitSwitchIP string
4343
}
4444

45-
func NewNonGatewayRouteHandler(smClient submarinerClientset.Interface, k8sClient kubernetes.Interface, transitSwitchIP TransitSwitchIP,
46-
) *NonGatewayRouteHandler {
45+
func NewNonGatewayRouteHandler(smClient submarinerClientset.Interface, k8sClient clientset.Interface) *NonGatewayRouteHandler {
4746
return &NonGatewayRouteHandler{
48-
smClient: smClient,
49-
k8sClient: k8sClient,
50-
transitSwitchIP: transitSwitchIP,
47+
smClient: smClient,
48+
k8sClient: k8sClient,
5149
}
5250
}
5351

5452
func (h *NonGatewayRouteHandler) Init() error {
5553
logger.Info("Starting NonGatewayRouteHandler")
56-
return errors.Wrap(h.transitSwitchIP.Init(h.k8sClient), "error initializing TransitSwitchIP")
54+
55+
node, err := nodeutil.GetLocalNode(h.k8sClient)
56+
if err != nil {
57+
return errors.Wrap(err, "error getting the g/w node")
58+
}
59+
60+
annotations := node.GetAnnotations()
61+
62+
// TODO transitSwitchIP changes support needs to be added.
63+
transitSwitchIP, ok := annotations[constants.OvnTransitSwitchIPAnnotation]
64+
if !ok {
65+
logger.Infof("No transit switch IP configured")
66+
return nil
67+
}
68+
69+
h.transitSwitchIP, err = jsonToIP(transitSwitchIP)
70+
71+
return errors.Wrapf(err, "error parsing the transit switch IP")
5772
}
5873

5974
func (h *NonGatewayRouteHandler) GetName() string {
@@ -65,7 +80,7 @@ func (h *NonGatewayRouteHandler) GetNetworkPlugins() []string {
6580
}
6681

6782
func (h *NonGatewayRouteHandler) RemoteEndpointCreated(endpoint *submarinerv1.Endpoint) error {
68-
if !h.State().IsOnGateway() || h.transitSwitchIP.Get() == "" {
83+
if !h.State().IsOnGateway() || h.transitSwitchIP == "" {
6984
return nil
7085
}
7186

@@ -83,7 +98,7 @@ func (h *NonGatewayRouteHandler) RemoteEndpointCreated(endpoint *submarinerv1.En
8398
}
8499

85100
func (h *NonGatewayRouteHandler) RemoteEndpointRemoved(endpoint *submarinerv1.Endpoint) error {
86-
if !h.State().IsOnGateway() || h.transitSwitchIP.Get() == "" {
101+
if !h.State().IsOnGateway() || h.transitSwitchIP == "" {
87102
return nil
88103
}
89104

@@ -98,7 +113,7 @@ func (h *NonGatewayRouteHandler) RemoteEndpointRemoved(endpoint *submarinerv1.En
98113
}
99114

100115
func (h *NonGatewayRouteHandler) TransitionToGateway() error {
101-
if h.transitSwitchIP.Get() == "" {
116+
if h.transitSwitchIP == "" {
102117
return nil
103118
}
104119

@@ -126,38 +141,6 @@ func (h *NonGatewayRouteHandler) TransitionToGateway() error {
126141
return nil
127142
}
128143

129-
func (h *NonGatewayRouteHandler) NodeUpdated(node *corev1.Node) error {
130-
updated, err := h.transitSwitchIP.UpdateFrom(node)
131-
if err != nil {
132-
logger.Errorf(err, "Error updating transit switch IP from node: %s", resource.ToJSON(node))
133-
return nil
134-
}
135-
136-
if !updated {
137-
return nil
138-
}
139-
140-
logger.Infof("Transit switch IP updated to %s", h.transitSwitchIP.Get())
141-
142-
if !h.State().IsOnGateway() {
143-
return nil
144-
}
145-
146-
endpoints := h.State().GetRemoteEndpoints()
147-
for i := range endpoints {
148-
err = util.Update(context.TODO(), NonGatewayResourceInterface(h.smClient, endpoints[i].Namespace),
149-
h.newNonGatewayRoute(&endpoints[i]), func(existing *submarinerv1.NonGatewayRoute) (*submarinerv1.NonGatewayRoute, error) {
150-
existing.RoutePolicySpec.NextHops = []string{h.transitSwitchIP.Get()}
151-
return existing, nil
152-
})
153-
if err != nil {
154-
return errors.Wrapf(err, "error updating NonGatewayRoute")
155-
}
156-
}
157-
158-
return nil
159-
}
160-
161144
func (h *NonGatewayRouteHandler) newNonGatewayRoute(endpoint *submarinerv1.Endpoint) *submarinerv1.NonGatewayRoute {
162145
return &submarinerv1.NonGatewayRoute{
163146
ObjectMeta: metav1.ObjectMeta{
@@ -166,7 +149,7 @@ func (h *NonGatewayRouteHandler) newNonGatewayRoute(endpoint *submarinerv1.Endpo
166149
},
167150
RoutePolicySpec: submarinerv1.RoutePolicySpec{
168151
RemoteCIDRs: endpoint.Spec.Subnets,
169-
NextHops: []string{h.transitSwitchIP.Get()},
152+
NextHops: []string{h.transitSwitchIP},
170153
},
171154
}
172155
}

0 commit comments

Comments
 (0)