Skip to content

Commit

Permalink
add process for delete networkpolicy start with number (#2157)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma authored Dec 13, 2022
1 parent 26f407f commit dbbbddc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/controller/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,18 @@ func (c *Controller) handleDeleteNp(key string) error {
utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", key))
return nil
}
npName := name
nameArray := []rune(name)
if !unicode.IsLetter(nameArray[0]) {
npName = "np" + name
}

pgName := strings.Replace(fmt.Sprintf("%s.%s", name, namespace), "-", ".", -1)
pgName := strings.Replace(fmt.Sprintf("%s.%s", npName, namespace), "-", ".", -1)
if err := c.ovnLegacyClient.DeletePortGroup(pgName); err != nil {
klog.Errorf("failed to delete np %s port group, %v", key, err)
}

svcAsNames, err := c.ovnLegacyClient.ListNpAddressSet(namespace, name, "service")
svcAsNames, err := c.ovnLegacyClient.ListNpAddressSet(namespace, npName, "service")
if err != nil {
klog.Errorf("failed to list svc address_set, %v", err)
return err
Expand All @@ -558,7 +563,7 @@ func (c *Controller) handleDeleteNp(key string) error {
}
}

ingressAsNames, err := c.ovnLegacyClient.ListNpAddressSet(namespace, name, "ingress")
ingressAsNames, err := c.ovnLegacyClient.ListNpAddressSet(namespace, npName, "ingress")
if err != nil {
klog.Errorf("failed to list address_set, %v", err)
return err
Expand All @@ -570,7 +575,7 @@ func (c *Controller) handleDeleteNp(key string) error {
}
}

egressAsNames, err := c.ovnLegacyClient.ListNpAddressSet(namespace, name, "egress")
egressAsNames, err := c.ovnLegacyClient.ListNpAddressSet(namespace, npName, "egress")
if err != nil {
klog.Errorf("failed to list address_set, %v", err)
return err
Expand Down

0 comments on commit dbbbddc

Please sign in to comment.