diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ee39e96f..7cdd0418 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,8 +9,8 @@ on: - main - 'release-*' env: - RUNC_VERSION: v1.0.0 - GO_VERSION: 1.16.5 + RUNC_VERSION: v1.0.2 + GO_VERSION: 1.16.7 jobs: golangci: @@ -25,7 +25,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: - version: v1.36 + version: v1.42.0 args: --timeout 5m build: diff --git a/.golangci.yml b/.golangci.yml index fcdd1677..4f3c1d3b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,22 +18,19 @@ linters: - godot - gofmt - goimports - - golint - gomodguard - gosimple - gosec - govet - goprintffuncname - ineffassign - - interfacer - - maligned - misspell - nakedret - noctx - nolintlint - prealloc + - revive - rowserrcheck - - scopelint - staticcheck - structcheck - stylecheck diff --git a/Jenkinsfile b/Jenkinsfile index f7a4d9b2..83951ae1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,10 +8,10 @@ pipeline { environment { GO111MODULE="on" REG="cloud-native-image-registry.westus.cloudapp.azure.com/" - RUNC_VERSION="v1.0.0" + RUNC_VERSION="v1.0.2" CRIO_VERSION="v1.20.0" - GOLANGCI_LINT_VERSION="v1.36.0" - GO_VERSION="1.16.5" + GOLANGCI_LINT_VERSION="v1.42.0" + GO_VERSION="1.16.7" GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz" GOROOT="/usr/local/go" GOPATH="/tmp/go" diff --git a/cmd/gpu_plugin/gpu_plugin.go b/cmd/gpu_plugin/gpu_plugin.go index 10519009..f7c166a7 100644 --- a/cmd/gpu_plugin/gpu_plugin.go +++ b/cmd/gpu_plugin/gpu_plugin.go @@ -98,7 +98,7 @@ func newDevicePlugin(sysfsDir, devfsDir string, options cliOptions) *devicePlugi func (dp *devicePlugin) Scan(notifier dpapi.Notifier) error { defer dp.scanTicker.Stop() - var previouslyFound int = -1 + var previouslyFound = -1 for { devTree, err := dp.scan() diff --git a/cmd/gpu_plugin/rm/gpu_plugin_resource_manager.go b/cmd/gpu_plugin/rm/gpu_plugin_resource_manager.go index eddf3021..5fa11d91 100644 --- a/cmd/gpu_plugin/rm/gpu_plugin_resource_manager.go +++ b/cmd/gpu_plugin/rm/gpu_plugin_resource_manager.go @@ -65,7 +65,7 @@ type podCandidate struct { allocationTargetNum int } -type deviceInfo struct { +type DeviceInfo struct { nodes []pluginapi.DeviceSpec mounts []pluginapi.Mount envs map[string]string @@ -88,15 +88,15 @@ type resourceManager struct { prGetClientFunc getClientFunc } -func NewDeviceInfo(nodes []pluginapi.DeviceSpec, mounts []pluginapi.Mount, envs map[string]string) *deviceInfo { - return &deviceInfo{ +func NewDeviceInfo(nodes []pluginapi.DeviceSpec, mounts []pluginapi.Mount, envs map[string]string) *DeviceInfo { + return &DeviceInfo{ nodes: nodes, mounts: mounts, envs: envs, } } -type DeviceInfoMap map[string]*deviceInfo +type DeviceInfoMap map[string]*DeviceInfo func NewDeviceInfoMap() DeviceInfoMap { return DeviceInfoMap{} diff --git a/cmd/operator/main.go b/cmd/operator/main.go index ea96b192..0f621a50 100644 --- a/cmd/operator/main.go +++ b/cmd/operator/main.go @@ -93,7 +93,7 @@ func main() { var metricsAddr string var devicePluginNamespace string var enableLeaderElection bool - var pm *patcher.PatcherManager + var pm *patcher.Manager ctrl.SetLogger(klogr.New()) @@ -146,7 +146,7 @@ func main() { if contains(devices, "sgx") { mgr.GetWebhookServer().Register("/pods-sgx", &webhook.Admission{ - Handler: &sgxwebhook.SgxMutator{Client: mgr.GetClient()}, + Handler: &sgxwebhook.Mutator{Client: mgr.GetClient()}, }) } diff --git a/cmd/sgx_admissionwebhook/main.go b/cmd/sgx_admissionwebhook/main.go index 7ab5f72b..487ec723 100644 --- a/cmd/sgx_admissionwebhook/main.go +++ b/cmd/sgx_admissionwebhook/main.go @@ -60,7 +60,7 @@ func main() { } mgr.GetWebhookServer().Register("/pods-sgx", &webhook.Admission{ - Handler: &sgxwebhook.SgxMutator{Client: mgr.GetClient()}, + Handler: &sgxwebhook.Mutator{Client: mgr.GetClient()}, }) setupLog.Info("starting manager") diff --git a/cmd/vpu_plugin/vpu_plugin.go b/cmd/vpu_plugin/vpu_plugin.go index 49383aed..bdf08903 100644 --- a/cmd/vpu_plugin/vpu_plugin.go +++ b/cmd/vpu_plugin/vpu_plugin.go @@ -90,7 +90,7 @@ func getPciDeviceCounts(sysfsPciDevicesPath string, vendorID string, pidSearch [ // Loop for list of pid of supported device type for _, pidVPU := range pciPid.pids { if vid == vendorID && pid == pidVPU { - found[i] += 1 + found[i]++ } } } diff --git a/cmd/vpu_plugin/vpu_plugin_test.go b/cmd/vpu_plugin/vpu_plugin_test.go index 0110d648..55d51638 100644 --- a/cmd/vpu_plugin/vpu_plugin_test.go +++ b/cmd/vpu_plugin/vpu_plugin_test.go @@ -72,8 +72,8 @@ func createDevice(pciBusRootDir string, bdf string, vid string, pid string) erro } func createTestPCI(folder string, testPCI []PCIPidDeviceType) error { - var busNum int = 1 - var devNum int = 3 + var busNum = 1 + var devNum = 3 //Loop for all supported device type for _, pciPid := range testPCI { //Loop for pid number @@ -83,7 +83,7 @@ func createTestPCI(folder string, testPCI []PCIPidDeviceType) error { if err := createDevice(folder, strconv.Itoa(busNum), vendorIDIntel, pidVPU); err != nil { return err } - busNum += 1 + busNum++ } } } diff --git a/pkg/fpgacontroller/fpgacontroller.go b/pkg/fpgacontroller/fpgacontroller.go index 5c58f18c..4b47475a 100644 --- a/pkg/fpgacontroller/fpgacontroller.go +++ b/pkg/fpgacontroller/fpgacontroller.go @@ -36,7 +36,7 @@ import ( type AcceleratorFunctionReconciler struct { client.Client Scheme *runtime.Scheme - PatcherManager *patcher.PatcherManager + PatcherManager *patcher.Manager } // Reconcile reconciles updates for AcceleratorFunction objects. @@ -71,7 +71,7 @@ func (r *AcceleratorFunctionReconciler) SetupWithManager(mgr ctrl.Manager) error type FpgaRegionReconciler struct { client.Client Scheme *runtime.Scheme - PatcherManager *patcher.PatcherManager + PatcherManager *patcher.Manager } // Reconcile reconciles updates for FpgaRegion objects. diff --git a/pkg/fpgacontroller/patcher/patchermanager.go b/pkg/fpgacontroller/patcher/patchermanager.go index 6121f856..f128c3a7 100644 --- a/pkg/fpgacontroller/patcher/patchermanager.go +++ b/pkg/fpgacontroller/patcher/patchermanager.go @@ -38,22 +38,22 @@ func init() { _ = corev1.AddToScheme(scheme) } -// PatcherManager keeps track of patchers registered for different Kubernetes namespaces. -type PatcherManager struct { +// Manager keeps track of patchers registered for different Kubernetes namespaces. +type Manager struct { log logr.Logger patchers map[string]*patcher } -// NewPatcherManager creates a new PatcherManager. -func NewPatcherManager(log logr.Logger) *PatcherManager { - return &PatcherManager{ +// NewPatcherManager creates a new Manager. +func NewPatcherManager(log logr.Logger) *Manager { + return &Manager{ log: log, patchers: make(map[string]*patcher), } } // GetPatcher returns a patcher specific to given namespace. -func (pm *PatcherManager) GetPatcher(namespace string) *patcher { +func (pm *Manager) GetPatcher(namespace string) *patcher { if p, ok := pm.patchers[namespace]; ok { return p } @@ -67,13 +67,13 @@ func (pm *PatcherManager) GetPatcher(namespace string) *patcher { // GetPodMutator returns a handler function replacing FPGA resource names with // real FPGA resources in pods. -func (pm *PatcherManager) GetPodMutator() func(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse { +func (pm *Manager) GetPodMutator() func(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse { return pm.mutate } // +kubebuilder:webhook:verbs=create;update,path=/pods,mutating=true,failurePolicy=Ignore,groups="",resources=pods,versions=v1,name=fpga.mutator.webhooks.intel.com,sideEffects=None,admissionReviewVersions=v1 -func (pm *PatcherManager) mutate(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse { +func (pm *Manager) mutate(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse { podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"} if req.Resource != podResource { err := errors.Errorf("unexpected resource type %q", req.Resource) diff --git a/pkg/fpgacontroller/patcher/patchermanager_test.go b/pkg/fpgacontroller/patcher/patchermanager_test.go index 35d2afbf..a973458a 100644 --- a/pkg/fpgacontroller/patcher/patchermanager_test.go +++ b/pkg/fpgacontroller/patcher/patchermanager_test.go @@ -40,7 +40,7 @@ func TestGetPatcher(t *testing.T) { namespace := "test" tcases := []struct { name string - pm *PatcherManager + pm *Manager }{ { name: "Create new patcher", @@ -48,7 +48,7 @@ func TestGetPatcher(t *testing.T) { }, { name: "Return existing patcher", - pm: &PatcherManager{patchers: map[string]*patcher{namespace: newPatcher(log)}}, + pm: &Manager{patchers: map[string]*patcher{namespace: newPatcher(log)}}, }, } for _, tt := range tcases { diff --git a/pkg/webhooks/sgx/sgx.go b/pkg/webhooks/sgx/sgx.go index b99d105c..3866afc7 100644 --- a/pkg/webhooks/sgx/sgx.go +++ b/pkg/webhooks/sgx/sgx.go @@ -29,8 +29,8 @@ import ( // +kubebuilder:webhook:path=/pods-sgx,mutating=true,failurePolicy=ignore,groups="",resources=pods,verbs=create;update,versions=v1,name=sgx.mutator.webhooks.intel.com,sideEffects=None,admissionReviewVersions=v1 -// SgxMutator annotates Pods. -type SgxMutator struct { +// Mutator annotates Pods. +type Mutator struct { Client client.Client decoder *admission.Decoder } @@ -97,7 +97,7 @@ func warnWrongResources(resources map[string]int64) []string { } // Handle implements controller-runtimes's admission.Handler inteface. -func (s *SgxMutator) Handle(ctx context.Context, req admission.Request) admission.Response { +func (s *Mutator) Handle(ctx context.Context, req admission.Request) admission.Response { pod := &corev1.Pod{} if err := s.decoder.Decode(req, pod); err != nil { @@ -214,7 +214,7 @@ func (s *SgxMutator) Handle(ctx context.Context, req admission.Request) admissio // InjectDecoder implements controller-runtime's admission.DecoderInjector interface. // A decoder will be automatically injected. -func (s *SgxMutator) InjectDecoder(d *admission.Decoder) error { +func (s *Mutator) InjectDecoder(d *admission.Decoder) error { s.decoder = d return nil }