Closed SkalaNetworks closed 1 month ago
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 pkg/webhook/subnet.go
shows that there is a validation check in place to prevent VPCs and Subnets from having the same name.
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 pkg/controller/subnet.go
file contains logic to handle various aspects of subnet creation and updates, including validation and formatting. For example, the validateVpcBySubnet
function ensures that the VPC associated with a subnet is in a valid state and does not have overlapping namespaces with other VPCs. This further emphasizes the importance of maintaining unique and non-conflicting names and configurations for VPCs and Subnets.
Here is a snippet from pkg/controller/subnet.go
:
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].
To continue talking to Dosu, mention @dosu.
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 VpcCreateHook
function, where it checks if any existing subnet has the same name as the VPC being created and returns an error if they do.
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].
To continue talking to Dosu, mention @dosu.
@bobz965 do you remember why we have this restriction?
VPC and subnets shouldn't have the same name
Maybe, LSP and LRP should have the same name when vpc and subnet has the same name. but LSP and LRP are both the Port resources?
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
kind: Subnet apiVersion: kubeovn.io/v1 metadata: name: net1 spec: vpc: test-vpc-1 cidrBlock: 10.0.1.0/24,fd00:10:10::/64 namespaces:
ns1
kind: Subnet apiVersion: kubeovn.io/v1 metadata: name: net2 spec: vpc: test-vpc-2 cidrBlock: 10.0.1.0/24 protocol: IPv4 namespaces:
apiVersion: v1 kind: Pod metadata: namespace: ns1 name: vpc1-pod spec: containers:
name: vpc1-pod image: docker.io/library/nginx:alpine
apiVersion: v1 kind: Pod metadata: namespace: ns2 name: vpc2-pod spec: containers:
kube-ovn-controller E0917 03:57:46.434360 7 ovn.go:216] error occurred in transact with operations [{Op:ins ert Table:Logical_Switch_Port Row:map[addresses:{GoSet:[router]} external_ids:{GoMap:map[ls:net2 vendor:kube-ovn] } name:net2-test-vpc-2 options:{GoMap:map[router-port:test-vpc-2-net2]} type:router] Rows:[] Columns:[] Mutations :[] Timeout: Where:[] Until: Durable: Comment: Lock: UUID: UUIDName:u0939685268} {Op:mutate T
able:Logical_Switch Row:map[] Rows:[] Columns:[] Mutations:[{Column:ports Mutator:insert Value:{GoSet:[{GoUUID:u0
939685268}]}}] Timeout: Where:[where column _uuid == {f438ac99-0318-4e97-ac71-4414fd0532c7}] Until: Durable:
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