CI: Add golint-ci (#888)
* add golint-ci * add gofmt * enable linters * uncap count * fix linting/fmt issues
This commit is contained in:
Родитель
7f2cfc7b74
Коммит
1fa243e5f5
|
@ -0,0 +1 @@
|
|||
*.go text eol=lf
|
|
@ -6,6 +6,8 @@ on:
|
|||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
paths:
|
||||
- 'npm/**'
|
||||
schedule:
|
||||
# run once a day at midnight
|
||||
- cron: '0 0 * * *'
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
name: golangci-lint
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
schedule:
|
||||
# run once a day at midnight
|
||||
- cron: '0 0 * * *'
|
||||
jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.16.x]
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
name: Lint
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.40
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
args: --timeout=5m
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
only-new-issues: true
|
|
@ -0,0 +1,24 @@
|
|||
issues:
|
||||
max-same-issues: 0
|
||||
max-issues-per-linter: 0
|
||||
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- errcheck
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
- golint
|
||||
- gomnd
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- lll
|
||||
- misspell
|
||||
- nakedret
|
|
@ -23,7 +23,6 @@ const (
|
|||
type CNSIPAMInvoker struct {
|
||||
podName string
|
||||
podNamespace string
|
||||
primaryInterfaceName string
|
||||
cnsClient *cnsclient.CNSClient
|
||||
}
|
||||
|
||||
|
@ -54,6 +53,9 @@ func (invoker *CNSIPAMInvoker) Add(nwCfg *cni.NetworkConfig, hostSubnetPrefix *n
|
|||
// Parse Pod arguments.
|
||||
podInfo := cns.KubernetesPodInfo{PodName: invoker.podName, PodNamespace: invoker.podNamespace}
|
||||
orchestratorContext, err := json.Marshal(podInfo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
log.Printf("Requesting IP for pod %v", podInfo)
|
||||
response, err := invoker.cnsClient.RequestIPAddress(orchestratorContext)
|
||||
|
|
|
@ -306,7 +306,6 @@ func (fake *HTTPServiceFake) Start(*common.ServiceConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (fake *HTTPServiceFake) Init(*common.ServiceConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Azure/azure-container-networking/common"
|
||||
"github.com/Azure/azure-container-networking/cnm/ipam"
|
||||
"github.com/Azure/azure-container-networking/common"
|
||||
)
|
||||
|
||||
var mux *http.ServeMux
|
||||
|
|
|
@ -78,7 +78,6 @@ func (pm *CNSIPAMPoolMonitor) Reconcile() error {
|
|||
batchSize := pm.getBatchSize() //Use getters in case customer changes batchsize manually
|
||||
maxIPCount := pm.getMaxIPCount()
|
||||
|
||||
|
||||
msg := fmt.Sprintf("[ipam-pool-monitor] Pool Size: %v, Goal Size: %v, BatchSize: %v, MaxIPCount: %v, MinFree: %v, MaxFree:%v, Allocated: %v, Available: %v, Pending Release: %v, Free: %v, Pending Program: %v",
|
||||
cnsPodIPConfigCount, pm.cachedNNC.Spec.RequestedIPCount, batchSize, maxIPCount, pm.MinimumFreeIps, pm.MaximumFreeIps, allocatedPodIPCount, availableIPConfigCount, pendingReleaseIPCount, freeIPConfigCount, pendingProgramCount)
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ func (r *CrdReconciler) Reconcile(request reconcile.Request) (reconcile.Result,
|
|||
|
||||
logger.Printf("[cns-rc] CRD Spec: %v", nodeNetConfig.Spec)
|
||||
|
||||
|
||||
// If there are no network containers, don't hand it off to CNS
|
||||
if len(nodeNetConfig.Status.NetworkContainers) == 0 {
|
||||
logger.Errorf("[cns-rc] Empty NetworkContainers")
|
||||
|
|
|
@ -512,7 +512,7 @@ func main() {
|
|||
}
|
||||
|
||||
logger.Printf("[Azure CNS] Start HTTP listener")
|
||||
if (httpRestService != nil) {
|
||||
if httpRestService != nil {
|
||||
err = httpRestService.Start(&config)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to start CNS, err:%v.\n", err)
|
||||
|
|
|
@ -5,13 +5,13 @@ package ipam
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Azure/azure-container-networking/common"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
"github.com/Azure/azure-container-networking/common"
|
||||
)
|
||||
|
||||
func TestFileIpam(t *testing.T) {
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
"runtime"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
testclient "k8s.io/client-go/kubernetes/fake"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/Azure/azure-container-networking/common"
|
||||
)
|
||||
|
@ -146,4 +146,3 @@ var (
|
|||
})
|
||||
})
|
||||
)
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ func TestManagerIpv6Ipam(t *testing.T) {
|
|||
RunSpecs(t, "Manager ipv6ipam Suite")
|
||||
}
|
||||
|
||||
|
||||
func createTestIpv6AddressManager() (AddressManager, error) {
|
||||
var config common.PluginConfig
|
||||
var options map[string]interface{}
|
||||
|
|
|
@ -579,7 +579,6 @@ var (
|
|||
})
|
||||
})
|
||||
|
||||
|
||||
Context("When pool is in use and it has ips allocated", func() {
|
||||
It("Should raise an error", func() {
|
||||
as := &addressSpace{
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
package iptm
|
||||
|
||||
import (
|
||||
"os"
|
||||
"golang.org/x/sys/unix"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
||||
func grabIptablesFileLock(f *os.File) error {
|
||||
return unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package npm
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"fmt"
|
||||
"sort"
|
||||
"container/heap"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package npm
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"reflect"
|
||||
"testing"
|
||||
"container/heap"
|
||||
|
||||
"github.com/Azure/azure-container-networking/npm/util"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -89,7 +89,6 @@ func TestGetOperatorAndLabel(t *testing.T) {
|
|||
t.Errorf("TestGetOperatorAndLabel failed @ operator comparison")
|
||||
}
|
||||
|
||||
|
||||
if !reflect.DeepEqual(resultLabels, expectedLabels) {
|
||||
t.Errorf("TestGetOperatorAndLabel failed @ label comparison")
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ func TestReadFileByLines(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestFileExists(t *testing.T) {
|
||||
isExist, err := CheckIfFileExists("testfiles/test1")
|
||||
if err != nil || !isExist {
|
||||
|
|
|
@ -6,12 +6,12 @@ package platform
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"golang.org/x/sys/windows"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/Azure/azure-container-networking/log"
|
||||
)
|
||||
|
|
|
@ -60,7 +60,7 @@ func (fcert *linuxTlsCertificateRetriever) readFile() ([]byte,error) {
|
|||
}
|
||||
|
||||
// Parses a file to PEM format
|
||||
func (fcert *linuxTlsCertificateRetriever) parsePEMFile(content []byte) (error) {
|
||||
func (fcert *linuxTlsCertificateRetriever) parsePEMFile(content []byte) error {
|
||||
pemBlocks := make([]*pem.Block, 0)
|
||||
|
||||
var pemBlock *pem.Block
|
||||
|
|
|
@ -77,7 +77,6 @@ func createPemCertificate(t *testing.T) []byte {
|
|||
t.Fatalf("Could not encode certificate to Pem %+v", err)
|
||||
}
|
||||
|
||||
|
||||
pemCert := pem.EncodeToMemory(&pem.Block{Type: CertLabel, Bytes: derBytes})
|
||||
pemKey := pem.EncodeToMemory(&pem.Block{Type: PrivateKeyLabel, Bytes: privateKeyBytes})
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ func (wtls *windowsTlsCertificateRetriever) readFile() ([]byte,error) {
|
|||
}
|
||||
|
||||
// ParsePEMFile Parses a file to PEM format
|
||||
func (fcert *windowsTlsCertificateRetriever) parsePEMFile(content []byte) (error) {
|
||||
func (fcert *windowsTlsCertificateRetriever) parsePEMFile(content []byte) error {
|
||||
pemBlocks := make([]*pem.Block, 0)
|
||||
|
||||
var pemBlock *pem.Block
|
||||
|
|
|
@ -79,7 +79,6 @@ func createPemCertificate(t *testing.T) []byte {
|
|||
t.Fatalf("Could not encode certificate to Pem %+v", err)
|
||||
}
|
||||
|
||||
|
||||
pemCert := pem.EncodeToMemory(&pem.Block{Type: CertLabel, Bytes: derBytes})
|
||||
pemKey := pem.EncodeToMemory(&pem.Block{Type: PrivateKeyLabel, Bytes: privateKeyBytes})
|
||||
|
||||
|
|
|
@ -139,7 +139,6 @@ func (kvs *jsonFileStore) flush() error {
|
|||
}
|
||||
}()
|
||||
|
||||
|
||||
if _, err = f.Write(buf); err != nil {
|
||||
return fmt.Errorf("Temp file write failed with: %v", err)
|
||||
}
|
||||
|
|
|
@ -50,4 +50,3 @@ func (store *KeyValueStoreMock) GetLockFileName() string {
|
|||
func (store *KeyValueStoreMock) Remove() {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче