Skip to content

Commit a56b665

Browse files
committed
cns changes based on update to network container contrac
1 parent e89f70f commit a56b665

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

cni/netconfig.go

Lines changed: 7 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,11 @@ const (
1615
PolicyStr string = "Policy"
1716
)
1817

18+
type KVPair struct {
19+
Name string `json:"name"`
20+
Value json.RawMessage `json:"value"`
21+
}
22+
1923
type PortMapping struct {
2024
HostPort int `json:"hostPort"`
2125
ContainerPort int `json:"containerPort"`
@@ -73,7 +77,7 @@ type NetworkConfig struct {
7377
DNS cniTypes.DNS `json:"dns,omitempty"`
7478
RuntimeConfig RuntimeConfig `json:"runtimeConfig,omitempty"`
7579
WindowsSettings WindowsSettings `json:"windowsSettings,omitempty"`
76-
AdditionalArgs []acn.KVPair `json:"AdditionalArgs,omitempty"`
80+
AdditionalArgs []KVPair `json:"AdditionalArgs,omitempty"`
7781
}
7882

7983
type WindowsSettings struct {
@@ -116,7 +120,7 @@ func ParseNetworkConfig(b []byte) (*NetworkConfig, error) {
116120
}
117121

118122
// GetPoliciesFromNwCfg returns network policies from network config.
119-
func GetPoliciesFromNwCfg(kvp []acn.KVPair) []policy.Policy {
123+
func GetPoliciesFromNwCfg(kvp []KVPair) []policy.Policy {
120124
var policies []policy.Policy
121125
for _, pair := range kvp {
122126
if strings.Contains(pair.Name, PolicyStr) {

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+
EdpointPolicies []policy.Policy
509509
}
510510

511511
type HostIPInfo struct {

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

66
"github.com/Azure/azure-container-networking/cns"
77
"github.com/Azure/azure-container-networking/cns/middlewares/utils"
8-
acn "github.com/Azure/azure-container-networking/common"
98
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
9+
"github.com/Azure/azure-container-networking/network/policy"
1010
"github.com/Microsoft/hcsshim/hcn"
1111
"github.com/pkg/errors"
1212
)
@@ -75,18 +75,18 @@ func addDefaultDenyACL(podIPInfo *cns.PodIpInfo) error {
7575
return errors.Wrap(err, "Failed to create default deny ACL policy ingress")
7676
}
7777

78-
additionalArgs := []acn.KVPair{
78+
additionalArgs := []policy.Policy{
7979
{
80-
Name: "EndpointPolicy",
81-
Value: blockEgressACL,
80+
Type: policy.ACLPolicy,
81+
Data: blockEgressACL,
8282
},
8383
{
84-
Name: "EndpointPolicy",
85-
Value: blockIngressACL,
84+
Type: policy.ACLPolicy,
85+
Data: blockIngressACL,
8686
},
8787
}
8888

89-
podIPInfo.DefaultDenyACL = append(podIPInfo.DefaultDenyACL, additionalArgs...)
89+
podIPInfo.EdpointPolicies = append(podIPInfo.EdpointPolicies, additionalArgs...)
9090

9191
return nil
9292
}

cns/middlewares/k8sSwiftV2_windows_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66
"testing"
77

8+
"github.com/Azure/azure-container-networking/cni"
89
"github.com/Azure/azure-container-networking/cns"
910
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
1011
acn "github.com/Azure/azure-container-networking/common"
@@ -119,7 +120,7 @@ func TestAddDefaultDenyACL(t *testing.T) {
119120
"Priority": 10000
120121
}`)
121122

122-
expectedDefaultDenyACL := []acn.KVPair{
123+
expectedDefaultDenyACL := []cni.KVPair{
123124
{
124125
Name: "EndpointPolicy",
125126
Value: valueOut,
@@ -151,8 +152,8 @@ func TestAddDefaultDenyACL(t *testing.T) {
151152
}
152153

153154
// normalizeKVPairs normalizes the JSON values in the KV pairs by unmarshaling them into a map, then marshaling them back to compact JSON to remove any extra space, new lines, etc
154-
func normalizeKVPairs(t *testing.T, kvPairs []acn.KVPair) []acn.KVPair {
155-
normalized := make([]acn.KVPair, len(kvPairs))
155+
func normalizeKVPairs(t *testing.T, kvPairs []acn.KVPair) []cni.KVPair {
156+
normalized := make([]cni.KVPair, len(kvPairs))
156157

157158
for i, kv := range kvPairs {
158159
var unmarshaledValue map[string]interface{}

common/config.go

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

44
package common
55

6-
import (
7-
"encoding/json"
8-
)
9-
106
// Command line options.
117
const (
128
// Operating environment.
@@ -150,9 +146,3 @@ const (
150146
// OptCNIConflistScenarioAlias "shorthand" for the cni conflist scenairo, see above
151147
OptCNIConflistScenarioAlias = "cniconflistscenario"
152148
)
153-
154-
// KVPair represents a K-V pair of a json object.
155-
type KVPair struct {
156-
Name string `json:"name"`
157-
Value json.RawMessage `json:"value"`
158-
}

0 commit comments

Comments
 (0)