Skip to content
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

controller: fix vpc update #3117

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
klog.Errorf("failed to get subnet %s, %v", subnetName, err)
return err
}
vpc, err := c.vpcsLister.Get(vpcName)
cachedVpc, err := c.vpcsLister.Get(vpcName)
if err != nil {
if k8serrors.IsNotFound(err) {
return nil
Expand All @@ -1227,6 +1227,7 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
klog.Error(err)
return err
}
vpc := cachedVpc.DeepCopy()
for _, eip := range ovnEips {
if !eip.Status.Ready || eip.Status.V4Ip == "" {
err := fmt.Errorf("ovn eip %q not ready", eip.Name)
Expand Down Expand Up @@ -1266,7 +1267,7 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
}
}
if needUpdate {
if vpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
klog.Errorf("failed to update vpc spec static route %s, %v", vpc.Name, err)
return err
}
Expand Down Expand Up @@ -1298,9 +1299,9 @@ func (c *Controller) reconcileCustomVpcAddNormalStaticRoute(vpcName string) erro
klog.Errorf("failed to get vpc %s, %v", vpcName, err)
return err
}
vpc := cachedVpc.DeepCopy()
rtbs := c.getRouteTablesByVpc(vpc)
routeTotal := len(vpc.Spec.StaticRoutes) + len(rtbs)*2

rtbs := c.getRouteTablesByVpc(cachedVpc)
routeTotal := len(cachedVpc.Spec.StaticRoutes) + len(rtbs)*2
routes := make([]*kubeovnv1.StaticRoute, 0, routeTotal)
v4Exist, v6Exist := false, false
for _, staticRoutes := range rtbs {
Expand Down Expand Up @@ -1348,8 +1349,9 @@ func (c *Controller) reconcileCustomVpcAddNormalStaticRoute(vpcName string) erro
}

if needUpdate {
vpc := cachedVpc.DeepCopy()
vpc.Spec.StaticRoutes = routes
if vpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
klog.Errorf("failed to update vpc spec static route %s, %v", vpc.Name, err)
return err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
}
rtbs := c.getRouteTablesByVpc(vpc)
targetRoutes := vpc.Spec.StaticRoutes
klog.Infof("vpc %s spec static routes: %v, exist route:", key, targetRoutes, existRoute)
if vpc.Name == c.config.ClusterRouter {
if _, ok := rtbs[util.MainRouteTable]; !ok {
rtbs[util.MainRouteTable] = nil
Expand Down Expand Up @@ -966,17 +965,18 @@ func (c *Controller) patchVpcBfdStatus(key string) error {
klog.Error("failed to get vpc %s, %v", key, err)
return err
}
vpc := cachedVpc.DeepCopy()
if vpc.Status.EnableBfd != vpc.Spec.EnableBfd {
vpc.Status.EnableExternal = cachedVpc.Spec.EnableExternal
vpc.Status.EnableBfd = cachedVpc.Spec.EnableBfd
bytes, err := vpc.Status.Bytes()

if cachedVpc.Status.EnableBfd != cachedVpc.Spec.EnableBfd {
status := cachedVpc.Status.DeepCopy()
status.EnableExternal = cachedVpc.Spec.EnableExternal
status.EnableBfd = cachedVpc.Spec.EnableBfd
bytes, err := status.Bytes()
if err != nil {
klog.Errorf("failed to marshal vpc status: %v", err)
return err
}
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(),
vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status"); err != nil {
cachedVpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status"); err != nil {
klog.Error(err)
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/ovs/ovn-nb-logical_router_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (c *ovnClient) AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPr
klog.Error(err)
return fmt.Errorf("failed to delete static routes from logical router %s: %v", lrName, err)
}
klog.Infof("logical router %s add static routes: %v", lrName, toAdd)
if err = c.CreateLogicalRouterStaticRoutes(lrName, toAdd...); err != nil {
return fmt.Errorf("failed to add static routes to logical router %s: %v", lrName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pinger/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func checkSBBindings(config *Configuration) ([]string, error) {
}
output, err := exec.Command("ovn-sbctl", command...).CombinedOutput()
if err != nil {
klog.Errorf("failed to find chassis %v", err)
klog.Errorf("failed to find chassis: %v, %s", err, string(output))
return nil, err
}
if len(output) == 0 {
Expand Down