Skip to content

Commit

Permalink
check whether subnet exists before deleting vpc (kubeovn#4533)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored and zcq98 committed Sep 18, 2024
1 parent fdf0c90 commit 0413583
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@ func (c *Controller) handleDelVpc(vpc *kubeovnv1.Vpc) error {
klog.Infof("handle delete vpc %s", vpc.Name)

// should delete vpc subnets first
if len(vpc.Status.Subnets) != 0 {
err := fmt.Errorf("failed to delete vpc %s, still has subnets %v", vpc.Name, vpc.Status.Subnets)
var err error
for _, subnet := range vpc.Status.Subnets {
if _, err = c.subnetsLister.Get(subnet); err != nil {
if k8serrors.IsNotFound(err) {
continue
}
err = fmt.Errorf("failed to get subnet %s for vpc %s: %w", subnet, vpc.Name, err)
} else {
err = fmt.Errorf("failed to delete vpc %s, please delete subnet %s first", vpc.Name, subnet)
}
klog.Error(err)
return err
}
Expand Down

0 comments on commit 0413583

Please sign in to comment.