Skip to content

Commit d8fa839

Browse files
authored
controller: fix vpc update (#3117)
1 parent b5b25ff commit d8fa839

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

pkg/controller/subnet.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
12071207
klog.Errorf("failed to get subnet %s, %v", subnetName, err)
12081208
return err
12091209
}
1210-
vpc, err := c.vpcsLister.Get(vpcName)
1210+
cachedVpc, err := c.vpcsLister.Get(vpcName)
12111211
if err != nil {
12121212
if k8serrors.IsNotFound(err) {
12131213
return nil
@@ -1227,6 +1227,7 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
12271227
klog.Error(err)
12281228
return err
12291229
}
1230+
vpc := cachedVpc.DeepCopy()
12301231
for _, eip := range ovnEips {
12311232
if !eip.Status.Ready || eip.Status.V4Ip == "" {
12321233
err := fmt.Errorf("ovn eip %q not ready", eip.Name)
@@ -1266,7 +1267,7 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
12661267
}
12671268
}
12681269
if needUpdate {
1269-
if vpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
1270+
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
12701271
klog.Errorf("failed to update vpc spec static route %s, %v", vpc.Name, err)
12711272
return err
12721273
}
@@ -1298,9 +1299,9 @@ func (c *Controller) reconcileCustomVpcAddNormalStaticRoute(vpcName string) erro
12981299
klog.Errorf("failed to get vpc %s, %v", vpcName, err)
12991300
return err
13001301
}
1301-
vpc := cachedVpc.DeepCopy()
1302-
rtbs := c.getRouteTablesByVpc(vpc)
1303-
routeTotal := len(vpc.Spec.StaticRoutes) + len(rtbs)*2
1302+
1303+
rtbs := c.getRouteTablesByVpc(cachedVpc)
1304+
routeTotal := len(cachedVpc.Spec.StaticRoutes) + len(rtbs)*2
13041305
routes := make([]*kubeovnv1.StaticRoute, 0, routeTotal)
13051306
v4Exist, v6Exist := false, false
13061307
for _, staticRoutes := range rtbs {
@@ -1348,8 +1349,9 @@ func (c *Controller) reconcileCustomVpcAddNormalStaticRoute(vpcName string) erro
13481349
}
13491350

13501351
if needUpdate {
1352+
vpc := cachedVpc.DeepCopy()
13511353
vpc.Spec.StaticRoutes = routes
1352-
if vpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
1354+
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
13531355
klog.Errorf("failed to update vpc spec static route %s, %v", vpc.Name, err)
13541356
return err
13551357
}

pkg/controller/vpc.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
278278
}
279279
rtbs := c.getRouteTablesByVpc(vpc)
280280
targetRoutes := vpc.Spec.StaticRoutes
281-
klog.Infof("vpc %s spec static routes: %v, exist route:", key, targetRoutes, existRoute)
282281
if vpc.Name == c.config.ClusterRouter {
283282
if _, ok := rtbs[util.MainRouteTable]; !ok {
284283
rtbs[util.MainRouteTable] = nil
@@ -966,17 +965,18 @@ func (c *Controller) patchVpcBfdStatus(key string) error {
966965
klog.Error("failed to get vpc %s, %v", key, err)
967966
return err
968967
}
969-
vpc := cachedVpc.DeepCopy()
970-
if vpc.Status.EnableBfd != vpc.Spec.EnableBfd {
971-
vpc.Status.EnableExternal = cachedVpc.Spec.EnableExternal
972-
vpc.Status.EnableBfd = cachedVpc.Spec.EnableBfd
973-
bytes, err := vpc.Status.Bytes()
968+
969+
if cachedVpc.Status.EnableBfd != cachedVpc.Spec.EnableBfd {
970+
status := cachedVpc.Status.DeepCopy()
971+
status.EnableExternal = cachedVpc.Spec.EnableExternal
972+
status.EnableBfd = cachedVpc.Spec.EnableBfd
973+
bytes, err := status.Bytes()
974974
if err != nil {
975975
klog.Errorf("failed to marshal vpc status: %v", err)
976976
return err
977977
}
978978
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(),
979-
vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status"); err != nil {
979+
cachedVpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status"); err != nil {
980980
klog.Error(err)
981981
return err
982982
}

pkg/ovs/ovn-nb-logical_router_route.go

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func (c *ovnClient) AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPr
104104
klog.Error(err)
105105
return fmt.Errorf("failed to delete static routes from logical router %s: %v", lrName, err)
106106
}
107-
klog.Infof("logical router %s add static routes: %v", lrName, toAdd)
108107
if err = c.CreateLogicalRouterStaticRoutes(lrName, toAdd...); err != nil {
109108
return fmt.Errorf("failed to add static routes to logical router %s: %v", lrName, err)
110109
}

pkg/pinger/ovn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func checkSBBindings(config *Configuration) ([]string, error) {
125125
}
126126
output, err := exec.Command("ovn-sbctl", command...).CombinedOutput()
127127
if err != nil {
128-
klog.Errorf("failed to find chassis %v", err)
128+
klog.Errorf("failed to find chassis: %v, %s", err, string(output))
129129
return nil, err
130130
}
131131
if len(output) == 0 {

0 commit comments

Comments
 (0)