@@ -8,45 +8,49 @@ import (
8
8
9
9
nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
10
10
nadutils "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils"
11
- multusapi "gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/server/api"
12
11
)
13
12
14
- func AddDynamicIfaceToStatus (currentPod * corev1.Pod , networkSelectionElement * nettypes. NetworkSelectionElement , response * multusapi. Response ) ([]nettypes.NetworkStatus , error ) {
13
+ func AddDynamicIfaceToStatus (currentPod * corev1.Pod , attachmentResults ... AttachmentResult ) ([]nettypes.NetworkStatus , error ) {
15
14
currentIfaceStatus , err := podDynamicNetworkStatus (currentPod )
16
15
if err != nil {
17
16
return nil , err
18
17
}
19
18
20
- if response != nil && response .Result != nil {
21
- newIfaceStatus , err := nadutils .CreateNetworkStatus (
22
- response .Result ,
23
- NamespacedName (networkSelectionElement .Namespace , networkSelectionElement .Name ),
24
- false ,
25
- nil ,
26
- )
27
- if err != nil {
28
- return nil , fmt .Errorf ("failed to create NetworkStatus from the response: %v" , err )
19
+ for _ , attachmentResult := range attachmentResults {
20
+ response := attachmentResult .result
21
+ networkSelectionElement := attachmentResult .attachment
22
+ if response != nil && response .Result != nil {
23
+ newIfaceStatus , err := nadutils .CreateNetworkStatus (
24
+ response .Result ,
25
+ NamespacedName (networkSelectionElement .Namespace , networkSelectionElement .Name ),
26
+ false ,
27
+ nil ,
28
+ )
29
+ if err != nil {
30
+ return nil , fmt .Errorf ("failed to create NetworkStatus from the response: %v" , err )
31
+ }
32
+ currentIfaceStatus = append (currentIfaceStatus , * newIfaceStatus )
29
33
}
30
-
31
- return append (currentIfaceStatus , * newIfaceStatus ), nil
32
34
}
33
- return nil , fmt . Errorf ( "got an empty response from multus: %+v" , response )
35
+ return currentIfaceStatus , nil
34
36
}
35
37
36
- func DeleteDynamicIfaceFromStatus (currentPod * corev1.Pod , networkSelectionElement * nettypes.NetworkSelectionElement ) ([]nettypes.NetworkStatus , error ) {
38
+ func DeleteDynamicIfaceFromStatus (currentPod * corev1.Pod , networkSelectionElements ... * nettypes.NetworkSelectionElement ) ([]nettypes.NetworkStatus , error ) {
37
39
currentIfaceStatus , err := podDynamicNetworkStatus (currentPod )
38
40
if err != nil {
39
41
return nil , err
40
42
}
41
43
42
- netName := NamespacedName (networkSelectionElement .Namespace , networkSelectionElement .Name )
43
44
var newIfaceStatus []nettypes.NetworkStatus
44
- newIfaceStatus = make ([]nettypes.NetworkStatus , 0 )
45
- for i := range currentIfaceStatus {
46
- if currentIfaceStatus [i ].Name == netName && currentIfaceStatus [i ].Interface == networkSelectionElement .InterfaceRequest {
47
- continue
45
+ for _ , networkSelectionElement := range networkSelectionElements {
46
+ netName := NamespacedName (networkSelectionElement .Namespace , networkSelectionElement .Name )
47
+ newIfaceStatus = make ([]nettypes.NetworkStatus , 0 )
48
+ for i := range currentIfaceStatus {
49
+ if currentIfaceStatus [i ].Name == netName && currentIfaceStatus [i ].Interface == networkSelectionElement .InterfaceRequest {
50
+ continue
51
+ }
52
+ newIfaceStatus = append (newIfaceStatus , currentIfaceStatus [i ])
48
53
}
49
- newIfaceStatus = append (newIfaceStatus , currentIfaceStatus [i ])
50
54
}
51
55
return newIfaceStatus , nil
52
56
}
0 commit comments