Skip to content

Commit 49da7b6

Browse files
committed
updated cni code to match network container contract update
1 parent 8b79796 commit 49da7b6

File tree

8 files changed

+38
-44
lines changed

8 files changed

+38
-44
lines changed

cni/netconfig.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/json"
88
"strings"
99

10-
acn "github.com/Azure/azure-container-networking/common"
1110
"github.com/Azure/azure-container-networking/network/policy"
1211
cniTypes "github.com/containernetworking/cni/pkg/types"
1312
)
@@ -16,6 +15,12 @@ const (
1615
PolicyStr string = "Policy"
1716
)
1817

18+
// KVPair represents a K-V pair of a json object.
19+
type KVPair struct {
20+
Name string `json:"name"`
21+
Value json.RawMessage `json:"value"`
22+
}
23+
1924
type PortMapping struct {
2025
HostPort int `json:"hostPort"`
2126
ContainerPort int `json:"containerPort"`
@@ -73,7 +78,7 @@ type NetworkConfig struct {
7378
DNS cniTypes.DNS `json:"dns,omitempty"`
7479
RuntimeConfig RuntimeConfig `json:"runtimeConfig,omitempty"`
7580
WindowsSettings WindowsSettings `json:"windowsSettings,omitempty"`
76-
AdditionalArgs []acn.KVPair `json:"AdditionalArgs,omitempty"`
81+
AdditionalArgs []KVPair `json:"AdditionalArgs,omitempty"`
7782
}
7883

7984
type WindowsSettings struct {
@@ -116,7 +121,7 @@ func ParseNetworkConfig(b []byte) (*NetworkConfig, error) {
116121
}
117122

118123
// GetPoliciesFromNwCfg returns network policies from network config.
119-
func GetPoliciesFromNwCfg(kvp []acn.KVPair) []policy.Policy {
124+
func GetPoliciesFromNwCfg(kvp []KVPair) []policy.Policy {
120125
var policies []policy.Policy
121126
for _, pair := range kvp {
122127
if strings.Contains(pair.Name, PolicyStr) {

cni/network/invoker_cns.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"github.com/Azure/azure-container-networking/cns"
1313
cnscli "github.com/Azure/azure-container-networking/cns/client"
1414
"github.com/Azure/azure-container-networking/cns/fsnotify"
15-
acn "github.com/Azure/azure-container-networking/common"
1615
"github.com/Azure/azure-container-networking/iptables"
1716
"github.com/Azure/azure-container-networking/network"
1817
"github.com/Azure/azure-container-networking/network/networkutils"
18+
"github.com/Azure/azure-container-networking/network/policy"
1919
cniSkel "github.com/containernetworking/cni/pkg/skel"
2020
"github.com/pkg/errors"
2121
"go.uber.org/zap"
@@ -56,7 +56,7 @@ type IPResultInfo struct {
5656
skipDefaultRoutes bool
5757
routes []cns.Route
5858
pnpID string
59-
defaultDenyACL []acn.KVPair
59+
endpointPolicies []policy.Policy
6060
}
6161

6262
func (i IPResultInfo) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
@@ -161,7 +161,7 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
161161
skipDefaultRoutes: response.PodIPInfo[i].SkipDefaultRoutes,
162162
routes: response.PodIPInfo[i].Routes,
163163
pnpID: response.PodIPInfo[i].PnPID,
164-
defaultDenyACL: response.PodIPInfo[i].DefaultDenyACL,
164+
endpointPolicies: response.PodIPInfo[i].EndpointPolicies,
165165
}
166166

167167
logger.Info("Received info for pod",
@@ -456,7 +456,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
456456
IPConfigs: ipConfigs,
457457
Routes: resRoute,
458458
HostSubnetPrefix: *hostIPNet,
459-
DefaultDenyACL: info.defaultDenyACL,
459+
EndpointPolicies: info.endpointPolicies,
460460
}
461461
}
462462

cni/network/invoker_cns_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/Azure/azure-container-networking/cni"
1111
"github.com/Azure/azure-container-networking/cni/util"
1212
"github.com/Azure/azure-container-networking/cns"
13-
acn "github.com/Azure/azure-container-networking/common"
1413
"github.com/Azure/azure-container-networking/iptables"
1514
"github.com/Azure/azure-container-networking/network"
15+
"github.com/Azure/azure-container-networking/network/policy"
1616
cniSkel "github.com/containernetworking/cni/pkg/skel"
1717
"github.com/stretchr/testify/require"
1818
)
@@ -536,14 +536,14 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
536536
"Priority": 10000
537537
}`)
538538

539-
expectedDefaultDenyACL := []acn.KVPair{
539+
expectedEndpointPolicies := []policy.Policy{
540540
{
541-
Name: "EndpointPolicy",
542-
Value: valueOut,
541+
Type: policy.ACLPolicy,
542+
Data: valueOut,
543543
},
544544
{
545-
Name: "EndpointPolicy",
546-
Value: valueIn,
545+
Type: policy.ACLPolicy,
546+
Data: valueIn,
547547
},
548548
}
549549
tests := []struct {
@@ -583,8 +583,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
583583
PrimaryIP: "10.0.0.1",
584584
Subnet: "10.0.0.0/24",
585585
},
586-
NICType: cns.InfraNIC,
587-
DefaultDenyACL: expectedDefaultDenyACL,
586+
NICType: cns.InfraNIC,
587+
EndpointPolicies: expectedEndpointPolicies,
588588
},
589589
},
590590
Response: cns.Response{
@@ -613,7 +613,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
613613
Gateway: net.ParseIP("10.0.0.1"),
614614
},
615615
},
616-
DefaultDenyACL: expectedDefaultDenyACL,
616+
EndpointPolicies: expectedEndpointPolicies,
617617
Routes: []network.RouteInfo{
618618
{
619619
Dst: network.Ipv4DefaultRouteDstPrefix,
@@ -654,7 +654,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
654654
PrimaryIP: "10.0.0.1",
655655
Subnet: "10.0.0.0/24",
656656
},
657-
DefaultDenyACL: expectedDefaultDenyACL,
657+
EndpointPolicies: expectedEndpointPolicies,
658658
},
659659
},
660660
Response: cns.Response{
@@ -683,7 +683,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
683683
Gateway: net.ParseIP("10.0.0.1"),
684684
},
685685
},
686-
DefaultDenyACL: expectedDefaultDenyACL,
686+
EndpointPolicies: expectedEndpointPolicies,
687687
Routes: []network.RouteInfo{
688688
{
689689
Dst: network.Ipv4DefaultRouteDstPrefix,
@@ -724,8 +724,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
724724
PrimaryIP: "10.0.0.1",
725725
Subnet: "10.0.0.0/24",
726726
},
727-
NICType: cns.InfraNIC,
728-
DefaultDenyACL: expectedDefaultDenyACL,
727+
NICType: cns.InfraNIC,
728+
EndpointPolicies: expectedEndpointPolicies,
729729
},
730730
{
731731
PodIPConfig: cns.IPSubnet{
@@ -745,8 +745,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
745745
PrimaryIP: "fe80::1234:5678:9abc",
746746
Subnet: "fd11:1234::/112",
747747
},
748-
NICType: cns.InfraNIC,
749-
DefaultDenyACL: expectedDefaultDenyACL,
748+
NICType: cns.InfraNIC,
749+
EndpointPolicies: expectedEndpointPolicies,
750750
},
751751
},
752752
Response: cns.Response{
@@ -779,7 +779,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
779779
Gateway: net.ParseIP("fe80::1234:5678:9abc"),
780780
},
781781
},
782-
DefaultDenyACL: expectedDefaultDenyACL,
782+
EndpointPolicies: expectedEndpointPolicies,
783783
Routes: []network.RouteInfo{
784784
{
785785
Dst: network.Ipv4DefaultRouteDstPrefix,
@@ -807,7 +807,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
807807
result: &cns.IPConfigsResponse{
808808
PodIPInfo: []cns.PodIpInfo{
809809
{
810-
DefaultDenyACL: expectedDefaultDenyACL,
810+
EndpointPolicies: expectedEndpointPolicies,
811811
},
812812
},
813813
Response: cns.Response{
@@ -836,7 +836,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
836836
}
837837
ipamAddResult, err := invoker.Add(IPAMAddConfig{nwCfg: tt.args.nwCfg, args: tt.args.args, options: tt.args.options})
838838
if tt.wantErr {
839-
require.Equalf([]acn.KVPair(nil), ipamAddResult.interfaceInfo[string(cns.InfraNIC)].DefaultDenyACL, "Correct default deny ACL")
839+
require.Equalf([]policy.Policy(nil), ipamAddResult.interfaceInfo[string(cns.InfraNIC)].EndpointPolicies, "There was an error requesting IP addresses from cns")
840840
require.Error(err)
841841
} else {
842842
require.NoError(err)
@@ -852,7 +852,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
852852
}
853853
if ifInfo.NICType == cns.InfraNIC {
854854
require.Equalf(tt.wantDefaultResult, ifInfo, "incorrect default response")
855-
require.Equalf(expectedDefaultDenyACL, ifInfo.DefaultDenyACL, "Correct default deny ACL")
855+
require.Equalf(expectedEndpointPolicies, ifInfo.EndpointPolicies, "Correct default deny ACL")
856856
}
857857
}
858858
})

cni/network/network.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,12 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
589589
// sendEvent(plugin, fmt.Sprintf("Allocated IPAddress from ipam DefaultInterface: %+v, SecondaryInterfaces: %+v", ipamAddResult.interfaceInfo[ifIndex], ipamAddResult.interfaceInfo))
590590
}
591591

592+
policies := cni.GetPoliciesFromNwCfg(nwCfg.AdditionalArgs)
592593
for key := range ipamAddResult.interfaceInfo {
593594
if key == string(cns.InfraNIC) {
594-
nwCfg.AdditionalArgs = append(nwCfg.AdditionalArgs, ipamAddResult.interfaceInfo[key].DefaultDenyACL...)
595+
policies = append(policies, ipamAddResult.interfaceInfo[key].EndpointPolicies...)
595596
}
596597
}
597-
598-
policies := cni.GetPoliciesFromNwCfg(nwCfg.AdditionalArgs)
599598
// moved to addIpamInvoker
600599
// sendEvent(plugin, fmt.Sprintf("Allocated IPAddress from ipam interface: %+v", ipamAddResult.PrettyString()))
601600

cni/network/network_windows_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/Azure/azure-container-networking/cni"
1414
"github.com/Azure/azure-container-networking/cns"
15-
acn "github.com/Azure/azure-container-networking/common"
1615
"github.com/Azure/azure-container-networking/network"
1716
"github.com/Azure/azure-container-networking/network/hnswrapper"
1817
"github.com/Azure/azure-container-networking/network/policy"
@@ -942,7 +941,7 @@ func TestPluginWindowsAdd(t *testing.T) {
942941
EnableExactMatchForPodName: true,
943942
Master: "eth0",
944943
// these are added to test that policies propagate to endpoint info
945-
AdditionalArgs: []acn.KVPair{
944+
AdditionalArgs: []cni.KVPair{
946945
{
947946
Name: "EndpointPolicy",
948947
Value: GetRawOutBoundNATPolicy(),

cns/NetworkContainerContract.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"strings"
99

1010
"github.com/Azure/azure-container-networking/cns/types"
11-
acn "github.com/Azure/azure-container-networking/common"
1211
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
12+
"github.com/Azure/azure-container-networking/network/policy"
1313
"github.com/google/uuid"
1414
"github.com/pkg/errors"
1515
corev1 "k8s.io/api/core/v1"
@@ -504,8 +504,8 @@ type PodIpInfo struct {
504504
Routes []Route
505505
// PnpId is set for backend interfaces, Pnp Id identifies VF. Plug and play id(pnp) is also called as PCI ID
506506
PnPID string
507-
// Defauly Deny ACL's to configure on HNS endpoints for Swiftv2 window nodes
508-
DefaultDenyACL []acn.KVPair
507+
// Default Deny ACL's to configure on HNS endpoints for Swiftv2 window nodes
508+
EndpointPolicies []policy.Policy
509509
}
510510

511511
type HostIPInfo struct {

common/config.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
package common
55

6-
import "encoding/json"
7-
86
// Command line options.
97
const (
108
// Operating environment.
@@ -148,9 +146,3 @@ const (
148146
// OptCNIConflistScenarioAlias "shorthand" for the cni conflist scenairo, see above
149147
OptCNIConflistScenarioAlias = "cniconflistscenario"
150148
)
151-
152-
// KVPair represents a K-V pair of a json object.
153-
type KVPair struct {
154-
Name string `json:"name"`
155-
Value json.RawMessage `json:"value"`
156-
}

network/endpoint.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/Azure/azure-container-networking/cni/log"
1313
"github.com/Azure/azure-container-networking/cns"
14-
acn "github.com/Azure/azure-container-networking/common"
1514
"github.com/Azure/azure-container-networking/netio"
1615
"github.com/Azure/azure-container-networking/netlink"
1716
"github.com/Azure/azure-container-networking/network/policy"
@@ -139,7 +138,7 @@ type InterfaceInfo struct {
139138
HostSubnetPrefix net.IPNet // Move this field from ipamAddResult
140139
NCResponse *cns.GetNetworkContainerResponse
141140
PnPID string
142-
DefaultDenyACL []acn.KVPair
141+
EndpointPolicies []policy.Policy
143142
}
144143

145144
type IPConfig struct {

0 commit comments

Comments
 (0)