Update tool versions and fix errors and warnings that originated from the update

Update tool versions
Fix the errors and warnings originated from the update:
-Correct type deviceInfo (->DeviceInfo) to make it public
-Fix gpu_plugin.go and vpu_plugin_test.go where stylecheck errors occur
-Fix deprecation warnings
-Rename type 'PatcherManager' to 'Manager' to solve exported errors
-Rename type 'SgxMutator' to 'Mutator' to solve exported errors

Signed-off-by: Hyeongju Johannes Lee <hyeongju.lee@intel.com>
This commit is contained in:
Hyeongju Johannes Lee 2021-08-20 10:22:33 +00:00
parent 48d4ec4986
commit 09ba9fde00
13 changed files with 35 additions and 38 deletions

View File

@ -9,8 +9,8 @@ on:
- main - main
- 'release-*' - 'release-*'
env: env:
RUNC_VERSION: v1.0.0 RUNC_VERSION: v1.0.2
GO_VERSION: 1.16.5 GO_VERSION: 1.16.7
jobs: jobs:
golangci: golangci:
@ -25,7 +25,7 @@ jobs:
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
version: v1.36 version: v1.42.0
args: --timeout 5m args: --timeout 5m
build: build:

View File

@ -18,22 +18,19 @@ linters:
- godot - godot
- gofmt - gofmt
- goimports - goimports
- golint
- gomodguard - gomodguard
- gosimple - gosimple
- gosec - gosec
- govet - govet
- goprintffuncname - goprintffuncname
- ineffassign - ineffassign
- interfacer
- maligned
- misspell - misspell
- nakedret - nakedret
- noctx - noctx
- nolintlint - nolintlint
- prealloc - prealloc
- revive
- rowserrcheck - rowserrcheck
- scopelint
- staticcheck - staticcheck
- structcheck - structcheck
- stylecheck - stylecheck

6
Jenkinsfile vendored
View File

@ -8,10 +8,10 @@ pipeline {
environment { environment {
GO111MODULE="on" GO111MODULE="on"
REG="cloud-native-image-registry.westus.cloudapp.azure.com/" REG="cloud-native-image-registry.westus.cloudapp.azure.com/"
RUNC_VERSION="v1.0.0" RUNC_VERSION="v1.0.2"
CRIO_VERSION="v1.20.0" CRIO_VERSION="v1.20.0"
GOLANGCI_LINT_VERSION="v1.36.0" GOLANGCI_LINT_VERSION="v1.42.0"
GO_VERSION="1.16.5" GO_VERSION="1.16.7"
GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz" GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz"
GOROOT="/usr/local/go" GOROOT="/usr/local/go"
GOPATH="/tmp/go" GOPATH="/tmp/go"

View File

@ -98,7 +98,7 @@ func newDevicePlugin(sysfsDir, devfsDir string, options cliOptions) *devicePlugi
func (dp *devicePlugin) Scan(notifier dpapi.Notifier) error { func (dp *devicePlugin) Scan(notifier dpapi.Notifier) error {
defer dp.scanTicker.Stop() defer dp.scanTicker.Stop()
var previouslyFound int = -1 var previouslyFound = -1
for { for {
devTree, err := dp.scan() devTree, err := dp.scan()

View File

@ -65,7 +65,7 @@ type podCandidate struct {
allocationTargetNum int allocationTargetNum int
} }
type deviceInfo struct { type DeviceInfo struct {
nodes []pluginapi.DeviceSpec nodes []pluginapi.DeviceSpec
mounts []pluginapi.Mount mounts []pluginapi.Mount
envs map[string]string envs map[string]string
@ -88,15 +88,15 @@ type resourceManager struct {
prGetClientFunc getClientFunc prGetClientFunc getClientFunc
} }
func NewDeviceInfo(nodes []pluginapi.DeviceSpec, mounts []pluginapi.Mount, envs map[string]string) *deviceInfo { func NewDeviceInfo(nodes []pluginapi.DeviceSpec, mounts []pluginapi.Mount, envs map[string]string) *DeviceInfo {
return &deviceInfo{ return &DeviceInfo{
nodes: nodes, nodes: nodes,
mounts: mounts, mounts: mounts,
envs: envs, envs: envs,
} }
} }
type DeviceInfoMap map[string]*deviceInfo type DeviceInfoMap map[string]*DeviceInfo
func NewDeviceInfoMap() DeviceInfoMap { func NewDeviceInfoMap() DeviceInfoMap {
return DeviceInfoMap{} return DeviceInfoMap{}

View File

@ -93,7 +93,7 @@ func main() {
var metricsAddr string var metricsAddr string
var devicePluginNamespace string var devicePluginNamespace string
var enableLeaderElection bool var enableLeaderElection bool
var pm *patcher.PatcherManager var pm *patcher.Manager
ctrl.SetLogger(klogr.New()) ctrl.SetLogger(klogr.New())
@ -146,7 +146,7 @@ func main() {
if contains(devices, "sgx") { if contains(devices, "sgx") {
mgr.GetWebhookServer().Register("/pods-sgx", &webhook.Admission{ mgr.GetWebhookServer().Register("/pods-sgx", &webhook.Admission{
Handler: &sgxwebhook.SgxMutator{Client: mgr.GetClient()}, Handler: &sgxwebhook.Mutator{Client: mgr.GetClient()},
}) })
} }

View File

@ -60,7 +60,7 @@ func main() {
} }
mgr.GetWebhookServer().Register("/pods-sgx", &webhook.Admission{ mgr.GetWebhookServer().Register("/pods-sgx", &webhook.Admission{
Handler: &sgxwebhook.SgxMutator{Client: mgr.GetClient()}, Handler: &sgxwebhook.Mutator{Client: mgr.GetClient()},
}) })
setupLog.Info("starting manager") setupLog.Info("starting manager")

View File

@ -90,7 +90,7 @@ func getPciDeviceCounts(sysfsPciDevicesPath string, vendorID string, pidSearch [
// Loop for list of pid of supported device type // Loop for list of pid of supported device type
for _, pidVPU := range pciPid.pids { for _, pidVPU := range pciPid.pids {
if vid == vendorID && pid == pidVPU { if vid == vendorID && pid == pidVPU {
found[i] += 1 found[i]++
} }
} }
} }

View File

@ -72,8 +72,8 @@ func createDevice(pciBusRootDir string, bdf string, vid string, pid string) erro
} }
func createTestPCI(folder string, testPCI []PCIPidDeviceType) error { func createTestPCI(folder string, testPCI []PCIPidDeviceType) error {
var busNum int = 1 var busNum = 1
var devNum int = 3 var devNum = 3
//Loop for all supported device type //Loop for all supported device type
for _, pciPid := range testPCI { for _, pciPid := range testPCI {
//Loop for pid number //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 { if err := createDevice(folder, strconv.Itoa(busNum), vendorIDIntel, pidVPU); err != nil {
return err return err
} }
busNum += 1 busNum++
} }
} }
} }

View File

@ -36,7 +36,7 @@ import (
type AcceleratorFunctionReconciler struct { type AcceleratorFunctionReconciler struct {
client.Client client.Client
Scheme *runtime.Scheme Scheme *runtime.Scheme
PatcherManager *patcher.PatcherManager PatcherManager *patcher.Manager
} }
// Reconcile reconciles updates for AcceleratorFunction objects. // Reconcile reconciles updates for AcceleratorFunction objects.
@ -71,7 +71,7 @@ func (r *AcceleratorFunctionReconciler) SetupWithManager(mgr ctrl.Manager) error
type FpgaRegionReconciler struct { type FpgaRegionReconciler struct {
client.Client client.Client
Scheme *runtime.Scheme Scheme *runtime.Scheme
PatcherManager *patcher.PatcherManager PatcherManager *patcher.Manager
} }
// Reconcile reconciles updates for FpgaRegion objects. // Reconcile reconciles updates for FpgaRegion objects.

View File

@ -38,22 +38,22 @@ func init() {
_ = corev1.AddToScheme(scheme) _ = corev1.AddToScheme(scheme)
} }
// PatcherManager keeps track of patchers registered for different Kubernetes namespaces. // Manager keeps track of patchers registered for different Kubernetes namespaces.
type PatcherManager struct { type Manager struct {
log logr.Logger log logr.Logger
patchers map[string]*patcher patchers map[string]*patcher
} }
// NewPatcherManager creates a new PatcherManager. // NewPatcherManager creates a new Manager.
func NewPatcherManager(log logr.Logger) *PatcherManager { func NewPatcherManager(log logr.Logger) *Manager {
return &PatcherManager{ return &Manager{
log: log, log: log,
patchers: make(map[string]*patcher), patchers: make(map[string]*patcher),
} }
} }
// GetPatcher returns a patcher specific to given namespace. // 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 { if p, ok := pm.patchers[namespace]; ok {
return p return p
} }
@ -67,13 +67,13 @@ func (pm *PatcherManager) GetPatcher(namespace string) *patcher {
// GetPodMutator returns a handler function replacing FPGA resource names with // GetPodMutator returns a handler function replacing FPGA resource names with
// real FPGA resources in pods. // 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 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 // +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"} podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
if req.Resource != podResource { if req.Resource != podResource {
err := errors.Errorf("unexpected resource type %q", req.Resource) err := errors.Errorf("unexpected resource type %q", req.Resource)

View File

@ -40,7 +40,7 @@ func TestGetPatcher(t *testing.T) {
namespace := "test" namespace := "test"
tcases := []struct { tcases := []struct {
name string name string
pm *PatcherManager pm *Manager
}{ }{
{ {
name: "Create new patcher", name: "Create new patcher",
@ -48,7 +48,7 @@ func TestGetPatcher(t *testing.T) {
}, },
{ {
name: "Return existing patcher", 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 { for _, tt := range tcases {

View File

@ -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 // +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. // Mutator annotates Pods.
type SgxMutator struct { type Mutator struct {
Client client.Client Client client.Client
decoder *admission.Decoder decoder *admission.Decoder
} }
@ -97,7 +97,7 @@ func warnWrongResources(resources map[string]int64) []string {
} }
// Handle implements controller-runtimes's admission.Handler inteface. // 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{} pod := &corev1.Pod{}
if err := s.decoder.Decode(req, pod); err != nil { 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. // InjectDecoder implements controller-runtime's admission.DecoderInjector interface.
// A decoder will be automatically injected. // 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 s.decoder = d
return nil return nil
} }