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 Dec 17, 2024
1 parent 3258908 commit 63d1231
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 @@ -138,6 +138,9 @@ func NewPodController(
// Subscribe Pod CNI add/del events.
podUpdateSubscriber.Subscribe(pc.processCNIUpdate)
}

pc.RestoreSecondaryNetwork(ovsBridgeClient, ifaceStore)

return &pc, nil
}

Expand Down Expand Up @@ -502,3 +505,69 @@ func checkForPodSecondaryNetworkAttachement(pod *corev1.Pod) (string, bool) {
return netObj, false
}
}

// RestoreSecondaryNetwork restore cniCache and pod interface when agent restart.
func (pc *PodController) RestoreSecondaryNetwork(ovsBridgeClient ovsconfig.OVSBridgeClient, ifaceStore interfacestore.InterfaceStore) {
err := InitializeInterfaceStore(ovsBridgeClient, ifaceStore)
if err != nil {
klog.ErrorS(err, "Failed to initialize the secondary bridge interface store")
}

knownInterfaces := ifaceStore.GetInterfacesByType(interfacestore.ContainerInterface)
for _, containerConfig := range knownInterfaces {
Config, exists := ifaceStore.GetContainerInterface(containerConfig.ContainerID)
if !exists {
klog.InfoS("The container interface has been deleted ", "container id", Config.ContainerID)
return
}
event := types.PodUpdate{
IsAdd: true,
PodName: Config.PodName,
PodNamespace: Config.PodNamespace,
ContainerID: Config.ContainerID,
}
pc.processCNIUpdate(event)

}
}

func InitializeInterfaceStore(ovsClient ovsconfig.OVSBridgeClient, ifaceStore interfacestore.InterfaceStore) error {
ovsPorts, err := ovsClient.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)
}

}

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

return nil
}

0 comments on commit 63d1231

Please sign in to comment.