Skip to content

Commit

Permalink
fix: all gw nodes (#3723)
Browse files Browse the repository at this point in the history
* fix: all gw nodes

---------

Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 authored Feb 18, 2024
1 parent bffef86 commit ae895e2
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 54 deletions.
24 changes: 12 additions & 12 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/external_gw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -214,9 +213,10 @@ func (c *Controller) createDefaultVpcLrpEip() (string, string, error) {

func (c *Controller) getGatewayChassis(config map[string]string) ([]string, error) {
chassises := []string{}
nodes, err := c.nodesLister.List(labels.Everything())
sel, _ := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{MatchLabels: map[string]string{util.ExGatewayLabel: "true"}})
nodes, err := c.nodesLister.List(sel)
if err != nil {
klog.Errorf("failed to list nodes, %v", err)
klog.Errorf("failed to list external gw nodes, %v", err)
return nil, err
}
gwNodes := make([]string, 0, len(nodes))
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (c *Controller) InitIPAM() error {
}
}

// Append ExternalIds is added in v1.7, used for upgrading from v1.6.3. It should be deleted now since v1.7 is not used anymore.
// Append externalIDs is added in v1.7, used for upgrading from v1.6.3. It should be deleted now since v1.7 is not used anymore.
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ func (c *Controller) checkGatewayReady() error {

success := false

pinger.OnRecv = func(p *goping.Packet) {
pinger.OnRecv = func(_ *goping.Packet) {
success = true
pinger.Stop()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,14 @@ func (c *Controller) reconcilePortSg(portName, securityGroups string) error {
needAssociated = "true"
}

if err = c.OVNNbClient.SetLogicalSwitchPortExternalIds(portName, map[string]string{fmt.Sprintf("associated_sg_%s", sgName): needAssociated}); err != nil {
if err = c.OVNNbClient.SetLogicalSwitchPortExternalIDs(portName, map[string]string{fmt.Sprintf("associated_sg_%s", sgName): needAssociated}); err != nil {
klog.Errorf("set logical switch port %s external_ids: %v", portName, err)
return err
}
c.syncSgPortsQueue.Add(sgName)
}

if err = c.OVNNbClient.SetLogicalSwitchPortExternalIds(portName, map[string]string{"security_groups": strings.ReplaceAll(securityGroups, ",", "/")}); err != nil {
if err = c.OVNNbClient.SetLogicalSwitchPortExternalIDs(portName, map[string]string{"security_groups": strings.ReplaceAll(securityGroups, ",", "/")}); err != nil {
klog.Errorf("set logical switch port %s external_ids: %v", portName, err)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func pingGateway(gw, src string, verbose bool, maxRetry int) (count int, err err
pinger.Timeout = time.Duration(maxRetry) * time.Second
pinger.Interval = time.Second

pinger.OnRecv = func(p *goping.Packet) {
pinger.OnRecv = func(_ *goping.Packet) {
pinger.Stop()
}

pinger.OnSend = func(p *goping.Packet) {
pinger.OnSend = func(_ *goping.Packet) {
if pinger.PacketsRecv == 0 && pinger.PacketsSent != 0 && pinger.PacketsSent%3 == 0 {
klog.Warningf("%s network not ready after %d ping to gateway %s", src, pinger.PacketsSent, gw)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type LogicalSwitchPort interface {
SetLogicalSwitchPortSecurity(portSecurity bool, lspName, mac, ips, vips string) error
SetLogicalSwitchPortVirtualParents(lsName, parents string, ips ...string) error
SetLogicalSwitchPortArpProxy(lspName string, enableArpProxy bool) error
SetLogicalSwitchPortExternalIds(lspName string, externalIds map[string]string) error
SetLogicalSwitchPortExternalIDs(lspName string, externalIDs map[string]string) error
SetLogicalSwitchPortVlanTag(lspName string, vlanID int) error
SetLogicalSwitchPortsSecurityGroup(sgName, op string) error
EnablePortLayer2forward(lspName string) error
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/ovn-nb-acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (suite *OvnClientTestSuite) testCreateNodeACL() {
require.Contains(t, pg.ACLs, acl.UUID)
}

expect := func(pg *ovnnb.PortGroup, gateway string) {
expect := func(pg *ovnnb.PortGroup, _ string) {
for _, ip := range strings.Split(nodeIP, ",") {
protocol := util.CheckProtocol(ip)
ipSuffix := "ip4"
Expand Down
1 change: 0 additions & 1 deletion pkg/ovs/ovn-nb-load_balancer_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func (c *OVNNbClient) DeleteLoadBalancerHealthChecks(filter func(lb *ovnnb.LoadB
return true
},
).Delete()

if err != nil {
return fmt.Errorf("generate operations for delete lb health checks: %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/ovs/ovn-nb-logical_switch_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ func (c *OVNNbClient) SetLogicalSwitchPortSecurity(portSecurity bool, lspName, m
return nil
}

// SetLogicalSwitchPortExternalIds set logical switch port external ids
func (c *OVNNbClient) SetLogicalSwitchPortExternalIds(lspName string, externalIds map[string]string) error {
// SetLogicalSwitchPortExternalIDs set logical switch port external ids
func (c *OVNNbClient) SetLogicalSwitchPortExternalIDs(lspName string, externalIDs map[string]string) error {
lsp, err := c.GetLogicalSwitchPort(lspName, false)
if err != nil {
klog.Error(err)
Expand All @@ -336,12 +336,12 @@ func (c *OVNNbClient) SetLogicalSwitchPortExternalIds(lspName string, externalId
lsp.ExternalIDs = make(map[string]string)
}

for k, v := range externalIds {
for k, v := range externalIDs {
lsp.ExternalIDs[k] = v
}

if err := c.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs); err != nil {
return fmt.Errorf("set logical switch port %s external ids %v: %v", lspName, externalIds, err)
return fmt.Errorf("set logical switch port %s external ids %v: %v", lspName, externalIDs, err)
}

return nil
Expand Down Expand Up @@ -407,11 +407,11 @@ func (c *OVNNbClient) SetLogicalSwitchPortsSecurityGroup(sgName, op string) erro
associated = "true"
}

externalIds := map[string]string{associatedSgKey: associated}
lsps, err := c.ListNormalLogicalSwitchPorts(true, externalIds)
externalIDs := map[string]string{associatedSgKey: associated}
lsps, err := c.ListNormalLogicalSwitchPorts(true, externalIDs)
if err != nil {
klog.Error(err)
return fmt.Errorf("list logical switch ports with external_ids %v: %v", externalIds, err)
return fmt.Errorf("list logical switch ports with external_ids %v: %v", externalIDs, err)
}

/* add to or remove from sgs form port external_ids */
Expand Down
6 changes: 3 additions & 3 deletions pkg/ovs/ovn-nb-logical_switch_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurity() {
})
}

func (suite *OvnClientTestSuite) testSetSetLogicalSwitchPortExternalIds() {
func (suite *OvnClientTestSuite) testSetSetLogicalSwitchPortExternalIDs() {
t := suite.T()
t.Parallel()

Expand All @@ -473,7 +473,7 @@ func (suite *OvnClientTestSuite) testSetSetLogicalSwitchPortExternalIds() {
err := createLogicalSwitchPort(ovnClient, lsp)
require.NoError(t, err)

err = ovnClient.SetLogicalSwitchPortExternalIds(lspName, map[string]string{"k1": "v1"})
err = ovnClient.SetLogicalSwitchPortExternalIDs(lspName, map[string]string{"k1": "v1"})
require.NoError(t, err)

lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false)
Expand All @@ -483,7 +483,7 @@ func (suite *OvnClientTestSuite) testSetSetLogicalSwitchPortExternalIds() {
"vendor": util.CniTypeName,
}, lsp.ExternalIDs)

err = ovnClient.SetLogicalSwitchPortExternalIds(lspName, map[string]string{"k1": "v2"})
err = ovnClient.SetLogicalSwitchPortExternalIDs(lspName, map[string]string{"k1": "v2"})
require.NoError(t, err)

lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ovs/ovn-nb-suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (suite *OvnClientTestSuite) Test_SetLogicalSwitchPortSecurity() {
suite.testSetLogicalSwitchPortSecurity()
}

func (suite *OvnClientTestSuite) Test_SetSetLogicalSwitchPortExternalIds() {
suite.testSetSetLogicalSwitchPortExternalIds()
func (suite *OvnClientTestSuite) Test_SetSetLogicalSwitchPortExternalIDs() {
suite.testSetSetLogicalSwitchPortExternalIDs()
}

func (suite *OvnClientTestSuite) Test_SetLogicalSwitchPortSecurityGroup() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/ovn-nb_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *OVNNbClient) GetNbGlobal() (*ovnnb.NBGlobal, error) {
nbGlobalList := make([]ovnnb.NBGlobal, 0, 1)

// there is only one nb_global in OVN_Northbound, so return true and it will work
err := c.WhereCache(func(config *ovnnb.NBGlobal) bool {
err := c.WhereCache(func(_ *ovnnb.NBGlobal) bool {
return true
}).List(ctx, &nbGlobalList)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/ovs/ovs-vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ func ConfigInterfaceMirror(globalMirror bool, open, iface string) error {
if len(mirrorPorts) > 1 {
return fmt.Errorf("repeated mirror data, mirror name=" + util.MirrorDefaultName)
}
for _, mirrorPortIds := range mirrorPorts {
if strings.Contains(mirrorPortIds, portID) {
for _, mirrorPortIDs := range mirrorPorts {
if strings.Contains(mirrorPortIDs, portID) {
// remove port from mirror
_, err := Exec("remove", "mirror", util.MirrorDefaultName, "select_dst_port", portID)
if err != nil {
Expand Down Expand Up @@ -383,8 +383,8 @@ func GetResidualInternalPorts() []string {
}

// iface-id field does not exist in external_ids for residual internal port
externalIds := strings.Split(intf, "\n")[1]
if !strings.Contains(externalIds, "iface-id") {
externalIDs := strings.Split(intf, "\n")[1]
if !strings.Contains(externalIDs, "iface-id") {
residualPorts = append(residualPorts, name)
}
}
Expand All @@ -407,7 +407,7 @@ func ClearPortQosBinding(ifaceID string) error {
return nil
}

func ListExternalIds(table string) (map[string]string, error) {
func ListExternalIDs(table string) (map[string]string, error) {
args := []string{"--data=bare", "--format=csv", "--no-heading", "--columns=_uuid,external_ids", "find", table, "external_ids:iface-id!=[]"}
output, err := Exec(args...)
if err != nil {
Expand All @@ -425,8 +425,8 @@ func ListExternalIds(table string) (map[string]string, error) {
continue
}
uuid := strings.TrimSpace(parts[0])
externalIds := strings.Fields(parts[1])
for _, externalID := range externalIds {
externalIDs := strings.Fields(parts[1])
for _, externalID := range externalIDs {
if !strings.Contains(externalID, "iface-id=") {
continue
}
Expand All @@ -438,7 +438,7 @@ func ListExternalIds(table string) (map[string]string, error) {
return result, nil
}

func ListQosQueueIds() (map[string]string, error) {
func ListQosQueueIDs() (map[string]string, error) {
args := []string{"--data=bare", "--format=csv", "--no-heading", "--columns=_uuid,queues", "find", "qos", "queues:0!=[]"}
output, err := Exec(args...)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/ovs/ovs-vsctl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func SetInterfaceBandwidth(podName, podNamespace, iface, ingress, egress string)
return err
}

qosIfaceUIDMap, err := ListExternalIds("qos")
qosIfaceUIDMap, err := ListExternalIDs("qos")
if err != nil {
klog.Error(err)
return err
}

queueIfaceUIDMap, err := ListExternalIds("queue")
queueIfaceUIDMap, err := ListExternalIDs("queue")
if err != nil {
klog.Error(err)
return err
Expand Down Expand Up @@ -103,7 +103,7 @@ func ClearHtbQosQueue(podName, podNamespace, iface string) error {
}

// https://github.com/kubeovn/kube-ovn/issues/1191
qosQueueMap, err := ListQosQueueIds()
qosQueueMap, err := ListQosQueueIDs()
if err != nil {
klog.Error(err)
return err
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *EndpointsClient) Patch(original, modified *corev1.Endpoints) *corev1.En

var patchedEndpoints *corev1.Endpoints
err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
s, err := c.EndpointsInterface.Patch(context.TODO(), original.Name, types.MergePatchType, patch, metav1.PatchOptions{}, "")
s, err := c.EndpointsInterface.Patch(ctx, original.Name, types.MergePatchType, patch, metav1.PatchOptions{}, "")
if err != nil {
return handleWaitingAPIError(err, false, "patch endpoints %q", original.Name)
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *EndpointsClient) DeleteSync(name string) {
// WaitUntil waits the given timeout duration for the specified condition to be met.
func (c *EndpointsClient) WaitUntil(name string, cond func(s *corev1.Endpoints) (bool, error), condDesc string, _, timeout time.Duration) *corev1.Endpoints {
var endpoints *corev1.Endpoints
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(_ context.Context) (bool, error) {
Logf("Waiting for endpoints %s to meet condition %q", name, condDesc)
endpoints = c.Get(name).DeepCopy()
met, err := cond(endpoints)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/switch-lb-rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *SwitchLBRuleClient) Patch(original, modified *apiv1.SwitchLBRule) *apiv

var patchedService *apiv1.SwitchLBRule
err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
s, err := c.SwitchLBRuleInterface.Patch(context.TODO(), original.Name, types.MergePatchType, patch, metav1.PatchOptions{}, "")
s, err := c.SwitchLBRuleInterface.Patch(ctx, original.Name, types.MergePatchType, patch, metav1.PatchOptions{}, "")
if err != nil {
return handleWaitingAPIError(err, false, "patch switch-lb-rule %q", original.Name)
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *SwitchLBRuleClient) DeleteSync(name string) {
// WaitUntil waits the given timeout duration for the specified condition to be met.
func (c *SwitchLBRuleClient) WaitUntil(name string, cond func(s *apiv1.SwitchLBRule) (bool, error), condDesc string, _, timeout time.Duration) *apiv1.SwitchLBRule {
var rules *apiv1.SwitchLBRule
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(_ context.Context) (bool, error) {
Logf("Waiting for switch-lb-rule %s to meet condition %q", name, condDesc)
rules = c.Get(name).DeepCopy()
met, err := cond(rules)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/ha/ha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = framework.Describe("[group:ha]", func() {
deployClient.SetScale(deploy.Name, 0)

ginkgo.By("Waiting for ovn-central pods to disappear")
framework.WaitUntil(2*time.Second, 30*time.Second, func(ctx context.Context) (bool, error) {
framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
pods, err := deployClient.GetAllPods(deploy)
if err != nil {
return false, err
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/kube-ovn/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var _ = framework.Describe("[group:service]", func() {
protocol := strings.ToLower(util.CheckProtocol(nodeIP))
ginkgo.By("Checking " + protocol + " connection via node " + nodeName)
cmd := fmt.Sprintf("curl -q -s --connect-timeout 5 %s/clientip", util.JoinHostPort(nodeIP, nodePort))
framework.WaitUntil(2*time.Second, 30*time.Second, func(ctx context.Context) (bool, error) {
framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
ginkgo.By(fmt.Sprintf(`Executing %q in pod %s/%s`, cmd, namespaceName, hostPodName))
_, err := e2epodoutput.RunHostCmd(namespaceName, hostPodName, cmd)
return err == nil, nil
Expand Down

0 comments on commit ae895e2

Please sign in to comment.