Skip to content

Commit

Permalink
chore: automated lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
  • Loading branch information
rbtr committed Jan 3, 2024
1 parent ad10662 commit f4c0aa3
Show file tree
Hide file tree
Showing 75 changed files with 252 additions and 255 deletions.
2 changes: 1 addition & 1 deletion aitelemetry/telemetrywrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (th *telemetryHandle) Close(timeout int) {
// wait for items to be sent otherwise timeout
<-th.client.Channel().Close(time.Duration(timeout) * time.Second)

// Remove diganostic message listener
// Remove diagnostic message listener
if th.diagListener != nil {
th.diagListener.Remove()
th.diagListener = nil
Expand Down
2 changes: 1 addition & 1 deletion cni/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ var (
})

Context("When pool is not use", func() {
It("Confirm pool was released by succesfully requesting pool", func() {
It("Confirm pool was released by successfully requesting pool", func() {
arg.StdinData = getStdinData("0.4.0", "", "")
err = plugin.Add(arg)
Expect(err).ShouldNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion cni/network/multitenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (m *Multitenancy) DetermineSnatFeatureOnHost(snatFile, nmAgentSupportedApis
// If we weren't able to retrieve snatConfiguration, query NMAgent
if retrieveSnatConfigErr != nil {
var resp *http.Response
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, nmAgentSupportedApisURL, nil)
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, nmAgentSupportedApisURL, http.NoBody)
if err != nil {
logger.Error("failed creating http request", zap.Error(err))
return false, false, fmt.Errorf("%w", err)
Expand Down
14 changes: 7 additions & 7 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,15 +1321,15 @@ func convertNnsToIPConfigs(
// method of ADD method
var ipConfigs []*network.IPConfig

if netRes.Interfaces != nil {
for _, ni := range netRes.Interfaces {
for _, ip := range ni.Ipaddresses {
ipAddr := net.ParseIP(ip.Ip)
if netRes.GetInterfaces() != nil {
for _, ni := range netRes.GetInterfaces() {
for _, ip := range ni.GetIpaddresses() {
ipAddr := net.ParseIP(ip.GetIp())

prefixLength, err := strconv.Atoi(ip.PrefixLength)
prefixLength, err := strconv.Atoi(ip.GetPrefixLength())
if err != nil {
logger.Error("Error parsing prefix length while converting to cni result",
zap.String("prefixLength", ip.PrefixLength),
zap.String("prefixLength", ip.GetPrefixLength()),
zap.String("operation", operationName),
zap.String("pod", podName),
zap.Error(err))
Expand All @@ -1345,7 +1345,7 @@ func convertNnsToIPConfigs(
address.Mask = net.CIDRMask(prefixLength, ipv4FullMask)
}

gateway := net.ParseIP(ip.DefaultGateway)
gateway := net.ParseIP(ip.GetDefaultGateway())

ipConfigs = append(ipConfigs, &network.IPConfig{
Address: address,
Expand Down
6 changes: 3 additions & 3 deletions cnm/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func decodeResponse(w *httptest.ResponseRecorder, response interface{}) error {
func TestActivate(t *testing.T) {
var resp cnm.ActivateResponse

req, err := http.NewRequest(http.MethodGet, "/Plugin.Activate", nil)
req, err := http.NewRequest(http.MethodGet, "/Plugin.Activate", http.NoBody)
if err != nil {
t.Fatal(err)
}
Expand All @@ -142,7 +142,7 @@ func TestActivate(t *testing.T) {
func TestGetCapabilities(t *testing.T) {
var resp GetCapabilitiesResponse

req, err := http.NewRequest(http.MethodGet, GetCapabilitiesPath, nil)
req, err := http.NewRequest(http.MethodGet, GetCapabilitiesPath, http.NoBody)
if err != nil {
t.Fatal(err)
}
Expand All @@ -161,7 +161,7 @@ func TestGetCapabilities(t *testing.T) {
func TestGetDefaultAddressSpaces(t *testing.T) {
var resp GetDefaultAddressSpacesResponse

req, err := http.NewRequest(http.MethodGet, GetAddressSpacesPath, nil)
req, err := http.NewRequest(http.MethodGet, GetAddressSpacesPath, http.NoBody)

Check failure on line 164 in cnm/ipam/ipam_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cnm/network/network_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func decodeResponse(w *httptest.ResponseRecorder, response interface{}) error {
func TestActivate(t *testing.T) {
var resp cnm.ActivateResponse

req, err := http.NewRequest(http.MethodGet, "/Plugin.Activate", nil)
req, err := http.NewRequest(http.MethodGet, "/Plugin.Activate", http.NoBody)
if err != nil {
t.Fatal(err)
}
Expand All @@ -143,7 +143,7 @@ func TestActivate(t *testing.T) {
func TestGetCapabilities(t *testing.T) {
var resp remoteApi.GetCapabilityResponse

req, err := http.NewRequest(http.MethodGet, getCapabilitiesPath, nil)
req, err := http.NewRequest(http.MethodGet, getCapabilitiesPath, http.NoBody)
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions cnm/plugin_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build linux
// +build linux

package cnm
Expand Down
12 changes: 6 additions & 6 deletions cnms/cnmspackage/monitor2rules_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (networkMonitor *NetworkMonitor) deleteRulesNotExistInMap(chainRules map[st
// addRulesNotExistInMap adds rules to nat Ebtable if rule was in stateRules and not in current chain rules after a certain number of iterations.
func (networkMonitor *NetworkMonitor) addRulesNotExistInMap(
stateRules map[string]string,
chainRules map[string]string) {

chainRules map[string]string,
) {
table := ebtables.Nat
action := ebtables.Append

Expand All @@ -63,8 +63,8 @@ func (networkMonitor *NetworkMonitor) addRulesNotExistInMap(
// CreateRequiredL2Rules finds the rules that should be in nat ebtable based on state.
func (networkMonitor *NetworkMonitor) CreateRequiredL2Rules(
currentEbtableRulesMap map[string]string,
currentStateRulesMap map[string]string) error {

currentStateRulesMap map[string]string,
) error {
for rule := range networkMonitor.AddRulesToBeValidated {
if _, ok := currentStateRulesMap[rule]; !ok {
delete(networkMonitor.AddRulesToBeValidated, rule)
Expand All @@ -79,8 +79,8 @@ func (networkMonitor *NetworkMonitor) CreateRequiredL2Rules(
// RemoveInvalidL2Rules removes rules that should not be in nat ebtable based on state.
func (networkMonitor *NetworkMonitor) RemoveInvalidL2Rules(
currentEbtableRulesMap map[string]string,
currentStateRulesMap map[string]string) error {

currentStateRulesMap map[string]string,
) error {
for rule := range networkMonitor.DeleteRulesToBeValidated {
if _, ok := currentEbtableRulesMap[rule]; !ok {
delete(networkMonitor.DeleteRulesToBeValidated, rule)
Expand Down
18 changes: 9 additions & 9 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,15 @@ func (u UnpublishNetworkContainerResponse) String() string {

// ValidAclPolicySetting - Used to validate ACL policy
type ValidAclPolicySetting struct {
Protocols string `json:","`
Action string `json:","`
Direction string `json:","`
LocalAddresses string `json:","`
RemoteAddresses string `json:","`
LocalPorts string `json:","`
RemotePorts string `json:","`
RuleType string `json:","`
Priority uint16 `json:","`
Protocols string `json:""`
Action string `json:""`
Direction string `json:""`
LocalAddresses string `json:""`
RemoteAddresses string `json:""`
LocalPorts string `json:""`
RemotePorts string `json:""`
RuleType string `json:""`
Priority uint16 `json:""`
}

const (
Expand Down
6 changes: 3 additions & 3 deletions cns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ type CreateHnsNetworkRequest struct {
AutomaticDNS bool `json:",omitempty"`
}

// SubnetInfo is assoicated with HNS network and represents a list
// SubnetInfo is associated with HNS network and represents a list
// of subnets available to the network
type SubnetInfo struct {
AddressPrefix string
GatewayAddress string
Policies []json.RawMessage `json:",omitempty"`
}

// MacPool is assoicated with HNS network and represents a list
// MacPool is associated with HNS network and represents a list
// of macaddresses available to the network
type MacPool struct {
StartMacAddress string
Expand Down Expand Up @@ -263,7 +263,7 @@ type GetIPAddressesResponse struct {
IPAddresses []string
}

// HostLocalIPAddressResponse describes reponse that returns the host local IP Address.
// HostLocalIPAddressResponse describes response that returns the host local IP Address.
type HostLocalIPAddressResponse struct {
Response Response
IPAddress string
Expand Down
4 changes: 2 additions & 2 deletions cns/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func (c *Client) GetIPAddressesMatchingStates(ctx context.Context, stateFilter .
// GetPodOrchestratorContext calls GetPodIpOrchestratorContext API on CNS
func (c *Client) GetPodOrchestratorContext(ctx context.Context) (map[string][]string, error) {
u := c.routes[cns.PathDebugPodContext]
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)
if err != nil {
return nil, errors.Wrap(err, "failed to build request")
}
Expand Down Expand Up @@ -565,7 +565,7 @@ func (c *Client) GetPodOrchestratorContext(ctx context.Context) (map[string][]st
// GetHTTPServiceData gets all public in-memory struct details for debugging purpose
func (c *Client) GetHTTPServiceData(ctx context.Context) (*restserver.GetHTTPServiceDataResponse, error) {
u := c.routes[cns.PathDebugRestData]
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)
if err != nil {
return nil, errors.Wrap(err, "failed to build request")
}
Expand Down
2 changes: 1 addition & 1 deletion cns/dockerclient/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type NetworkConfiguration struct {
Options map[string]interface{}
}

// DockerErrorResponse defines the error response retunred by docker.
// DockerErrorResponse defines the error response returned by docker.
type DockerErrorResponse struct {
message string
}
2 changes: 1 addition & 1 deletion cns/dockerclient/dockerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *Client) DeleteNetwork(networkName string) error {
logger.Printf("[Azure CNS] DeleteNetwork")

url := c.connectionURL + inspectNetworkPath + networkName
req, err := http.NewRequest("DELETE", url, nil)
req, err := http.NewRequest("DELETE", url, http.NoBody)

Check failure on line 155 in cns/dockerclient/dockerclient.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx)
if err != nil {
logger.Printf("[Azure CNS] Error received while creating http DELETE request for network delete %v %v", networkName, err.Error())
return err
Expand Down
1 change: 1 addition & 0 deletions cns/dockerclient/dockerclient_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build linux
// +build linux

package dockerclient
Expand Down
6 changes: 4 additions & 2 deletions cns/hnsclient/hnsclient_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ func CreateHostNCApipaEndpoint(
localIPConfiguration cns.IPConfiguration,
allowNCToHostCommunication bool,
allowHostToNCCommunication bool,
ncPolicies []cns.NetworkContainerRequestPolicies) (string, error) {
ncPolicies []cns.NetworkContainerRequestPolicies,

Check warning on line 42 in cns/hnsclient/hnsclient_linux.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

unused-parameter: parameter 'ncPolicies' seems to be unused, consider removing or renaming it as _ (revive)
) (string, error) {
return "", nil
}

// DeleteHostNCApipaEndpoint deletes the endpoint in the apipa network
// created for host container connectivity
// This is windows platform specific.
func DeleteHostNCApipaEndpoint(
networkContainerID string) error {
networkContainerID string,

Check warning on line 51 in cns/hnsclient/hnsclient_linux.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

unused-parameter: parameter 'networkContainerID' seems to be unused, consider removing or renaming it as _ (revive)
) error {
return nil
}
10 changes: 5 additions & 5 deletions cns/ipamclient/ipamclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (ic *IpamClient) GetAddressSpace() (string, error) {

if resp.Err != "" {
log.Printf("[Azure CNS] GetAddressSpace received error response :%v", resp.Err)
return "", fmt.Errorf(resp.Err)
return "", errors.New(resp.Err)
}

return resp.LocalDefaultAddressSpace, nil
Expand Down Expand Up @@ -103,7 +103,7 @@ func (ic *IpamClient) GetPoolID(asID, subnet string) (string, error) {

if resp.Err != "" {
log.Printf("[Azure CNS] GetPoolID received error response :%v", resp.Err)
return "", fmt.Errorf(resp.Err)
return "", errors.New(resp.Err)
}

return resp.PoolID, nil
Expand Down Expand Up @@ -151,7 +151,7 @@ func (ic *IpamClient) ReserveIPAddress(poolID string, reservationID string) (str

if reserveResp.Err != "" {
log.Printf("[Azure CNS] ReserveIP received error response :%v", reserveResp.Err)
return "", fmt.Errorf(reserveResp.Err)
return "", errors.New(reserveResp.Err)
}

return reserveResp.Address, nil
Expand Down Expand Up @@ -201,7 +201,7 @@ func (ic *IpamClient) ReleaseIPAddress(poolID string, reservationID string) erro

if releaseResp.Err != "" {
log.Printf("[Azure CNS] ReleaseIP received error response :%v", releaseResp.Err)
return fmt.Errorf(releaseResp.Err)
return errors.New(releaseResp.Err)
}

return nil
Expand Down Expand Up @@ -245,7 +245,7 @@ func (ic *IpamClient) GetIPAddressUtilization(poolID string) (int, int, []string

if poolInfoResp.Err != "" {
log.Printf("[Azure CNS] GetIPUtilization received error response :%v", poolInfoResp.Err)
return 0, 0, nil, fmt.Errorf(poolInfoResp.Err)
return 0, 0, nil, errors.New(poolInfoResp.Err)
}

return poolInfoResp.Capacity, poolInfoResp.Available, poolInfoResp.UnhealthyAddresses, nil
Expand Down
1 change: 1 addition & 0 deletions cns/ipamclient/ipamclient_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build linux
// +build linux

package ipamclient
Expand Down
2 changes: 1 addition & 1 deletion cns/networkcontainers/networkcontainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func execPlugin(rt *libcni.RuntimeConf, netconf []byte, operation, path string)
environ := args(operation, path, rt).AsEnv()
logger.Printf("[Azure CNS] CNI called with environ variables %v", environ)
stdout := &bytes.Buffer{}
command := exec.Command(path + string(os.PathSeparator) + "azure-vnet")
command := exec.Command(filepath.Join(path, "azure-vnet"))
command.Env = environ
command.Stdin = bytes.NewBuffer(netconf)
command.Stdout = stdout
Expand Down
4 changes: 2 additions & 2 deletions cns/restserver/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func TestGetNumOfCPUCores(t *testing.T) {
req *http.Request
)

req, err = http.NewRequest(http.MethodGet, cns.NumberOfCPUCoresPath, nil)
req, err = http.NewRequest(http.MethodGet, cns.NumberOfCPUCoresPath, http.NoBody)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1030,7 +1030,7 @@ func publishNCViaCNS(
}
}

fmt.Printf("PublishNetworkContainer succeded with response %+v, raw:%+v\n", resp, w.Body)
fmt.Printf("PublishNetworkContainer succeeded with response %+v, raw:%+v\n", resp, w.Body)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/internalapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,

// try to retrieve NodeInfoResponse from mDNC
url := fmt.Sprintf(common.SyncNodeNetworkContainersURLFmt, dncEP, infraVnet, nodeID, dncApiVersion)
req, _ := http.NewRequestWithContext(context.TODO(), http.MethodGet, url, nil)
req, _ := http.NewRequestWithContext(context.TODO(), http.MethodGet, url, http.NoBody)
resp, err := httpc.Do(req)
if err == nil {
if resp.StatusCode == http.StatusOK {
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/internalapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestCreateAndUpdateNCWithSecondaryIPNCVersion(t *testing.T) {
// Validate secondary IPs' NC version has been updated by NC request
receivedSecondaryIPConfigs := containerStatus.CreateNetworkContainerRequest.SecondaryIPConfigs
if len(receivedSecondaryIPConfigs) != 1 {
t.Fatalf("receivedSecondaryIPConfigs lenth must be 1, but recieved %d", len(receivedSecondaryIPConfigs))
t.Fatalf("receivedSecondaryIPConfigs lenth must be 1, but received %d", len(receivedSecondaryIPConfigs))
}
for _, secIPConfig := range receivedSecondaryIPConfigs {
if secIPConfig.IPAddress != "10.0.0.16" || secIPConfig.NCVersion != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (service *HTTPRestService) saveNetworkContainerGoalState(req cns.CreateNetw
}
if hostVersion == "" {
// Host version is the NC version from NMAgent, set it -1 to indicate no result from NMAgent yet.
// TODO, query NMAgent and with aggresive time out and assign latest host version.
// TODO, query NMAgent and with aggressive time out and assign latest host version.
hostVersion = "-1"
}

Expand Down
1 change: 1 addition & 0 deletions cns/routes/routes_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build linux
// +build linux

package routes
Expand Down
2 changes: 1 addition & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ var args = acn.ArgumentList{
Shorthand: acn.OptNetPluginConfigFileAlias,
Description: "Set network plugin configuration file absolute path",
Type: "string",
DefaultValue: platform.K8SNetConfigPath + string(os.PathSeparator) + defaultCNINetworkConfigFileName,
DefaultValue: filepath.Join(platform.K8SNetConfigPath, defaultCNINetworkConfigFileName),

Check failure on line 222 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

undefined: filepath (typecheck)
},
{
Name: acn.OptCreateDefaultExtNetworkType,
Expand Down
2 changes: 1 addition & 1 deletion common/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func printErrorForArg(arg *Argument) {
// printHelpForArg prints the help line for the given argument.
func printHelpForArg(arg *Argument) {
left := fmt.Sprintf(" -%v, --%v", arg.Shorthand, arg.Name)
right := fmt.Sprintf("%v", arg.Description)
right := arg.Description

if arg.ValueMap != nil {
left += fmt.Sprintf("=%v", arg.DefaultValue)
Expand Down
Loading

0 comments on commit f4c0aa3

Please sign in to comment.