Skip to content

Commit fd5a1d1

Browse files
authored
Merge pull request #5370 from npinaeva/gateway-refactor
Gateway refactoring: preparation work for Layer2 with router
2 parents 356b274 + 6395072 commit fd5a1d1

31 files changed

+903
-818
lines changed

go-controller/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,17 @@ clean:
9393

9494
lint:
9595
ifeq ($(CONTAINER_RUNNABLE), 0)
96-
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME)
96+
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME) || { echo "lint failed! Try running 'make lint-fix'"; exit 1; }
9797
else
98-
echo "linter can only be run within a container since it needs a specific golangci-lint version"
98+
echo "linter can only be run within a container since it needs a specific golangci-lint version"; exit 1
99+
endif
100+
101+
lint-fix:
102+
ifeq ($(CONTAINER_RUNNABLE), 0)
103+
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME) fix || { echo "ERROR: lint fix failed! There is a bug that changes file ownership to root \
104+
when this happens. To fix it, simply run 'chown -R <user>:<group> *' from the repo root."; exit 1; }
105+
else
106+
echo "linter can only be run within a container since it needs a specific golangci-lint version"; exit 1
99107
endif
100108

101109
gofmt:

go-controller/hack/lint.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/usr/bin/env bash
2-
32
VERSION=v1.60.3
3+
extra_flags=""
44
if [ "$#" -ne 1 ]; then
5+
if [ "$#" -eq 2 ] && [ "$2" == "fix" ]; then
6+
extra_flags="--fix"
7+
else
58
echo "Expected command line argument - container runtime (docker/podman) got $# arguments: $@"
69
exit 1
10+
fi
711
fi
812

913
$1 run --security-opt label=disable --rm \
1014
-v ${HOME}/.cache/golangci-lint:/cache -e GOLANGCI_LINT_CACHE=/cache \
1115
-v $(pwd):/app -w /app -e GO111MODULE=on docker.io/golangci/golangci-lint:${VERSION} \
1216
golangci-lint run --verbose --print-resources-usage \
13-
--modules-download-mode=vendor --timeout=15m0s && \
14-
echo "lint OK!"
17+
--modules-download-mode=vendor --timeout=15m0s ${extra_flags} && \
18+
echo "lint OK!"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ops
2+
3+
// This is a list of options used for OVN operations.
4+
// Started with adding only some of them, feel free to continue extending this list.
5+
// Eventually we expect to have no string options in the code.
6+
const (
7+
// RequestedTnlKey can be used by LogicalSwitch, LogicalSwitchPort, LogicalRouter and LogicalRouterPort
8+
// for distributed switches/routers
9+
RequestedTnlKey = "requested-tnl-key"
10+
// RequestedChassis can be used by LogicalSwitchPort and LogicalRouterPort.
11+
// It specifies the chassis (by name or hostname) that is allowed to bind this port.
12+
RequestedChassis = "requested-chassis"
13+
// RouterPort can be used by LogicalSwitchPort to specify a connection to a logical router.
14+
RouterPort = "router-port"
15+
// GatewayMTU can be used by LogicalRouterPort to specify the MTU for the gateway port.
16+
// If set, logical flows will be added to router pipeline to check packet length.
17+
GatewayMTU = "gateway_mtu"
18+
)

go-controller/pkg/ovn/base_network_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func (bnc *BaseNetworkController) syncNodeClusterRouterPort(node *corev1.Node, h
425425
enableGatewayMTU := util.ParseNodeGatewayMTUSupport(node)
426426
if enableGatewayMTU {
427427
lrpOptions = map[string]string{
428-
"gateway_mtu": strconv.Itoa(config.Default.MTU),
428+
libovsdbops.GatewayMTU: strconv.Itoa(config.Default.MTU),
429429
}
430430
}
431431
logicalRouterPort := nbdb.LogicalRouterPort{
@@ -560,7 +560,7 @@ func (bnc *BaseNetworkController) createNodeLogicalSwitch(nodeName string, hostS
560560
Type: "router",
561561
Addresses: []string{"router"},
562562
Options: map[string]string{
563-
"router-port": types.RouterToSwitchPrefix + switchName,
563+
libovsdbops.RouterPort: types.RouterToSwitchPrefix + switchName,
564564
},
565565
}
566566
if bnc.IsDefault() {

go-controller/pkg/ovn/base_network_controller_pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ func (bnc *BaseNetworkController) addLogicalPortToNetwork(pod *corev1.Pod, nadNa
535535
// rescheduled.
536536

537537
if !config.Kubernetes.DisableRequestedChassis {
538-
lsp.Options["requested-chassis"] = pod.Spec.NodeName
538+
lsp.Options[libovsdbops.RequestedChassis] = pod.Spec.NodeName
539539
}
540540

541541
// let's calculate if this network controller's role for this pod

go-controller/pkg/ovn/egressgw.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -649,30 +649,27 @@ func deletePodSNATOps(nbClient libovsdbclient.Client, ops []ovsdb.Operation, gwR
649649
// addOrUpdatePodSNAT adds or updates per pod SNAT rules towards the nodeIP that are applied to the GR where the pod resides
650650
// used when disableSNATMultipleGWs=true
651651
func addOrUpdatePodSNAT(nbClient libovsdbclient.Client, gwRouterName string, extIPs, podIfAddrs []*net.IPNet) error {
652-
nats, err := buildPodSNAT(extIPs, podIfAddrs, "")
652+
ops, err := addOrUpdatePodSNATOps(nbClient, gwRouterName, extIPs, podIfAddrs, nil)
653653
if err != nil {
654654
return err
655655
}
656-
logicalRouter := nbdb.LogicalRouter{
657-
Name: gwRouterName,
658-
}
659-
if err := libovsdbops.CreateOrUpdateNATs(nbClient, &logicalRouter, nats...); err != nil {
660-
return fmt.Errorf("failed to update SNAT for pods of router %s: %v", logicalRouter.Name, err)
656+
if _, err = libovsdbops.TransactAndCheck(nbClient, ops); err != nil {
657+
return fmt.Errorf("failed to update SNAT for pods of router %s: %v", gwRouterName, err)
661658
}
662659
return nil
663660
}
664661

665662
// addOrUpdatePodSNATOps returns the operation that adds or updates per pod SNAT rules towards the nodeIP that are
666663
// applied to the GR where the pod resides
667664
// used when disableSNATMultipleGWs=true
668-
func addOrUpdatePodSNATOps(nbClient libovsdbclient.Client, gwRouterName string, extIPs, podIfAddrs []*net.IPNet, match string, ops []ovsdb.Operation) ([]ovsdb.Operation, error) {
669-
router := &nbdb.LogicalRouter{Name: gwRouterName}
670-
nats, err := buildPodSNAT(extIPs, podIfAddrs, match)
665+
func addOrUpdatePodSNATOps(nbClient libovsdbclient.Client, gwRouterName string, extIPs, podIfAddrs []*net.IPNet, ops []ovsdb.Operation) ([]ovsdb.Operation, error) {
666+
gwRouter := &nbdb.LogicalRouter{Name: gwRouterName}
667+
nats, err := buildPodSNAT(extIPs, podIfAddrs, "")
671668
if err != nil {
672669
return nil, err
673670
}
674-
if ops, err = libovsdbops.CreateOrUpdateNATsOps(nbClient, ops, router, nats...); err != nil {
675-
return nil, fmt.Errorf("failed to update SNAT for pods of router: %s, error: %v", gwRouterName, err)
671+
if ops, err = libovsdbops.CreateOrUpdateNATsOps(nbClient, ops, gwRouter, nats...); err != nil {
672+
return nil, fmt.Errorf("failed to create ops to update SNAT for pods of router: %s, error: %v", gwRouterName, err)
676673
}
677674
return ops, nil
678675
}

0 commit comments

Comments
 (0)