Skip to content

Commit

Permalink
Fix error log not printed nearby in ovs package (#4562)
Browse files Browse the repository at this point in the history
* Fix error log not printed nearby in ovs package


---------

Signed-off-by: dolibali <[email protected]>
Co-authored-by: dolibali <[email protected]>
  • Loading branch information
dolibali and dolibali committed Sep 29, 2024
1 parent 3d12fa7 commit e90a58a
Show file tree
Hide file tree
Showing 23 changed files with 180 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/ovs/ovn-ic-sbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (c LegacyClient) GetRouteUUIDsInOneAZ(uuid string) ([]string, error) {
func (c LegacyClient) GetPortBindingUUIDsInOneAZ(uuid string) ([]string, error) {
portBindings, err := c.FindUUIDWithAttrInTable("availability_zone", uuid, "Port_Binding")
if err != nil {
klog.Error(err)
return nil, fmt.Errorf("failed to get ovn-ic-sb Port_Binding with uuid %v: %w", uuid, err)
}
return portBindings, nil
Expand All @@ -109,6 +110,7 @@ func (c LegacyClient) GetPortBindingUUIDsInOneAZ(uuid string) ([]string, error)
func (c LegacyClient) DestroyGateways(uuids []string) error {
for _, uuid := range uuids {
if err := c.DestroyTableWithUUID(uuid, "gateway"); err != nil {
klog.Error(err)
return fmt.Errorf("failed to delete gateway %v: %w", uuid, err)
}
}
Expand All @@ -118,6 +120,7 @@ func (c LegacyClient) DestroyGateways(uuids []string) error {
func (c LegacyClient) DestroyRoutes(uuids []string) error {
for _, uuid := range uuids {
if err := c.DestroyTableWithUUID(uuid, "route"); err != nil {
klog.Error(err)
return fmt.Errorf("failed to delete route %v: %w", uuid, err)
}
}
Expand All @@ -127,6 +130,7 @@ func (c LegacyClient) DestroyRoutes(uuids []string) error {
func (c LegacyClient) DestroyPortBindings(uuids []string) error {
for _, uuid := range uuids {
if err := c.DestroyTableWithUUID(uuid, "Port_Binding"); err != nil {
klog.Error(err)
return fmt.Errorf("failed to delete Port_Binding %v: %w", uuid, err)
}
}
Expand All @@ -135,6 +139,7 @@ func (c LegacyClient) DestroyPortBindings(uuids []string) error {

func (c LegacyClient) DestroyChassis(uuid string) error {
if err := c.DestroyTableWithUUID(uuid, "availability_zone"); err != nil {
klog.Error(err)
return fmt.Errorf("failed to delete chassis %v: %w", uuid, err)
}
return nil
Expand Down
23 changes: 21 additions & 2 deletions pkg/ovs/ovn-nb-acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (c *OVNNbClient) UpdateIngressACLOps(pgName, asIngressName, asExceptName, p

defaultDropACL, err := c.newACLWithoutCheck(pgName, ovnnb.ACLDirectionToLport, util.IngressDefaultDrop, allIPMatch.String(), ovnnb.ACLActionDrop, util.NetpolACLTier, options)
if err != nil {
klog.Error(err)
return nil, fmt.Errorf("new default drop ingress acl for port group %s: %w", pgName, err)
}

Expand All @@ -61,6 +62,7 @@ func (c *OVNNbClient) UpdateIngressACLOps(pgName, asIngressName, asExceptName, p

allowACL, err := c.newACLWithoutCheck(pgName, ovnnb.ACLDirectionToLport, util.IngressAllowPriority, m, ovnnb.ACLActionAllowRelated, util.NetpolACLTier, options)
if err != nil {
klog.Error(err)
return nil, fmt.Errorf("new allow ingress acl for port group %s: %w", pgName, err)
}

Expand All @@ -69,7 +71,8 @@ func (c *OVNNbClient) UpdateIngressACLOps(pgName, asIngressName, asExceptName, p

ops, err := c.CreateAclsOps(pgName, portGroupKey, acls...)
if err != nil {
return nil, err
klog.Error(err)
return nil, fmt.Errorf("failed to create ingress acl for port group %s: %w", pgName, err)
}

return ops, nil
Expand Down Expand Up @@ -197,6 +200,7 @@ func (c *OVNNbClient) CreateGatewayACL(lsName, pgName, gateway, u2oInterconnecti
}

if err := c.CreateAcls(parentName, parentType, acls...); err != nil {
klog.Error(err)
return fmt.Errorf("add gateway acls to %s: %w", pgName, err)
}

Expand Down Expand Up @@ -283,13 +287,16 @@ func (c *OVNNbClient) CreateSgDenyAllACL(sgName string) error {
return fmt.Errorf("new deny all egress acl for security group %s: %w", sgName, err)
}

if err := c.CreateAcls(pgName, portGroupKey, ingressACL, egressACL); err != nil {
err = c.CreateAcls(pgName, portGroupKey, ingressACL, egressACL)
if err != nil {
klog.Error(err)
return fmt.Errorf("add deny all acl to port group %s: %w", pgName, err)
}

return nil
}

// CreateSgACL create allow acl for security group
func (c *OVNNbClient) CreateSgBaseACL(sgName, direction string) error {
pgName := GetSgPortGroupName(sgName)

Expand Down Expand Up @@ -365,6 +372,7 @@ func (c *OVNNbClient) CreateSgBaseACL(sgName, direction string) error {
newACL(vrrpMatch.String())

if err := c.CreateAcls(pgName, portGroupKey, acls...); err != nil {
klog.Error(err)
return fmt.Errorf("add ingress acls to port group %s: %w", pgName, err)
}
return nil
Expand All @@ -375,6 +383,7 @@ func (c *OVNNbClient) UpdateSgACL(sg *kubeovnv1.SecurityGroup, direction string)

// clear acl
if err := c.DeleteAcls(pgName, portGroupKey, direction, nil); err != nil {
klog.Error(err)
return fmt.Errorf("delete direction '%s' acls from port group %s: %w", direction, pgName, err)
}

Expand Down Expand Up @@ -422,6 +431,7 @@ func (c *OVNNbClient) UpdateSgACL(sg *kubeovnv1.SecurityGroup, direction string)
}

if err := c.CreateAcls(pgName, portGroupKey, acls...); err != nil {
klog.Error(err)
return fmt.Errorf("add acl to port group %s: %w", pgName, err)
}

Expand All @@ -430,6 +440,7 @@ func (c *OVNNbClient) UpdateSgACL(sg *kubeovnv1.SecurityGroup, direction string)

func (c *OVNNbClient) UpdateLogicalSwitchACL(lsName, cidrBlock string, subnetAcls []kubeovnv1.ACL, allowEWTraffic bool) error {
if err := c.DeleteAcls(lsName, logicalSwitchKey, "", map[string]string{"subnet": lsName}); err != nil {
klog.Error(err)
return fmt.Errorf("delete subnet acls from %s: %w", lsName, err)
}

Expand Down Expand Up @@ -487,6 +498,7 @@ func (c *OVNNbClient) UpdateLogicalSwitchACL(lsName, cidrBlock string, subnetAcl
}

if err := c.CreateAcls(lsName, logicalSwitchKey, acls...); err != nil {
klog.Error(err)
return fmt.Errorf("add acls to logical switch %s: %w", lsName, err)
}

Expand All @@ -506,6 +518,7 @@ func (c *OVNNbClient) UpdateACL(acl *ovnnb.ACL, fields ...interface{}) error {
}

if err = c.Transact("acl-update", op); err != nil {
klog.Error(err)
return fmt.Errorf("update acl with 'direction %s priority %d match %s': %w", acl.Direction, acl.Priority, acl.Match, err)
}

Expand All @@ -516,6 +529,7 @@ func (c *OVNNbClient) UpdateACL(acl *ovnnb.ACL, fields ...interface{}) error {
func (c *OVNNbClient) SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCIDR string, allowSubnets []string) error {
// clear acls
if err := c.DeleteAcls(lsName, logicalSwitchKey, "", nil); err != nil {
klog.Error(err)
return fmt.Errorf("clear logical switch %s acls: %w", lsName, err)
}

Expand Down Expand Up @@ -705,6 +719,7 @@ func (c *OVNNbClient) CreateBareACL(parentName, direction, priority, match, acti
}

if err = c.Transact("acl-create", op); err != nil {
klog.Error(err)
return fmt.Errorf("create acl direction %s priority %s match %s action %s: %w", direction, priority, match, action, err)
}

Expand All @@ -722,6 +737,7 @@ func (c *OVNNbClient) DeleteAcls(parentName, parentType, direction string, exter
}

if err = c.Transact("acls-del", ops); err != nil {
klog.Error(err)
return fmt.Errorf("del acls from type %s %s: %w", parentType, parentName, err)
}

Expand Down Expand Up @@ -780,6 +796,7 @@ func (c *OVNNbClient) GetACL(parent, direction, priority, match string, ignoreNo
if err := c.ovsDbClient.WhereCache(func(acl *ovnnb.ACL) bool {
return len(acl.ExternalIDs) != 0 && acl.ExternalIDs[aclParentKey] == parent && acl.Direction == direction && acl.Priority == intPriority && acl.Match == match
}).List(ctx, &aclList); err != nil {
klog.Error(err)
return nil, fmt.Errorf("get acl with 'parent %s direction %s priority %s match %s': %w", parent, direction, priority, match, err)
}

Expand Down Expand Up @@ -1346,6 +1363,7 @@ func (c *OVNNbClient) UpdateAnpRuleACLOps(pgName, asName, protocol, aclName stri
strPriority := strconv.Itoa(priority)
setACL, err := c.newACLWithoutCheck(pgName, direction, strPriority, m, aclAction, tier, options)
if err != nil {
klog.Error(err)
return nil, fmt.Errorf("new ingress acl for port group %s: %w", pgName, err)
}

Expand All @@ -1354,6 +1372,7 @@ func (c *OVNNbClient) UpdateAnpRuleACLOps(pgName, asName, protocol, aclName stri

ops, err := c.CreateAclsOps(pgName, portGroupKey, acls...)
if err != nil {
klog.Error(err)
return nil, err
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/ovs/ovn-nb-address_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (c *OVNNbClient) CreateAddressSet(asName string, externalIDs map[string]str
}

if err = c.Transact("as-add", ops); err != nil {
klog.Error(err)
return fmt.Errorf("create address set %s: %w", asName, err)
}

Expand Down Expand Up @@ -78,6 +79,7 @@ func (c *OVNNbClient) AddressSetUpdateAddress(asName string, addresses ...string
as.Addresses = addresses

if err := c.UpdateAddressSet(as, &as.Addresses); err != nil {
klog.Error(err)
return fmt.Errorf("set address set %s addresses %v: %w", asName, addresses, err)
}

Expand Down Expand Up @@ -123,6 +125,7 @@ func (c *OVNNbClient) DeleteAddressSet(asName string) error {
}

if err := c.Transact("as-del", op); err != nil {
klog.Error(err)
return fmt.Errorf("delete address set %s: %w", asName, err)
}

Expand All @@ -143,6 +146,7 @@ func (c *OVNNbClient) DeleteAddressSets(externalIDs map[string]string) error {
}

if err := c.Transact("ass-del", op); err != nil {
klog.Error(err)
return fmt.Errorf("delete address sets with external IDs %v: %w", externalIDs, err)
}

Expand Down Expand Up @@ -179,6 +183,7 @@ func (c *OVNNbClient) ListAddressSets(externalIDs map[string]string) ([]ovnnb.Ad
asList := make([]ovnnb.AddressSet, 0)

if err := c.WhereCache(addressSetFilter(externalIDs)).List(ctx, &asList); err != nil {
klog.Error(err)
return nil, fmt.Errorf("list address set: %w", err)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/ovs/ovn-nb-dhcp_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (c *OVNNbClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet, mtu int) (*DHC
/* delete dhcp options */
if !enableDHCP {
if err := c.DeleteDHCPOptions(lsName, subnet.Spec.Protocol); err != nil {
klog.Error(err)
return nil, fmt.Errorf("delete dhcp options for logical switch %s: %w", lsName, err)
}
return &DHCPOptionsUUIDs{}, nil
Expand Down Expand Up @@ -136,6 +137,7 @@ func (c *OVNNbClient) updateDHCPv4Options(lsName, cidr, gateway, options string,

/* create */
if err := c.CreateDHCPOptions(lsName, cidr, options); err != nil {
klog.Error(err)
return "", fmt.Errorf("create dhcp options: %w", err)
}

Expand Down Expand Up @@ -189,6 +191,7 @@ func (c *OVNNbClient) updateDHCPv6Options(lsName, cidr, options string) (uuid st

/* create */
if err := c.CreateDHCPOptions(lsName, cidr, options); err != nil {
klog.Error(err)
return "", fmt.Errorf("create dhcp options: %w", err)
}

Expand All @@ -214,6 +217,7 @@ func (c *OVNNbClient) updateDHCPOptions(dhcpOpt *ovnnb.DHCPOptions, fields ...in
}

if err = c.Transact("dhcp-options-update", op); err != nil {
klog.Error(err)
return fmt.Errorf("update dhcp options %s: %w", dhcpOpt.UUID, err)
}

Expand All @@ -237,6 +241,7 @@ func (c *OVNNbClient) DeleteDHCPOptionsByUUIDs(uuidList ...string) error {
}

if err := c.Transact("dhcp-options-del", ops); err != nil {
klog.Error(err)
return fmt.Errorf("delete dhcp options %v: %w", uuidList, err)
}

Expand Down Expand Up @@ -311,6 +316,7 @@ func (c *OVNNbClient) ListDHCPOptions(needVendorFilter bool, externalIDs map[str
dhcpOptList := make([]ovnnb.DHCPOptions, 0)

if err := c.WhereCache(dhcpOptionsFilter(needVendorFilter, externalIDs)).List(ctx, &dhcpOptList); err != nil {
klog.Error(err)
return nil, fmt.Errorf("list dhcp options with external IDs %v: %w", externalIDs, err)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ovs/ovn-nb-gateway_chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (c *OVNNbClient) DeleteGatewayChassises(lrpName string, chassises []string)
}

if err := c.Transact("gateway-chassises-delete", ops); err != nil {
klog.Error(err)
return fmt.Errorf("delete gateway chassises %v from logical router port %s: %w", chassises, lrpName, err)
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/ovs/ovn-nb-load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ func (c *OVNNbClient) CreateLoadBalancer(lbName, protocol, selectFields string)
}

if ops, err = c.ovsDbClient.Create(lb); err != nil {
klog.Error(err)
return fmt.Errorf("generate operations for creating load balancer %s: %w", lbName, err)
}

if err = c.Transact("lb-add", ops); err != nil {
klog.Error(err)
return fmt.Errorf("create load balancer %s: %w", lbName, err)
}
return nil
Expand All @@ -66,10 +68,12 @@ func (c *OVNNbClient) UpdateLoadBalancer(lb *ovnnb.LoadBalancer, fields ...inter
)

if ops, err = c.ovsDbClient.Where(lb).Update(lb, fields...); err != nil {
klog.Error(err)
return fmt.Errorf("generate operations for updating load balancer %s: %w", lb.Name, err)
}

if err = c.Transact("lb-update", ops); err != nil {
klog.Error(err)
return fmt.Errorf("update load balancer %s: %w", lb.Name, err)
}
return nil
Expand Down Expand Up @@ -125,6 +129,7 @@ func (c *OVNNbClient) LoadBalancerAddVip(lbName, vip string, backends ...string)

if ops != nil {
if err = c.Transact("lb-add", ops); err != nil {
klog.Error(err)
return fmt.Errorf("failed to add vip %s with backends %v to load balancers %s: %w", vip, backends, lbName, err)
}
}
Expand Down Expand Up @@ -177,13 +182,15 @@ func (c *OVNNbClient) LoadBalancerDeleteVip(lbName, vipEndpoint string, ignoreHe
},
)
if err != nil {
klog.Error(err)
return fmt.Errorf("failed to generate operations when deleting vip %s from load balancers %s: %w", vipEndpoint, lbName, err)
}
if len(ops) == 0 {
return nil
}

if err = c.Transact("lb-add", ops); err != nil {
klog.Error(err)
return fmt.Errorf("failed to delete vip %s from load balancers %s: %w", vipEndpoint, lbName, err)
}
return nil
Expand Down Expand Up @@ -215,6 +222,7 @@ func (c *OVNNbClient) SetLoadBalancerAffinityTimeout(lbName string, timeout int)

lb.Options = options
if err = c.UpdateLoadBalancer(lb, &lb.Options); err != nil {
klog.Error(err)
return fmt.Errorf("failed to set affinity timeout of lb %s to %d: %w", lbName, timeout, err)
}
return nil
Expand All @@ -235,6 +243,7 @@ func (c *OVNNbClient) DeleteLoadBalancers(filter func(lb *ovnnb.LoadBalancer) bo
return true
},
).Delete(); err != nil {
klog.Error(err)
return fmt.Errorf("generate operations for delete load balancers: %w", err)
}

Expand Down Expand Up @@ -282,6 +291,7 @@ func (c *OVNNbClient) GetLoadBalancer(lbName string, ignoreNotFound bool) (*ovnn
return lb.Name == lbName
},
).List(ctx, &lbList); err != nil {
klog.Error(err)
return nil, fmt.Errorf("failed to list load balancer %q: %w", lbName, err)
}

Expand Down Expand Up @@ -325,6 +335,7 @@ func (c *OVNNbClient) ListLoadBalancers(filter func(lb *ovnnb.LoadBalancer) bool
return true
},
).List(ctx, &lbList); err != nil {
klog.Error(err)
return nil, fmt.Errorf("failed to list load balancer: %w", err)
}
return lbList, nil
Expand Down Expand Up @@ -411,10 +422,12 @@ func (c *OVNNbClient) LoadBalancerAddIPPortMapping(lbName, vipEndpoint string, m
}
},
); err != nil {
klog.Error(err)
return fmt.Errorf("failed to generate operations when adding ip port mapping with vip %v to load balancers %s: %w", vipEndpoint, lbName, err)
}

if err = c.Transact("lb-add", ops); err != nil {
klog.Error(err)
return fmt.Errorf("failed to add ip port mapping with vip %v to load balancers %s: %w", vipEndpoint, lbName, err)
}
return nil
Expand Down Expand Up @@ -470,6 +483,7 @@ func (c *OVNNbClient) LoadBalancerDeleteIPPortMapping(lbName, vipEndpoint string
}
},
); err != nil {
klog.Error(err)
return fmt.Errorf("failed to generate operations when deleting ip port mapping %s from load balancers %s: %w", vipEndpoint, lbName, err)
}
if len(ops) == 0 {
Expand Down
Loading

0 comments on commit e90a58a

Please sign in to comment.