Skip to content

Commit

Permalink
Remove slice
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Feb 2, 2024
1 parent 2a9c1fd commit 0371464
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
5 changes: 1 addition & 4 deletions cnf-certification-test/networking/icmp/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ func BuildNetTestContext(pods []*provider.Pod, aIPVersion netcommons.IPVersion,
}
for netKey, multusNetworkInterface := range put.MultusNetworkInterfaces {
// The first container is used to get the network namespace
// Loop through all the network interfaces and their IPs
for _, networkInterface := range multusNetworkInterface {
processContainerIpsPerNet(put.Containers[0], netKey, networkInterface.IPs, networkInterface.Interface, netsUnderTest, aIPVersion, logger)
}
processContainerIpsPerNet(put.Containers[0], netKey, multusNetworkInterface.IPs, multusNetworkInterface.Interface, netsUnderTest, aIPVersion, logger)
}
continue
}
Expand Down
42 changes: 17 additions & 25 deletions cnf-certification-test/networking/icmp/icmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestBuildNetTestContext(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for idx := range tt.args.pods {
tt.args.pods[idx].MultusNetworkInterfaces = make(map[string][]provider.CniNetworkInterface)
tt.args.pods[idx].MultusNetworkInterfaces = make(map[string]provider.CniNetworkInterface)
var err error
tt.args.pods[idx].MultusNetworkInterfaces, err = provider.GetPodIPsPerNet(tt.args.pods[idx].GetAnnotations()[provider.CniNetworksStatusKey])
if err != nil {
Expand Down Expand Up @@ -572,20 +572,16 @@ var (
},
},
},
MultusNetworkInterfaces: map[string][]provider.CniNetworkInterface{
MultusNetworkInterfaces: map[string]provider.CniNetworkInterface{
"tnf/mynet-ipv4-0": {
{
Interface: "net1",
Name: "mynet-ipv4-0",
IPs: []string{"192.168.0.3"},
},
Interface: "net1",
Name: "mynet-ipv4-0",
IPs: []string{"192.168.0.3"},
},
"tnf/mynet-ipv4-1": {
{
Interface: "net2",
Name: "mynet-ipv4-1",
IPs: []string{"192.168.1.3"},
},
Interface: "net2",
Name: "mynet-ipv4-1",
IPs: []string{"192.168.1.3"},
},
},
SkipNetTests: false,
Expand Down Expand Up @@ -623,20 +619,16 @@ var (
},
},
},
MultusNetworkInterfaces: map[string][]provider.CniNetworkInterface{
MultusNetworkInterfaces: map[string]provider.CniNetworkInterface{
"tnf/mynet-ipv4-0": {
{
Interface: "net1",
Name: "mynet-ipv4-0",
IPs: []string{"192.168.0.4"},
},
Interface: "net1",
Name: "mynet-ipv4-0",
IPs: []string{"192.168.0.4"},
},
"tnf/mynet-ipv4-1": {
{
Interface: "net2",
Name: "mynet-ipv4-1",
IPs: []string{"192.168.1.4"},
},
Interface: "net2",
Name: "mynet-ipv4-1",
IPs: []string{"192.168.1.4"},
},
},
SkipNetTests: false,
Expand Down Expand Up @@ -674,7 +666,7 @@ var (
},
},
},
MultusNetworkInterfaces: map[string][]provider.CniNetworkInterface{
MultusNetworkInterfaces: map[string]provider.CniNetworkInterface{
"": {},
},
SkipNetTests: true,
Expand Down Expand Up @@ -712,7 +704,7 @@ var (
},
},
},
MultusNetworkInterfaces: map[string][]provider.CniNetworkInterface{
MultusNetworkInterfaces: map[string]provider.CniNetworkInterface{
"": {},
},
SkipNetTests: false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
type Pod struct {
*corev1.Pod
Containers []*Container
MultusNetworkInterfaces map[string][]CniNetworkInterface
MultusNetworkInterfaces map[string]CniNetworkInterface
MultusPCIs []string
SkipNetTests bool
SkipMultusNetTests bool
Expand All @@ -52,7 +52,7 @@ type Pod struct {
func NewPod(aPod *corev1.Pod) (out Pod) {
var err error
out.Pod = aPod
out.MultusNetworkInterfaces = make(map[string][]CniNetworkInterface)
out.MultusNetworkInterfaces = make(map[string]CniNetworkInterface)
out.MultusNetworkInterfaces, err = GetPodIPsPerNet(aPod.GetAnnotations()[CniNetworksStatusKey])
if err != nil {
log.Error("Could not get IPs for Pod %q (namespace %q), err: %v", aPod.Name, aPod.Namespace, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ func GetRuntimeUID(cs *corev1.ContainerStatus) (runtime, uid string) {
// GetPodIPsPerNet gets the IPs of a pod.
// CNI annotation "k8s.v1.cni.cncf.io/networks-status".
// Returns (ips, error).
func GetPodIPsPerNet(annotation string) (ips map[string][]CniNetworkInterface, err error) {
func GetPodIPsPerNet(annotation string) (ips map[string]CniNetworkInterface, err error) {
// This is a map indexed with the network name (network attachment) and
// listing all the IPs created in this subnet and belonging to the pod namespace
// The list of ips pr net is parsed from the content of the "k8s.v1.cni.cncf.io/networks-status" annotation.
ips = make(map[string][]CniNetworkInterface)
ips = make(map[string]CniNetworkInterface)

var cniInfo []CniNetworkInterface
err = json.Unmarshal([]byte(annotation), &cniInfo)
Expand All @@ -462,7 +462,7 @@ func GetPodIPsPerNet(annotation string) (ips map[string][]CniNetworkInterface, e
// Otherwise add all non default interfaces
for _, cniInterface := range cniInfo {
if !cniInterface.Default {
ips[cniInterface.Name] = append(ips[cniInterface.Name], cniInterface)
ips[cniInterface.Name] = cniInterface
}
}
return ips, nil
Expand Down

0 comments on commit 0371464

Please sign in to comment.