Skip to content

Commit

Permalink
remove unused
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Aug 17, 2023
1 parent e105518 commit 9392ded
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 50 deletions.
16 changes: 8 additions & 8 deletions mocks/pkg/ovs/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func Run(ctx context.Context, config *Configuration) {
vpcs: &sync.Map{},
podSubnetMap: &sync.Map{},
deletingPodObjMap: &sync.Map{},
ovnLegacyClient: ovs.NewLegacyClient(config.OvnTimeout, config.OvnSbAddr, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.ClusterTcpSessionLoadBalancer, config.ClusterUdpSessionLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR),
ovnLegacyClient: ovs.NewLegacyClient(config.OvnTimeout),
ipam: ovnipam.NewIPAM(),
namedPort: NewNamedPort(),

Expand Down Expand Up @@ -488,10 +488,10 @@ func Run(ctx context.Context, config *Configuration) {
}

var err error
if controller.ovnNbClient, err = ovs.NewOvnNbClient(config.OvnNbAddr, config.OvnTimeout, config.NodeSwitchCIDR); err != nil {
if controller.ovnNbClient, err = ovs.NewOvnNbClient(config.OvnNbAddr, config.OvnTimeout); err != nil {
util.LogFatalAndExit(err, "failed to create ovn nb client")
}
if controller.ovnSbClient, err = ovs.NewOvnSbClient(config.OvnSbAddr, config.OvnTimeout, config.NodeSwitchCIDR); err != nil {
if controller.ovnSbClient, err = ovs.NewOvnSbClient(config.OvnSbAddr, config.OvnTimeout); err != nil {
util.LogFatalAndExit(err, "failed to create ovn sb client")
}
if config.EnableLb {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}

if subnet.Spec.Private {
if err := c.ovnNbClient.SetLogicalSwitchPrivate(subnet.Name, subnet.Spec.CIDRBlock, subnet.Spec.AllowSubnets); err != nil {
if err := c.ovnNbClient.SetLogicalSwitchPrivate(subnet.Name, subnet.Spec.CIDRBlock, c.config.NodeSwitchCIDR, subnet.Spec.AllowSubnets); err != nil {
c.patchSubnetStatus(subnet, "SetPrivateLogicalSwitchFailed", err.Error())
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type ACL interface {
UpdateSgAcl(sg *kubeovnv1.SecurityGroup, direction string) error
UpdateLogicalSwitchAcl(lsName string, subnetAcls []kubeovnv1.Acl) error
SetAclLog(pgName, protocol string, logEnable, isIngress bool) error
SetLogicalSwitchPrivate(lsName, cidrBlock string, allowSubnets []string) error
SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCIDR string, allowSubnets []string) error
DeleteAcls(parentName, parentType string, direction string, externalIDs map[string]string) error
DeleteAclsOps(parentName, parentType string, direction string, externalIDs map[string]string) ([]ovsdb.Operation, error)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ovs/ovn-nb-acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (c *ovnNbClient) UpdateAcl(acl *ovnnb.ACL, fields ...interface{}) error {
}

// SetLogicalSwitchPrivate will drop all ingress traffic except allow subnets, same subnet and node subnet
func (c *ovnNbClient) SetLogicalSwitchPrivate(lsName, cidrBlock string, allowSubnets []string) error {
func (c *ovnNbClient) SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCIDR string, allowSubnets []string) error {
// clear acls
if err := c.DeleteAcls(lsName, logicalSwitchKey, "", nil); err != nil {
return fmt.Errorf("clear logical switch %s acls: %v", lsName, err)
Expand All @@ -476,7 +476,7 @@ func (c *ovnNbClient) SetLogicalSwitchPrivate(lsName, cidrBlock string, allowSub
acls = append(acls, defaultDropAcl)

nodeSubnetAclFunc := func(protocol, ipSuffix string) error {
for _, nodeCidr := range strings.Split(c.NodeSwitchCIDR, ",") {
for _, nodeCidr := range strings.Split(nodeSwitchCIDR, ",") {
// skip different address family
if protocol != util.CheckProtocol(nodeCidr) {
continue
Expand Down
9 changes: 5 additions & 4 deletions pkg/ovs/ovn-nb-acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() {

ovnClient := suite.ovnClient

nodeSwitchCidrBlock := "100.64.0.0/16,fd00:100:64::/112"
cidrBlock := "10.244.0.0/16,fc00::af4:0/112"
allowSubnets := []string{
"10.230.0.0/16",
Expand All @@ -757,7 +758,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() {
err := ovnClient.CreateBareLogicalSwitch(lsName)
require.NoError(t, err)

err = ovnClient.SetLogicalSwitchPrivate(lsName, cidrBlock, allowSubnets)
err = ovnClient.SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCidrBlock, allowSubnets)
require.NoError(t, err)

ls, err := ovnClient.GetLogicalSwitch(lsName, false)
Expand Down Expand Up @@ -804,7 +805,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() {
}

// node subnet acl
for _, cidr := range strings.Split(ovnClient.NodeSwitchCIDR, ",") {
for _, cidr := range strings.Split(nodeSwitchCidrBlock, ",") {
protocol := util.CheckProtocol(cidr)

match := fmt.Sprintf(`ip4.src == %s`, cidr)
Expand All @@ -826,7 +827,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() {
require.NoError(t, err)

cidrBlock := "10.244.0.0/16"
err = ovnClient.SetLogicalSwitchPrivate(lsName, cidrBlock, allowSubnets)
err = ovnClient.SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCidrBlock, allowSubnets)
require.NoError(t, err)

ls, err := ovnClient.GetLogicalSwitch(lsName, false)
Expand Down Expand Up @@ -873,7 +874,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() {
}

// node subnet acl
for _, cidr := range strings.Split(ovnClient.NodeSwitchCIDR, ",") {
for _, cidr := range strings.Split(nodeSwitchCidrBlock, ",") {
protocol := util.CheckProtocol(cidr)

match := fmt.Sprintf(`ip4.src == %s`, cidr)
Expand Down
7 changes: 3 additions & 4 deletions pkg/ovs/ovn-nb-suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *OvnClientTestSuite) SetupSuite() {
endpoint := fmt.Sprintf("unix:%s", sock)
require.FileExists(suite.T(), sock)

ovnClient, err := newOvnNbClient(suite.T(), endpoint, 10, "100.64.0.0/16,fd00:100:64::/64")
ovnClient, err := newOvnNbClient(suite.T(), endpoint, 10)
require.NoError(suite.T(), err)

suite.ovnClient = ovnClient
Expand Down Expand Up @@ -649,7 +649,7 @@ func (suite *OvnClientTestSuite) Test_GetEntityInfo() {
func Test_scratch(t *testing.T) {
t.SkipNow()
endpoint := "tcp:[172.20.149.35]:6641"
ovnClient, err := newOvnNbClient(t, endpoint, 10, "")
ovnClient, err := newOvnNbClient(t, endpoint, 10)
require.NoError(t, err)

err = ovnClient.DeleteAcls("test_pg", portGroupKey, ovnnb.ACLDirectionToLport, nil)
Expand Down Expand Up @@ -692,7 +692,7 @@ func newOVSDBServer(t *testing.T, dbModel model.ClientDBModel, schema ovsdb.Data
return server, tmpfile
}

func newOvnNbClient(t *testing.T, ovnNbAddr string, ovnNbTimeout int, nodeSwitchCIDR string) (*ovnNbClient, error) {
func newOvnNbClient(t *testing.T, ovnNbAddr string, ovnNbTimeout int) (*ovnNbClient, error) {
nbClient, err := newNbClient(ovnNbAddr, ovnNbTimeout)
require.NoError(t, err)

Expand All @@ -701,7 +701,6 @@ func newOvnNbClient(t *testing.T, ovnNbAddr string, ovnNbTimeout int, nodeSwitch
Client: nbClient,
Timeout: time.Duration(ovnNbTimeout) * time.Second,
},
NodeSwitchCIDR: nodeSwitchCIDR,
}, nil
}

Expand Down
31 changes: 7 additions & 24 deletions pkg/ovs/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@ import (

// LegacyClient is the legacy ovn client
type LegacyClient struct {
OvnTimeout int
OvnICNbAddress string
OvnICSbAddress string
ClusterRouter string
ClusterTcpLoadBalancer string
ClusterUdpLoadBalancer string
ClusterTcpSessionLoadBalancer string
ClusterUdpSessionLoadBalancer string
NodeSwitch string
NodeSwitchCIDR string
Version string
OvnTimeout int
OvnICNbAddress string
OvnICSbAddress string
}

type ovnNbClient struct {
ovsDbClient
ClusterRouter string
NodeSwitchCIDR string
ClusterRouter string
}

type ovnSbClient struct {
Expand All @@ -56,16 +47,9 @@ const (
)

// NewLegacyClient init a legacy ovn client
func NewLegacyClient(timeout int, ovnSbAddr, clusterRouter, clusterTcpLoadBalancer, clusterUdpLoadBalancer, clusterTcpSessionLoadBalancer, clusterUdpSessionLoadBalancer, nodeSwitch, nodeSwitchCIDR string) *LegacyClient {
func NewLegacyClient(timeout int) *LegacyClient {
return &LegacyClient{
OvnTimeout: timeout,
ClusterRouter: clusterRouter,
ClusterTcpLoadBalancer: clusterTcpLoadBalancer,
ClusterUdpLoadBalancer: clusterUdpLoadBalancer,
ClusterTcpSessionLoadBalancer: clusterTcpSessionLoadBalancer,
ClusterUdpSessionLoadBalancer: clusterUdpSessionLoadBalancer,
NodeSwitch: nodeSwitch,
NodeSwitchCIDR: nodeSwitchCIDR,
OvnTimeout: timeout,
}
}

Expand Down Expand Up @@ -104,12 +88,11 @@ func NewOvnNbClient(ovnNbAddr string, ovnNbTimeout int) (*ovnNbClient, error) {
Client: nbClient,
Timeout: time.Duration(ovnNbTimeout) * time.Second,
},
NodeSwitchCIDR: nodeSwitchCIDR,
}
return c, nil
}

func NewOvnSbClient(ovnSbAddr string, ovnSbTimeout int, nodeSwitchCIDR string) (*ovnSbClient, error) {
func NewOvnSbClient(ovnSbAddr string, ovnSbTimeout int) (*ovnSbClient, error) {
dbModel, err := ovnsb.FullDatabaseModel()
if err != nil {
klog.Error(err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/ovsdb/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func NewOvsDbClient(db, addr string, dbModel model.ClientDBModel, monitors []cli
}
options = append(options, client.WithEndpoint(ep))
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(len(endpoints)+1)*timeout)
defer cancel()
if ssl {
cert, err := tls.LoadX509KeyPair("/var/run/tls/cert", "/var/run/tls/key")
if err != nil {
Expand All @@ -81,12 +79,13 @@ func NewOvsDbClient(db, addr string, dbModel model.ClientDBModel, monitors []cli
}
options = append(options, client.WithTLSConfig(tlsConfig))
}

c, err := client.NewOVSDBClient(dbModel, options...)
if err != nil {
klog.Error(err)
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(len(endpoints)+1)*timeout)
defer cancel()
if err = c.Connect(ctx); err != nil {
klog.Errorf("failed to connect to OVN NB server %s: %v", addr, err)
return nil, err
Expand Down

0 comments on commit 9392ded

Please sign in to comment.