Skip to content

Commit

Permalink
Delete secondaryNetwork OVS ports correctly after an Agent restart
Browse files Browse the repository at this point in the history
Signed-off-by: KMAnju-2021 <[email protected]>
  • Loading branch information
KMAnju-2021 committed Jan 3, 2025
1 parent 3258908 commit 20ca6f4
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pkg/agent/secondarynetwork/podwatch/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ func (pc *PodController) syncPod(key string) error {
if err := pc.removeInterfaces(storedInterfaces); err != nil {
return err
}

} else {
return nil
}
}

Expand Down Expand Up @@ -488,6 +491,9 @@ func (pc *PodController) Run(stopCh <-chan struct{}) {
if !cache.WaitForNamedCacheSync(controllerName, stopCh, pc.podInformer.HasSynced) {
return
}
if err := pc.RestoreSecondaryNetwork(); err != nil {
klog.ErrorS(err, "Failed to restore the secondary bridge interface store")
}
for i := 0; i < numWorkers; i++ {
go wait.Until(pc.Worker, time.Second, stopCh)
}
Expand All @@ -502,3 +508,66 @@ func checkForPodSecondaryNetworkAttachement(pod *corev1.Pod) (string, bool) {
return netObj, false
}
}

// RestoreSecondaryNetwork restore interfacedstore and cniCache when agent restart.
func (pc *PodController) RestoreSecondaryNetwork() error {
err := pc.InitializeInterfaceStore()
if err != nil {
klog.ErrorS(err, "Failed to initialize the secondary bridge interface store")
return err
}

knownInterfaces := pc.interfaceStore.GetInterfacesByType(interfacestore.ContainerInterface)
for _, containerConfig := range knownInterfaces {
event := types.PodUpdate{
IsAdd: true,
PodName: containerConfig.ContainerInterfaceConfig.PodName,
PodNamespace: containerConfig.ContainerInterfaceConfig.PodNamespace,
ContainerID: containerConfig.ContainerInterfaceConfig.ContainerID,
}
pc.processCNIUpdate(event)
}

return nil
}

func (pc *PodController) InitializeInterfaceStore() error {
ovsPorts, err := pc.ovsBridgeClient.GetPortList()
if err != nil {
klog.ErrorS(err, "Failed to list OVS ports for the secondary bridge")
return err
}

ifaceList := make([]*interfacestore.InterfaceConfig, 0, len(ovsPorts))
for index := range ovsPorts {
port := &ovsPorts[index]
ovsPort := &interfacestore.OVSPortConfig{
PortUUID: port.UUID,
OFPort: port.OFPort,
}

interfaceType, ok := port.ExternalIDs[interfacestore.AntreaInterfaceTypeKey]
if !ok {
klog.InfoS("Interface type is not set for the secondary bridge", "interfaceName", port.Name)
continue
}

var intf *interfacestore.InterfaceConfig
switch interfaceType {
case interfacestore.AntreaContainer:
intf = cniserver.ParseOVSPortInterfaceConfig(port, ovsPort)
default:
klog.InfoS("Unknown Antrea interface type for the secondary bridge", "type", interfaceType)
}

if intf != nil {
ifaceList = append(ifaceList, intf)
}

}

pc.interfaceStore.Initialize(ifaceList)
klog.InfoS("Successfully initialized the secondary bridge interface store")

return nil
}

0 comments on commit 20ca6f4

Please sign in to comment.