-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete secondaryNetwork OVS ports correctly after an Agent restart #6853
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ func NewPodController( | |
netAttachDefClient netdefclient.K8sCniCncfIoV1Interface, | ||
podInformer cache.SharedIndexInformer, | ||
podUpdateSubscriber channel.Subscriber, | ||
pIfaceStore interfacestore.InterfaceStore, | ||
ovsBridgeClient ovsconfig.OVSBridgeClient, | ||
) (*PodController, error) { | ||
ifaceStore := interfacestore.NewInterfaceStore() | ||
|
@@ -133,6 +134,18 @@ func NewPodController( | |
}, | ||
resyncPeriod, | ||
) | ||
|
||
err = pc.initializeSecondaryInterfaceStore() | ||
if err != nil { | ||
klog.ErrorS(err, "Failed to initialize the secondary interface store") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically we do not log if the returned error will be logged in the caller; instead we can append extra context to the returned error like: |
||
return &pc, err | ||
} | ||
|
||
if err := pc.reconcileSecondaryInterfaces(pIfaceStore); err != nil { | ||
klog.ErrorS(err, "Failed to restore CNI cache and reconcile secondary interfaces") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
return &pc, err | ||
} | ||
|
||
// podUpdateSubscriber can be nil with test code. | ||
if podUpdateSubscriber != nil { | ||
// Subscribe Pod CNI add/del events. | ||
|
@@ -502,3 +515,82 @@ func checkForPodSecondaryNetworkAttachement(pod *corev1.Pod) (string, bool) { | |
return netObj, false | ||
} | ||
} | ||
|
||
// initializeSecondaryInterfaceStore restore secondary interfacestore when agent restart. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. restore -> restores interfacestore -> "interface store" or "InterfaceStore" restart -> restarts |
||
func (pc *PodController) initializeSecondaryInterfaceStore() error { | ||
if pc.ovsBridgeClient == nil { | ||
return nil | ||
} | ||
|
||
ovsPorts, err := pc.ovsBridgeClient.GetPortList() | ||
if err != nil { | ||
klog.ErrorS(err, "Failed to list OVS ports for the secondary bridge", "bridgeName", pc.ovsBridgeClient.GetBridgeName()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, do we need to log here? |
||
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) | ||
KMAnju-2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if intf != nil { | ||
ifaceList = append(ifaceList, intf) | ||
} | ||
|
||
} | ||
|
||
pc.interfaceStore.Initialize(ifaceList) | ||
KMAnju-2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
klog.InfoS("Successfully initialized the secondary bridge interface store") | ||
|
||
return nil | ||
} | ||
|
||
// reconcileSecondaryInterfaces restore cniCache when agent restart using primary interfacestore. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. restores restarts InterfaceStore |
||
func (pc *PodController) reconcileSecondaryInterfaces(pIfaceStore interfacestore.InterfaceStore) error { | ||
knownInterfaces := pIfaceStore.GetInterfacesByType(interfacestore.ContainerInterface) | ||
for _, containerConfig := range knownInterfaces { | ||
config := containerConfig.ContainerInterfaceConfig | ||
podKey := podKeyGet(config.PodName, config.PodNamespace) | ||
|
||
pc.cniCache.Store(podKey, &podCNIInfo{ | ||
containerID: config.ContainerID, | ||
}) | ||
pc.queue.Add(podKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we queue the task? I feel it is not needed. |
||
} | ||
|
||
var staleInterfaces []*interfacestore.InterfaceConfig | ||
// secondaryInterfaces is the list of interfaces currently in the secondary local cache and delete ports not in the CNI cache. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this sentence needs to be revised. Probably make it: And move |
||
secondaryInterfaces := pc.interfaceStore.GetInterfacesByType(interfacestore.ContainerInterface) | ||
for _, containerConfig := range secondaryInterfaces { | ||
_, exists := pIfaceStore.GetContainerInterface(containerConfig.ContainerID) | ||
if !exists || containerConfig.OFPort == -1 { | ||
staleInterfaces = append(staleInterfaces, containerConfig) | ||
} | ||
} | ||
|
||
// If there are any stale interfaces, pass them to removeInterfaces() | ||
if len(staleInterfaces) > 0 { | ||
if err := pc.removeInterfaces(staleInterfaces); err != nil { | ||
return fmt.Errorf("failed to remove stale interfaces: %w", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel we should just log the error, but no need to return it and fail the agent start. Check https://github.com/antrea-io/antrea/blob/main/pkg/agent/cniserver/pod_configuration.go#L472 |
||
} | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Controller -> controller