Skip to content

Commit

Permalink
Merge pull request ovn-kubernetes#2567 from astoycos/libovsdb-logical…
Browse files Browse the repository at this point in the history
…-switch-2

Libovsdb logical switch conversion
  • Loading branch information
trozet authored Oct 27, 2021
2 parents 6fcb12b + 81eefd5 commit 24d24d5
Show file tree
Hide file tree
Showing 21 changed files with 1,503 additions and 815 deletions.
2 changes: 1 addition & 1 deletion go-controller/hybrid-overlay/pkg/controller/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (m *MasterController) handleOverlayPort(node *kapi.Node, annotator kube.Ann
", stderr:%s: %v", node.Name, stderr, err)
}
for _, subnet := range subnets {
if err := util.UpdateNodeSwitchExcludeIPs(node.Name, subnet); err != nil {
if err := util.UpdateNodeSwitchExcludeIPs(m.nbClient, node.Name, subnet); err != nil {
return err
}
}
Expand Down
61 changes: 41 additions & 20 deletions go-controller/hybrid-overlay/pkg/controller/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,23 @@ var _ = Describe("Hybrid SDN Master Operations", func() {
Name: types.OVNClusterRouter,
Policies: []string{"reroute-policy-UUID"},
},
&nbdb.LogicalSwitchPort{
Name: types.HybridOverlayPrefix + nodeName,
UUID: types.HybridOverlayPrefix + nodeName + "-UUID",
},
}

// Pre-add the HO port until the ovn-nbctl lsp-add commands are converted to libovsdb
nodeSwitch := &nbdb.LogicalSwitch{
Name: nodeName,
UUID: nodeName + "-UUID",
Ports: []string{types.HybridOverlayPrefix + nodeName + "-UUID"},
}

initialExpectedDB := append(expectedDatabaseState, nodeSwitch)

dbSetup := libovsdbtest.TestSetup{
NBData: expectedDatabaseState,
NBData: initialExpectedDB,
}
libovsdbOvnNBClient, err := libovsdbtest.NewNBTestHarness(dbSetup, stopChan)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand All @@ -204,9 +218,19 @@ var _ = Describe("Hybrid SDN Master Operations", func() {
Expect(err).NotTo(HaveOccurred())

// #1 node add
addLinuxNodeCommands(fexec, nodeHOMAC, nodeName, nodeHOIP)
fexec.AddFakeCmdsNoOutputNoError([]string{
// Setting the mac on the lsp
"ovn-nbctl --timeout=15 -- " +
"--may-exist lsp-add node1 int-node1 -- " +
"lsp-set-addresses int-node1 " + nodeHOMAC,
})
// #2 comes because we set the ho dr gw mac annotation in #1
addLinuxNodeCommands(fexec, nodeHOMAC, nodeName, nodeHOIP)
fexec.AddFakeCmdsNoOutputNoError([]string{
// Setting the mac on the lsp
"ovn-nbctl --timeout=15 -- " +
"--may-exist lsp-add node1 int-node1 -- " +
"lsp-set-addresses int-node1 " + nodeHOMAC,
})

f.Start(stopChan)
wg.Add(1)
Expand All @@ -224,6 +248,10 @@ var _ = Describe("Hybrid SDN Master Operations", func() {
return updatedNode.Annotations, nil
}, 2).Should(HaveKeyWithValue(hotypes.HybridOverlayDRMAC, nodeHOMAC))

nodeSwitch.OtherConfig = map[string]string{"exclude_ips": "10.1.2.2"}

expectedDatabaseState = append(expectedDatabaseState, nodeSwitch)

Eventually(fexec.CalledMatchesExpected, 2).Should(BeTrue(), fexec.ErrorDesc)
Eventually(libovsdbOvnNBClient).Should(libovsdbtest.HaveDataIgnoringUUIDs(expectedDatabaseState))

Expand All @@ -240,6 +268,12 @@ var _ = Describe("Hybrid SDN Master Operations", func() {
&nbdb.LogicalRouter{
Name: types.OVNClusterRouter,
},
// This will be deleted once the nbctl commands for lsps are converted
&nbdb.LogicalSwitchPort{
Name: types.HybridOverlayPrefix + nodeName,
UUID: types.HybridOverlayPrefix + nodeName + "-uuid",
},
nodeSwitch,
}
Eventually(libovsdbOvnNBClient).Should(libovsdbtest.HaveDataIgnoringUUIDs(expectedDatabaseState))
return nil
Expand Down Expand Up @@ -381,6 +415,10 @@ var _ = Describe("Hybrid SDN Master Operations", func() {
Addresses: []string{nodeHOMAC, nodeHOIP},
DynamicAddresses: &dynAdd,
},
&nbdb.LogicalSwitch{
Name: nodeName,
UUID: nodeName + "-UUID",
},
}
dbSetup := libovsdbtest.TestSetup{
NBData: expectedDatabaseState,
Expand Down Expand Up @@ -443,20 +481,3 @@ var _ = Describe("Hybrid SDN Master Operations", func() {
Expect(err).NotTo(HaveOccurred())
})
})

func addLinuxNodeCommands(fexec *ovntest.FakeExec, nodeHOMAC, nodeName, nodeHOIP string) {
fexec.AddFakeCmdsNoOutputNoError([]string{
// Setting the mac on the lsp
"ovn-nbctl --timeout=15 -- " +
"--may-exist lsp-add node1 int-node1 -- " +
"lsp-set-addresses int-node1 " + nodeHOMAC,
})

fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovn-nbctl --timeout=15 lsp-list " + nodeName,
Output: "29df5ce5-2802-4ee5-891f-4fb27ca776e9 (" + types.K8sPrefix + nodeName + ")",
})
fexec.AddFakeCmdsNoOutputNoError([]string{
"ovn-nbctl --timeout=15 -- --if-exists set logical_switch " + nodeName + " other-config:exclude_ips=" + nodeHOIP,
})
}
10 changes: 3 additions & 7 deletions go-controller/pkg/libovsdb/libovsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,26 @@ import (
"io/ioutil"
"reflect"
"strings"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ovn-org/libovsdb/client"
"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/sbdb"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
"gopkg.in/fsnotify/fsnotify.v1"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
)

const (
OVSDBTimeout = 10 * time.Second
)

// newClient creates a new client object given the provided config
// the stopCh is required to ensure the goroutine for ssl cert
// update is not leaked
func newClient(cfg config.OvnAuthConfig, dbModel *model.ClientDBModel, stopCh <-chan struct{}) (client.Client, error) {
logger := klogr.New()
options := []client.Option{
client.WithReconnect(OVSDBTimeout, &backoff.ZeroBackOff{}),
client.WithReconnect(types.OVSDBTimeout, &backoff.ZeroBackOff{}),
client.WithLeaderOnly(true),
client.WithLogger(&logger),
}
Expand All @@ -56,7 +52,7 @@ func newClient(cfg config.OvnAuthConfig, dbModel *model.ClientDBModel, stopCh <-
return nil, err
}

ctx, cancel := context.WithTimeout(context.Background(), OVSDBTimeout)
ctx, cancel := context.WithTimeout(context.Background(), types.OVSDBTimeout)
defer cancel()
err = client.Connect(ctx)
if err != nil {
Expand Down
58 changes: 0 additions & 58 deletions go-controller/pkg/ovn/acl/acl.go

This file was deleted.

64 changes: 0 additions & 64 deletions go-controller/pkg/ovn/acl/acl_test.go

This file was deleted.

9 changes: 7 additions & 2 deletions go-controller/pkg/ovn/controller/services/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

libovsdbclient "github.com/ovn-org/libovsdb/client"
globalconfig "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/ovn/acl"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/ovn/libovsdbops"
ovnlb "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/ovn/loadbalancer"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"

Expand Down Expand Up @@ -115,7 +115,12 @@ func (r *repair) runBeforeSync() {

// Remove existing reject rules. They are not used anymore
// given the introduction of idling loadbalancers
err = acl.PurgeRejectRules(r.nbClient)
acls, err := libovsdbops.FindRejectACLs(r.nbClient)
if err != nil {
klog.Errorf("Error while finding rejct ACLs error: %v", err)
}

err = libovsdbops.RemoveACLsFromAllSwitches(r.nbClient, acls)
if err != nil {
klog.Errorf("Failed to purge existing reject rules: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ type Controller struct {
client clientset.Interface

// libovsdb northbound client interface
nbClient libovsdbclient.Client

nbClient libovsdbclient.Client
eventBroadcaster record.EventBroadcaster
eventRecorder record.EventRecorder

Expand Down
Loading

0 comments on commit 24d24d5

Please sign in to comment.