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 committed Dec 14, 2022
1 parent 0ef78a1 commit 0c4a9f1
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 @@ -548,13 +548,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 @@ -566,7 +571,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 @@ -578,7 +583,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 0c4a9f1

Please sign in to comment.