Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aitelemetry/telemetrywrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func getMetadata(th *telemetryHandle) {
return
}

//acquire write lock before writing metadata to telemetry handle
// acquire write lock before writing metadata to telemetry handle
th.rwmutex.Lock()
th.metadata = metadata
th.rwmutex.Unlock()
Expand Down Expand Up @@ -188,7 +188,7 @@ func (th *telemetryHandle) TrackLog(report Report) {
// Initialize new trace message
trace := appinsights.NewTraceTelemetry(report.Message, appinsights.Warning)

//Override few of existing columns with metadata
// Override few of existing columns with metadata
trace.Tags.User().SetAuthUserId(runtime.GOOS)
trace.Tags.Operation().SetId(report.Context)
trace.Tags.Operation().SetParentId(th.appVersion)
Expand Down
4 changes: 1 addition & 3 deletions aitelemetry/telemetrywrapper_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ import (
"path/filepath"
)

var (
metadataFile = filepath.FromSlash(os.Getenv("TEMP")) + "\\azuremetadata.json"
)
var metadataFile = filepath.FromSlash(os.Getenv("TEMP")) + "\\azuremetadata.json"
1 change: 0 additions & 1 deletion cni/client/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,4 @@ func TestGetStateWithEmptyStateFile(t *testing.T) {
state, err := c.GetEndpointState()
require.NoError(t, err)
require.Exactly(t, 0, len(state.ContainerInterfaces))

}
46 changes: 20 additions & 26 deletions cni/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ import (
"github.com/Azure/azure-container-networking/common"
)

var ipamQueryUrl = "localhost:42424"
var ipamQueryResponse = "" +
"<Interfaces>" +
" <Interface MacAddress=\"*\" IsPrimary=\"true\">" +
" <IPSubnet Prefix=\"10.0.0.0/16\">" +
" <IPAddress Address=\"10.0.0.4\" IsPrimary=\"true\"/>" +
" <IPAddress Address=\"10.0.0.5\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.6\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.7\" IsPrimary=\"false\"/>" +
" </IPSubnet>" +
" </Interface>" +
"</Interfaces>"
var (
ipamQueryUrl = "localhost:42424"
ipamQueryResponse = "" +
"<Interfaces>" +
" <Interface MacAddress=\"*\" IsPrimary=\"true\">" +
" <IPSubnet Prefix=\"10.0.0.0/16\">" +
" <IPAddress Address=\"10.0.0.4\" IsPrimary=\"true\"/>" +
" <IPAddress Address=\"10.0.0.5\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.6\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.7\" IsPrimary=\"false\"/>" +
" </IPSubnet>" +
" </Interface>" +
"</Interfaces>"
)

func TestIpam(t *testing.T) {
RegisterFailHandler(Fail)
Expand Down Expand Up @@ -73,11 +75,11 @@ var (
err error
endpointID1 = uuid.New().String()

//this usedAddresses map is to test not duplicate IP's
// this usedAddresses map is to test not duplicate IP's
// have been provided throughout this test execution
UsedAddresses = map[string]string{}

//below is the network,used to test if the IP's provided by IPAM
// below is the network,used to test if the IP's provided by IPAM
// is in the the space requested.
network = net.IPNet{IP: net.ParseIP("10.0.0.0"), Mask: net.CIDRMask(16, 32)}

Expand All @@ -104,9 +106,7 @@ var (
})

_ = Describe("Test IPAM", func() {

Context("IPAM start", func() {

var config common.PluginConfig

It("Create IPAM plugin", func() {
Expand All @@ -127,7 +127,6 @@ var (
})

Describe("Test IPAM ADD and DELETE pool", func() {

var result *cniTypesCurr.Result

Context("When ADD with nothing, call for ipam triggering request pool and address", func() {
Expand All @@ -153,7 +152,6 @@ var (
Expect(err).ShouldNot(HaveOccurred())

delete(UsedAddresses, result.IPs[0].Address.IP.String())

})
})

Expand All @@ -167,7 +165,6 @@ var (
})

Describe("Test IPAM ADD and DELETE address", func() {

Context("When address is given", func() {
It("Request pool and address successfully", func() {
arg.StdinData = getStdinData("0.4.0", "", "10.0.0.6")
Expand Down Expand Up @@ -217,14 +214,13 @@ var (

AssertProperAddressSpace(result.IPs[0].Address)

//release the container ID for next test
// release the container ID for next test
arg.ContainerID = ""
})
})
})

Describe("Test IPAM DELETE", func() {

Context("Delete when only container id is given", func() {
It("Deleted", func() {
arg.StdinData = getStdinData("0.4.0", "10.0.0.0/16", "")
Expand All @@ -236,13 +232,11 @@ var (
address := UsedAddresses[arg.ContainerID]

RemoveAddressUsage(address, arg.ContainerID)

})
})

Context("When address and subnet is given", func() {
It("Release address successfully", func() {

nextAddress := GetNextAddress()
arg.StdinData = getStdinData("0.4.0", "10.0.0.0/16", nextAddress)
err = plugin.Delete(arg)
Expand Down Expand Up @@ -291,15 +285,15 @@ var (
)

func GetNextAddress() string {
//return first value
// return first value
for a := range UsedAddresses {
return a
}
return ""
}

func AssertAddressNotInUse(address string) {
//confirm if IP is in use by other invocation
// confirm if IP is in use by other invocation
_, exists := UsedAddresses[address]

Expect(exists).Should(BeFalse())
Expand All @@ -325,7 +319,7 @@ func RemoveAddressUsage(address, containerId string) {
}

func AssertProperAddressSpace(address net.IPNet) {
//validate the IP is part of this network IP space
// validate the IP is part of this network IP space
Expect(network.Contains(address.IP)).Should(Equal(true))
Expect(address.Mask).Should(Equal(network.Mask))
}
1 change: 1 addition & 0 deletions cni/netconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type PortMapping struct {
Protocol string `json:"protocol"`
HostIp string `json:"hostIP,omitempty"`
}

type RuntimeConfig struct {
PortMappings []PortMapping `json:"portMappings,omitempty"`
DNS RuntimeDNSConfig `json:"dns,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions cni/network/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
// or simply act as a client to an external ipam, such as azure-cns.
type IPAMInvoker interface {

//Add returns two results, one IPv4, the other IPv6.
// Add returns two results, one IPv4, the other IPv6.
Add(nwCfg *cni.NetworkConfig, args *cniSkel.CmdArgs, subnetPrefix *net.IPNet, options map[string]interface{}) (*cniTypesCurr.Result, *cniTypesCurr.Result, error)

//Delete calls to the invoker source, and returns error. Returning an error here will fail the CNI Delete call.
// Delete calls to the invoker source, and returns error. Returning an error here will fail the CNI Delete call.
Delete(address *net.IPNet, nwCfg *cni.NetworkConfig, args *cniSkel.CmdArgs, options map[string]interface{}) error
}
3 changes: 1 addition & 2 deletions cni/network/invoker_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (invoker *AzureIPAMInvoker) Add(nwCfg *cni.NetworkConfig, _ *cniSkel.CmdArg
result, err = invoker.plugin.DelegateAdd(nwCfg.Ipam.Type, nwCfg)
if err != nil {
err = invoker.plugin.Errorf("Failed to allocate pool: %v", err)
return nil, nil, err
return nil, nil, err
}

defer func() {
Expand Down Expand Up @@ -83,7 +83,6 @@ func (invoker *AzureIPAMInvoker) Add(nwCfg *cni.NetworkConfig, _ *cniSkel.CmdArg
}

func (invoker *AzureIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConfig, _ *cniSkel.CmdArgs, options map[string]interface{}) error {

if nwCfg == nil {
return invoker.plugin.Errorf("nil nwCfg passed to CNI ADD, stack: %+v", string(debug.Stack()))
}
Expand Down
2 changes: 1 addition & 1 deletion cni/network/invoker_cns.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewCNSInvoker(podName, namespace string) (*CNSIPAMInvoker, error) {
}, err
}

//Add uses the requestipconfig API in cns, and returns ipv4 and a nil ipv6 as CNS doesn't support IPv6 yet
// Add uses the requestipconfig API in cns, and returns ipv4 and a nil ipv6 as CNS doesn't support IPv6 yet
func (invoker *CNSIPAMInvoker) Add(nwCfg *cni.NetworkConfig, args *cniSkel.CmdArgs, hostSubnetPrefix *net.IPNet, options map[string]interface{}) (*cniTypesCurr.Result, *cniTypesCurr.Result, error) {
// Parse Pod arguments.
podInfo := cns.KubernetesPodInfo{
Expand Down
2 changes: 1 addition & 1 deletion cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ func determineSnat() (bool, bool, error) {
}

jsonStr, _ := json.Marshal(snatConfig)
fp, err := os.OpenFile(snatConfigFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0664))
fp, err := os.OpenFile(snatConfigFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0o664))
if err == nil {
fp.Write(jsonStr)
fp.Close()
Expand Down
6 changes: 1 addition & 5 deletions cni/network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ var (
win1903Version = 18362
)



/* handleConsecutiveAdd handles consecutive add calls for infrastructure containers on Windows platform.
* This is a temporary work around for issue #57253 of Kubernetes.
* We can delete this if statement once they fix it.
Expand Down Expand Up @@ -289,9 +287,7 @@ func getPoliciesFromRuntimeCfg(nwCfg *cni.NetworkConfig) []policy.Policy {
}

func addIPV6EndpointPolicy(nwInfo network.NetworkInfo) (policy.Policy, error) {
var (
eppolicy policy.Policy
)
var eppolicy policy.Policy

if len(nwInfo.Subnets) < 2 {
return eppolicy, fmt.Errorf("network state doesn't have ipv6 subnet")
Expand Down
3 changes: 1 addition & 2 deletions cnm/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ type errorResponse struct {
}

// Request sent by libnetwork for activation.
type activateRequest struct {
}
type activateRequest struct{}

// Response sent by plugin for activation.
type ActivateResponse struct {
Expand Down
6 changes: 2 additions & 4 deletions cnm/ipam/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const (
)

// Request sent by libnetwork when querying plugin capabilities.
type GetCapabilitiesRequest struct {
}
type GetCapabilitiesRequest struct{}

// Response sent by plugin when registering its capabilities with libnetwork.
type GetCapabilitiesResponse struct {
Expand All @@ -33,8 +32,7 @@ type GetCapabilitiesResponse struct {
}

// Request sent by libnetwork when querying the default address space names.
type GetDefaultAddressSpacesRequest struct {
}
type GetDefaultAddressSpacesRequest struct{}

// Response sent by plugin when returning the default address space names.
type GetDefaultAddressSpacesResponse struct {
Expand Down
45 changes: 24 additions & 21 deletions cnm/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@ import (
"github.com/Azure/azure-container-networking/ipam"
)

var plugin IpamPlugin
var mux *http.ServeMux

var ipamQueryUrl = "localhost:42424"
var ipamQueryResponse = "" +
"<Interfaces>" +
" <Interface MacAddress=\"*\" IsPrimary=\"true\">" +
" <IPSubnet Prefix=\"10.0.0.0/16\">" +
" <IPAddress Address=\"10.0.0.4\" IsPrimary=\"true\"/>" +
" <IPAddress Address=\"10.0.0.5\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.6\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.7\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.8\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.9\" IsPrimary=\"false\"/>" +
" </IPSubnet>" +
" </Interface>" +
"</Interfaces>"

var localAsId string
var poolId1 string
var address1 string
var (
plugin IpamPlugin
mux *http.ServeMux
)

var (
ipamQueryUrl = "localhost:42424"
ipamQueryResponse = "" +
"<Interfaces>" +
" <Interface MacAddress=\"*\" IsPrimary=\"true\">" +
" <IPSubnet Prefix=\"10.0.0.0/16\">" +
" <IPAddress Address=\"10.0.0.4\" IsPrimary=\"true\"/>" +
" <IPAddress Address=\"10.0.0.5\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.6\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.7\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.8\" IsPrimary=\"false\"/>" +
" <IPAddress Address=\"10.0.0.9\" IsPrimary=\"false\"/>" +
" </IPSubnet>" +
" </Interface>" +
"</Interfaces>"
localAsId string
poolId1 string
address1 string
)

// Wraps the test run with plugin setup and teardown.
func TestMain(m *testing.M) {
Expand Down
3 changes: 1 addition & 2 deletions cnm/network/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const (
)

// Request sent by libnetwork when querying plugin capabilities.
type getCapabilitiesRequest struct {
}
type getCapabilitiesRequest struct{}

// Response sent by plugin when registering its capabilities with libnetwork.
type getCapabilitiesResponse struct {
Expand Down
20 changes: 12 additions & 8 deletions cnm/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ import (
remoteApi "github.com/docker/libnetwork/drivers/remote/api"
)

var plugin NetPlugin
var mux *http.ServeMux
var (
plugin NetPlugin
mux *http.ServeMux
)

var anyInterface = "dummy"
var anySubnet = "192.168.1.0/24"
var ipnet = net.IPNet{IP: net.ParseIP("192.168.1.0"), Mask: net.IPv4Mask(255, 255, 255, 0)}
var networkID = "N1"
var netns = "22212"
var (
anyInterface = "dummy"
anySubnet = "192.168.1.0/24"
ipnet = net.IPNet{IP: net.ParseIP("192.168.1.0"), Mask: net.IPv4Mask(255, 255, 255, 0)}
networkID = "N1"
netns = "22212"
)

// endpoint ID must contain 7 characters
var endpointID = "E1-xxxx"
Expand Down Expand Up @@ -178,7 +182,7 @@ func TestCNM(t *testing.T) {
log.Printf("###DeleteEndpoint#####################################################################################")
deleteEndpointT(t)
log.Printf("###DeleteNetwork#####################################################################################")
//deleteNetworkT(t)
// deleteNetworkT(t)
}

// Tests NetworkDriver.CreateNetwork functionality.
Expand Down
4 changes: 2 additions & 2 deletions cnm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (plugin *Plugin) EnableDiscovery() error {

// Create the spec directory.
path := plugin.getSpecPath()
os.MkdirAll(path, 0755)
os.MkdirAll(path, 0o755)

// Write the listener URL to the spec file.
fileName := path + plugin.Name + ".spec"
url := plugin.Listener.URL.String()
err := ioutil.WriteFile(fileName, []byte(url), 0644)
err := ioutil.WriteFile(fileName, []byte(url), 0o644)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cnm/plugin_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (plugin *Plugin) getAPIServerURL() string {
urls = defaultAPIServerURL + plugin.Name + ".sock"
}

os.MkdirAll(pluginSocketPath, 0755)
os.MkdirAll(pluginSocketPath, 0o755)

return urls
}
Expand Down
Loading