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
- '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:

View File

@ -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

6
Jenkinsfile vendored
View File

@ -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"

View File

@ -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()

View File

@ -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{}

View File

@ -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()},
})
}

View File

@ -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")

View File

@ -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]++
}
}
}

View File

@ -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++
}
}
}

View File

@ -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.

View File

@ -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)

View File

@ -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 {

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
// 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
}