Skip to content

Commit

Permalink
Merge pull request kubevirt#11678 from Vicente-Cheng/fix-ordinal-pod-…
Browse files Browse the repository at this point in the history
…interface-name

Improve the handling of ordinal pod interface name for upgrade
  • Loading branch information
kubevirt-bot authored Apr 11, 2024
2 parents fa25a88 + 40431b3 commit 68144f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pkg/network/namescheme/networknamescheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,13 @@ func CreateOrdinalNetworkNameScheme(vmiNetworks []v1.Network) map[string]string
return networkNameSchemeMap
}

// OrdinalPodInterfaceName returns the ordinal interface name for the given network name.
// Rereuse the `CreateOrdinalNetworkNameScheme` for various networks helps find the target interface name.
func OrdinalPodInterfaceName(name string, networks []v1.Network) string {
for i, network := range networks {
if network.Name == name {
if vmispec.IsSecondaryMultusNetwork(network) {
return generateOrdinalInterfaceName(i)
}

return PrimaryPodInterfaceName
}
networkNameSchemeMap := CreateOrdinalNetworkNameScheme(networks)
if ordinalName, exist := networkNameSchemeMap[name]; exist {
return ordinalName
}

return ""
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/network/namescheme/networknamescheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,22 @@ var _ = Describe("Network Name Scheme", func() {
},
"net2",
),
Entry("given secondary network name with different order",
"multus01",
[]virtv1.Network{
createMultusSecondaryNetwork("blue", "test-br"),
createMultusSecondaryNetwork("multus01", "test-br"),
newPodNetwork(),
},
"net2",
),
Entry("given secondary network name, only one secondary network",
"multus01",
[]virtv1.Network{
createMultusSecondaryNetwork("multus01", "test-br"),
},
"net1",
),
)
})
})
Expand Down

0 comments on commit 68144f8

Please sign in to comment.