Skip to content

Commit

Permalink
Merge pull request #4560 from trozet/fix_anno_update
Browse files Browse the repository at this point in the history
Make annotation in pod sync only happen for local pods
  • Loading branch information
tssurya authored Jul 25, 2024
2 parents 1cd905b + c53542d commit e4f63cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
2 changes: 2 additions & 0 deletions go-controller/pkg/node/node_ip_handler_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ var _ = Describe("Node IP Handler tests", func() {
Output: dummyBrInternalIPv4,
})
Expect(util.SetExec(fexec)).ShouldNot(HaveOccurred())
// Restore global default values before each testcase
Expect(config.PrepareTestConfig()).To(Succeed())
config.IPv4Mode = true
config.IPv6Mode = true
tc = configureKubeOVNContextWithNs(nodeName)
Expand Down
57 changes: 30 additions & 27 deletions go-controller/pkg/ovn/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,41 @@ func (oc *DefaultNetworkController) syncPods(pods []interface{}) error {
expectedLogicalPorts[expectedLogicalPortName] = true
}

// delete the outdated hybrid overlay subnet route if it exists
newRoutes := []util.PodRoute{}
// HO is IPv4 only
ipv4Subnets := util.MatchAllIPNetFamily(false, oc.lsManager.GetSwitchSubnets(pod.Spec.NodeName))
for _, route := range annotations.Routes {
if !util.IsNodeHybridOverlayIfAddr(route.NextHop, ipv4Subnets) {
newRoutes = append(newRoutes, route)
// only update annotations for pods belonging to my zone
if oc.isPodScheduledinLocalZone(pod) {
// delete the outdated hybrid overlay subnet route if it exists
newRoutes := []util.PodRoute{}
// HO is IPv4 only
ipv4Subnets := util.MatchAllIPNetFamily(false, oc.lsManager.GetSwitchSubnets(pod.Spec.NodeName))
for _, route := range annotations.Routes {
if !util.IsNodeHybridOverlayIfAddr(route.NextHop, ipv4Subnets) {
newRoutes = append(newRoutes, route)
}
}
}

syncPodAnnotations := false
syncPodAnnotations := false

// checking the length because cannot compare the slices directly and if routes are removed
// the length will be different
if len(annotations.Routes) != len(newRoutes) {
annotations.Routes = newRoutes
syncPodAnnotations = true
}
// the ovn pod annotation role field is mandatory for default pod network, update old pods
// it it's missing
if util.IsNetworkSegmentationSupportEnabled() {
if annotations.Role == "" {
// Hardcode directly to primary since we don't support primary role networks at namespaces with
// pods in it, do not make sense to call GetNetworkRole here.
annotations.Role = types.NetworkRolePrimary
// checking the length because cannot compare the slices directly and if routes are removed
// the length will be different
if len(annotations.Routes) != len(newRoutes) {
annotations.Routes = newRoutes
syncPodAnnotations = true
}
}
if syncPodAnnotations {
err = oc.updatePodAnnotationWithRetry(pod, annotations, ovntypes.DefaultNetworkName)
if err != nil {
return fmt.Errorf("failed to set annotation on pod %s: %v", pod.Name, err)
// the ovn pod annotation role field is mandatory for default pod network, update old pods
// it it's missing
if util.IsNetworkSegmentationSupportEnabled() {
if annotations.Role == "" {
// Hardcode directly to primary since we don't support primary role networks at namespaces with
// pods in it, do not make sense to call GetNetworkRole here.
annotations.Role = types.NetworkRolePrimary
syncPodAnnotations = true
}
}
if syncPodAnnotations {
err = oc.updatePodAnnotationWithRetry(pod, annotations, ovntypes.DefaultNetworkName)
if err != nil {
return fmt.Errorf("failed to set annotation on pod %s: %v", pod.Name, err)
}
}
}
}
Expand Down

0 comments on commit e4f63cc

Please sign in to comment.