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 11, 2024
1 parent 3258908 commit 3b7abe8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ func run(o *Options) error {
NodePortAddressesIPv6: nodePortAddressesIPv6,
}

if features.DefaultFeatureGate.Enabled(features.SecondaryNetwork) {
bridgeConfig := o.config.SecondaryNetwork.OVSBridges[0]
ovsSecBridgeClient := ovsconfig.NewOVSBridge(bridgeConfig.BridgeName, ovsDatapathType, ovsdbConnection, ovsconfig.WithRequiredPortExternalIDs(interfacestore.AntreaInterfaceTypeKey))
secondaryBridge :=agent.NewSecondaryBridgeInitializer(ovsSecBridgeClient, ifaceStore, bridgeConfig.BridgeName)
err := secondaryBridge.InitializeInterfaceStore()
if err != nil {
klog.ErrorS(err, "Failed to initialize the secondary bridge interface store")
}
}

// Initialize agent and node network.
agentInitializer := agent.NewInitializer(
k8sClient,
Expand Down
59 changes: 59 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,24 @@ func NewInitializer(
}
}

type SecondaryBridgeInitializer struct {
ovsClient ovsconfig.OVSBridgeClient
ifaceStore interfacestore.InterfaceStore
bridgeName string
}

func NewSecondaryBridgeInitializer(
ovsClient ovsconfig.OVSBridgeClient,
ifaceStore interfacestore.InterfaceStore,
bridgeName string,
) *SecondaryBridgeInitializer {
return &SecondaryBridgeInitializer{
ovsClient: ovsClient,
ifaceStore: ifaceStore,
bridgeName: bridgeName,
}
}

// GetNodeConfig returns the NodeConfig.
func (i *Initializer) GetNodeConfig() *config.NodeConfig {
return i.nodeConfig
Expand Down Expand Up @@ -274,6 +292,47 @@ func (i *Initializer) validateSupportedDPFeatures() error {
return nil
}

func (s *SecondaryBridgeInitializer) InitializeInterfaceStore() error {
ovsPorts, err := s.ovsClient.GetPortList()
if err != nil {
klog.ErrorS(err, "Failed to list OVS ports for the secondary bridge", "bridgeName", s.bridgeName)
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)
}

}

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

return nil
}

// initInterfaceStore initializes InterfaceStore with all OVS ports retrieved
// from the OVS bridge.
func (i *Initializer) initInterfaceStore() error {
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/cniserver/pod_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,15 @@ func (pc *podConfigurator) reconcile(pods []corev1.Pod, containerAccess *contain
continue
}
podWg.Add(1)
go func(containerID, pod, namespace string) {
go func(containerID, iface, pod, namespace string) {
defer podWg.Done()
// Do not install Pod flows until all preconditions are met.
podNetworkWait.Wait()
// To avoid race condition with CNIServer CNI event handlers.
containerAccess.lockContainer(containerID)
defer containerAccess.unlockContainer(containerID)

containerConfig, exists := pc.ifaceStore.GetContainerInterface(containerID)
containerConfig, exists := pc.ifaceStore.GetInterfaceByName(iface)
if !exists {
klog.InfoS("The container interface had been deleted, skip installing flows for Pod", "Pod", klog.KRef(namespace, name), "containerID", containerID)
return
Expand All @@ -496,7 +496,7 @@ func (pc *podConfigurator) reconcile(pods []corev1.Pod, containerAccess *contain
); err != nil {
klog.ErrorS(err, "Error when re-installing flows for Pod", "Pod", klog.KRef(namespace, name))
}
}(containerConfig.ContainerID, name, namespace)
}(containerConfig.ContainerID, containerConfig.InterfaceName, name, namespace)
} else {
// clean-up and delete interface
klog.V(4).InfoS("Deleting interface", "Pod", klog.KRef(namespace, name), "iface", containerConfig.InterfaceName)
Expand Down

0 comments on commit 3b7abe8

Please sign in to comment.