Skip to content

Commit

Permalink
virt-controller, vmi: Update the multus annotation only if it changed
Browse files Browse the repository at this point in the history
If the calculated multus annotation is identical to the existing, there
is no need to execute a patch on the VMI object.

This change also resolves a bug that occurs when unplugging the last
secondary network.
Before this fix, when the last network got unplugged, no secondary
network got left, therefore there was no multus annotation generated.
And this led to not patching the VMI object, although it should have.

Signed-off-by: Edward Haas <[email protected]>
  • Loading branch information
EdDev committed Nov 30, 2023
1 parent 08e4caf commit c25e0f0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/virt-controller/watch/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2296,13 +2296,15 @@ func (c *VMIController) updateMultusAnnotation(namespace string, interfaces []vi
if err != nil {
return err
}

currentMultusAnnotation := podAnnotations[networkv1.NetworkAttachmentAnnot]
log.Log.Object(pod).V(4).Infof(
"current multus annotation for pod: %s; updated multus annotation for pod with: %s",
podAnnotations[networkv1.NetworkAttachmentAnnot],
currentMultusAnnotation,
multusAnnotations,
)

if multusAnnotations != "" {
if multusAnnotations != currentMultusAnnotation {
newAnnotations := map[string]string{networkv1.NetworkAttachmentAnnot: multusAnnotations}
patchedPod, err := c.syncPodAnnotations(pod, newAnnotations)
if err != nil {
Expand Down

0 comments on commit c25e0f0

Please sign in to comment.