-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Recreating VPC/Subnet after their deletion yields errors #4530
Comments
To resolve the database errors when recreating VPCs and Subnets with the same names after deletion in Kube-OVN v1.13.0 on Kubernetes v1.30.4+k0s, you need to ensure that VPCs and Subnets do not share the same name. The provided code snippet from Here is the relevant part of the code: vpcList := &ovnv1.VpcList{}
if err := v.cache.List(ctx, vpcList); err != nil {
return ctrlwebhook.Errored(http.StatusBadRequest, err)
}
for _, item := range vpcList.Items {
if item.Name == o.Name {
err := errors.New("vpc and subnet cannot have the same name")
return ctrlwebhook.Errored(http.StatusBadRequest, err)
}
} This code checks if any existing VPC has the same name as the Subnet being created and returns an error if it does. To resolve the issue, ensure that when you recreate VPCs and Subnets, they have unique names that do not conflict with each other. Additionally, the Here is a snippet from func (c *Controller) validateVpcBySubnet(subnet *kubeovnv1.Subnet) (*kubeovnv1.Vpc, error) {
vpc, err := c.vpcsLister.Get(subnet.Spec.Vpc)
if err != nil {
klog.Errorf("failed to get subnet's vpc '%s', %v", subnet.Spec.Vpc, err)
return vpc, err
}
if !vpc.Status.Standby {
err = fmt.Errorf("the vpc '%s' not standby yet", vpc.Name)
klog.Error(err)
return vpc, err
}
if !vpc.Status.Default {
for _, ns := range subnet.Spec.Namespaces {
if !slices.Contains(vpc.Spec.Namespaces, ns) {
err = fmt.Errorf("namespace '%s' is out of range to custom vpc '%s'", ns, vpc.Name)
klog.Error(err)
return vpc, err
}
}
} else {
vpcs, err := c.vpcsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list vpc, %v", err)
return vpc, err
}
for _, vpc := range vpcs {
if (subnet.Annotations[util.VpcLastName] == "" && subnet.Spec.Vpc != vpc.Name ||
subnet.Annotations[util.VpcLastName] != "" && subnet.Annotations[util.VpcLastName] != vpc.Name) &&
!vpc.Status.Default && util.IsStringsOverlap(vpc.Spec.Namespaces, subnet.Spec.Namespaces) {
err = fmt.Errorf("namespaces %v are overlap with vpc '%s'", subnet.Spec.Namespaces, vpc.Name)
klog.Error(err)
return vpc, err
}
}
}
return vpc, nil
} By ensuring unique names and validating configurations, you can avoid database errors when recreating VPCs and Subnets [1][2][3]. |
So apparently VPC and subnets shouldn't have the same name, this is a very weird requirement, is this warranted? |
Yes, it is warranted that VPCs and subnets should not have the same name in Kube-OVN. This is enforced in the for _, item := range subnetList.Items {
if item.Name == vpc.Name {
err := errors.New("vpc and subnet cannot have the same name")
return ctrlwebhook.Errored(http.StatusBadRequest, err)
}
} This requirement helps to avoid conflicts and ensures the integrity of the system [1]. |
@bobz965 do you remember why we have this restriction? |
Kube-OVN Version
v1.13.0
Kubernetes Version
v1.30.4+k0s
K0s
Operation-system/Kernel Version
"Debian GNU/Linux 12 (bookworm)"
6.1.0-18-amd64
Description
After deleting VPCs and their associated subnets, recreating them identically yields database errors.
Steps To Reproduce
Current Behavior
VPCs/Subnets fail to work with the same name after they've been deleted and recreated
Expected Behavior
Can recreate them just fine
The text was updated successfully, but these errors were encountered: