Skip to content

Commit f6b6206

Browse files
committed
removed cni circular dependency
1 parent f2bd968 commit f6b6206

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

cni/netconfig.go

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

10+
acn "github.com/Azure/azure-container-networking/common"
1011
"github.com/Azure/azure-container-networking/network/policy"
1112
cniTypes "github.com/containernetworking/cni/pkg/types"
1213
)
@@ -15,12 +16,6 @@ const (
1516
PolicyStr string = "Policy"
1617
)
1718

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-
2419
type PortMapping struct {
2520
HostPort int `json:"hostPort"`
2621
ContainerPort int `json:"containerPort"`
@@ -78,7 +73,7 @@ type NetworkConfig struct {
7873
DNS cniTypes.DNS `json:"dns,omitempty"`
7974
RuntimeConfig RuntimeConfig `json:"runtimeConfig,omitempty"`
8075
WindowsSettings WindowsSettings `json:"windowsSettings,omitempty"`
81-
AdditionalArgs []KVPair `json:"AdditionalArgs,omitempty"`
76+
AdditionalArgs []acn.KVPair `json:"AdditionalArgs,omitempty"`
8277
}
8378

8479
type WindowsSettings struct {
@@ -121,7 +116,7 @@ func ParseNetworkConfig(b []byte) (*NetworkConfig, error) {
121116
}
122117

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

cni/network/network_windows_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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"
1516
"github.com/Azure/azure-container-networking/network"
1617
"github.com/Azure/azure-container-networking/network/hnswrapper"
1718
"github.com/Azure/azure-container-networking/network/policy"
@@ -941,7 +942,7 @@ func TestPluginWindowsAdd(t *testing.T) {
941942
EnableExactMatchForPodName: true,
942943
Master: "eth0",
943944
// these are added to test that policies propagate to endpoint info
944-
AdditionalArgs: []cni.KVPair{
945+
AdditionalArgs: []acn.KVPair{
945946
{
946947
Name: "EndpointPolicy",
947948
Value: GetRawOutBoundNATPolicy(),

cns/NetworkContainerContract.go

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

10-
"github.com/Azure/azure-container-networking/cni"
1110
"github.com/Azure/azure-container-networking/cns/types"
11+
acn "github.com/Azure/azure-container-networking/common"
1212
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
1313
"github.com/google/uuid"
1414
"github.com/pkg/errors"
@@ -505,7 +505,7 @@ type PodIpInfo struct {
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
507507
// Defauly Deny ACL's to configure on HNS endpoints for Swiftv2 window nodes
508-
DefaultDenyACL []cni.KVPair
508+
DefaultDenyACL []acn.KVPair
509509
}
510510

511511
type HostIPInfo struct {

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package middlewares
33
import (
44
"encoding/json"
55

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

78-
additionalArgs := []cni.KVPair{
78+
additionalArgs := []acn.KVPair{
7979
{
8080
Name: "EndpointPolicy",
8181
Value: blockEgressACL,

cns/middlewares/k8sSwiftV2_windows_test.go

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

8-
"github.com/Azure/azure-container-networking/cni"
98
"github.com/Azure/azure-container-networking/cns"
109
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
10+
acn "github.com/Azure/azure-container-networking/common"
1111
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
1212
"github.com/stretchr/testify/require"
1313
"gotest.tools/v3/assert"
@@ -119,7 +119,7 @@ func TestAddDefaultDenyACL(t *testing.T) {
119119
"Priority": 10000
120120
}`)
121121

122-
expectedDefaultDenyACL := []cni.KVPair{
122+
expectedDefaultDenyACL := []acn.KVPair{
123123
{
124124
Name: "EndpointPolicy",
125125
Value: valueOut,
@@ -151,8 +151,8 @@ func TestAddDefaultDenyACL(t *testing.T) {
151151
}
152152

153153
// 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 []cni.KVPair) []cni.KVPair {
155-
normalized := make([]cni.KVPair, len(kvPairs))
154+
func normalizeKVPairs(t *testing.T, kvPairs []acn.KVPair) []acn.KVPair {
155+
normalized := make([]acn.KVPair, len(kvPairs))
156156

157157
for i, kv := range kvPairs {
158158
var unmarshaledValue map[string]interface{}
@@ -165,7 +165,7 @@ func normalizeKVPairs(t *testing.T, kvPairs []cni.KVPair) []cni.KVPair {
165165
require.NoError(t, err, "Failed to re-marshal JSON value")
166166

167167
// Replace Value with the normalized compact JSON
168-
normalized[i] = cni.KVPair{
168+
normalized[i] = acn.KVPair{
169169
Name: kv.Name,
170170
Value: normalizedValue,
171171
}

common/config.go

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

44
package common
55

6+
import (
7+
"encoding/json"
8+
)
9+
610
// Command line options.
711
const (
812
// Operating environment.
@@ -146,3 +150,9 @@ const (
146150
// OptCNIConflistScenarioAlias "shorthand" for the cni conflist scenairo, see above
147151
OptCNIConflistScenarioAlias = "cniconflistscenario"
148152
)
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)