Skip to content

Commit

Permalink
chore: Upgrade Golang version from 1.17 to 1.19 (#68)
Browse files Browse the repository at this point in the history
- Remove the linters for "deadcode", "structcheck", "varcheck"
- Use "os" packages instead of deprecated "io/ioutil" (SA1019)
- Capture pre-commit output in a local log file

Fixes #64

---------

Signed-off-by: Spolti <[email protected]>
  • Loading branch information
spolti authored Nov 30, 2023
1 parent b61efb4 commit 0ba2f47
Show file tree
Hide file tree
Showing 82 changed files with 169 additions and 161 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
.DS_Store
Dockerfile
temp
.pre-commit.log

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
*.iml

public/

.pre-commit.log

3 changes: 0 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,13 @@ linters:
fast: false
enable:
# These are the defaults for golangci-lint
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

# Also enable these
- goconst
Expand Down
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.43.0
rev: v1.51.1
hooks:
- id: golangci-lint
log_file: .pre-commit.log
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.4.1
hooks:
- id: prettier
log_file: .pre-commit.log
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
###############################################################################
# Stage 1: Create the developer image for the BUILDPLATFORM only
###############################################################################
ARG GOLANG_VERSION=1.17
ARG GOLANG_VERSION=1.19
FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION AS develop

ARG PROTOC_VERSION=21.5
Expand Down Expand Up @@ -93,6 +93,8 @@ RUN true \
COPY .pre-commit-config.yaml ./
RUN git init && \
pre-commit install-hooks && \
# Fix: 'fatal: detected dubious ownership in repository' \
git config --global --add safe.directory "*" && \
rm -rf .git

# Download dependencies before copying the source so they will be cached
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kserve/modelmesh-runtime-adapter

go 1.17
go 1.19

require (
cloud.google.com/go/storage v1.28.1
Expand All @@ -12,7 +12,7 @@ require (
github.com/go-logr/zapr v1.2.3
github.com/golang/mock v1.6.0
github.com/joho/godotenv v1.4.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.23.0
golang.org/x/sync v0.1.0
google.golang.org/api v0.114.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down
6 changes: 3 additions & 3 deletions internal/modelschema/modelschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,7 +16,7 @@ package modelschema
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

// Filename for the schema JSON
Expand Down Expand Up @@ -55,7 +55,7 @@ const (
)

func NewFromFile(schemaFilename string) (*ModelSchema, error) {
jsonBytes, err := ioutil.ReadFile(schemaFilename)
jsonBytes, err := os.ReadFile(schemaFilename)
if err != nil {
return nil, fmt.Errorf("Unable to read model schema file %s: %w", schemaFilename, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/util/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion internal/util/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
6 changes: 3 additions & 3 deletions internal/util/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -22,7 +22,7 @@ import (

// RemoveFileFromListOfFileInfo
// The input `files` content is modified, the order of elements is changed
func RemoveFileFromListOfFileInfo(filename string, files []os.FileInfo) (bool, []os.FileInfo) {
func RemoveFileFromListOfFileInfo(filename string, files []os.DirEntry) (bool, []os.DirEntry) {
var fileIndex int = -1
for i, f := range files {
if f.Name() == filename {
Expand All @@ -49,7 +49,7 @@ func FileExists(path string) (bool, error) {
}
}

// Clear contents of directory if it exists.
// ClearDirectoryContents Clear contents of directory if it exists.
// If condition is specified then only delete dir entries to which it returns true
func ClearDirectoryContents(dirPath string, condition func(entry os.DirEntry) bool) error {
files, err := os.ReadDir(dirPath)
Expand Down
2 changes: 1 addition & 1 deletion internal/util/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion internal/util/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion internal/util/loadmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion model-mesh-mlserver-adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
11 changes: 5 additions & 6 deletions model-mesh-mlserver-adapter/server/adaptmodellayout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,7 +16,6 @@ package server
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (tt adaptModelLayoutTestCase) writeConfigFile(t *testing.T) {
if jerr != nil {
t.Fatal("Error marshalling config JSON", jerr)
}
if err := ioutil.WriteFile(configFullPath, jsonBytes, 0644); err != nil {
if err := os.WriteFile(configFullPath, jsonBytes, 0644); err != nil {
t.Fatalf("Unable to write config JSON: %v", err)
}
}
Expand All @@ -110,7 +109,7 @@ func (tt adaptModelLayoutTestCase) writeSchemaFile(t *testing.T) {
}

schemaFullPath := filepath.Join(tt.getSourceDir(), tt.SchemaPath)
if werr := ioutil.WriteFile(schemaFullPath, jsonBytes, 0644); werr != nil {
if werr := os.WriteFile(schemaFullPath, jsonBytes, 0644); werr != nil {
t.Fatal("Error writing JSON to schema file", werr)
}
}
Expand Down Expand Up @@ -533,7 +532,7 @@ func TestAdaptModelLayoutForRuntime(t *testing.T) {
}

// read in the config to assert on it
configJSON, err2 := ioutil.ReadFile(configFilePath)
configJSON, err2 := os.ReadFile(configFilePath)
if err2 != nil {
t.Fatalf("Unable to read config file %s: %v", configFilePath, err2)
}
Expand Down Expand Up @@ -635,7 +634,7 @@ func assertCreateEmptyFile(path string, t *testing.T) {

func createFile(path, contents string) error {
os.MkdirAll(filepath.Dir(path), 0755)
err := ioutil.WriteFile(path, []byte(contents), 0644)
err := os.WriteFile(path, []byte(contents), 0644)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion model-mesh-mlserver-adapter/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
19 changes: 10 additions & 9 deletions model-mesh-mlserver-adapter/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -180,7 +179,7 @@ func adaptModelLayoutForRuntime(rootModelDir, modelID, modelType, modelPath, sch
err = adaptModelLayout(modelID, modelType, modelPath, schemaPath, mlserverModelIDDir, false, log)
} else {
// model path is a directory, inspect the files
files, err1 := ioutil.ReadDir(modelPath)
files, err1 := os.ReadDir(modelPath)
if err1 != nil {
return fmt.Errorf("Could not read files in dir %s: %w", modelPath, err)
}
Expand Down Expand Up @@ -216,7 +215,7 @@ func adaptModelLayoutForRuntime(rootModelDir, modelID, modelType, modelPath, sch
// Only minimal changes should be made to the model repo to get it to load. For
// MLServer, this means writing the model ID into the configuration file and
// just symlinking all other files
func adaptNativeModelLayout(files []os.FileInfo, modelID, modelPath, schemaPath, targetDir string, log logr.Logger) error {
func adaptNativeModelLayout(files []os.DirEntry, modelID, modelPath, schemaPath, targetDir string, log logr.Logger) error {
for _, f := range files {
filename := f.Name()
source, err := util.SecureJoin(modelPath, filename)
Expand All @@ -226,9 +225,9 @@ func adaptNativeModelLayout(files []os.FileInfo, modelID, modelPath, schemaPath,
}
// special handling of the config file
if filename == mlserverRepositoryConfigFilename {
configJSON, err1 := ioutil.ReadFile(source)
configJSON, err1 := os.ReadFile(source)
if err1 != nil {
return fmt.Errorf("Could not read model config file %s: %w", source, err1)
return fmt.Errorf("could not read model config file %s: %w", source, err1)
}

// process the config to set the model's `name` to the model-mesh model id
Expand All @@ -243,9 +242,11 @@ func adaptNativeModelLayout(files []os.FileInfo, modelID, modelPath, schemaPath,
"mlserverRepositoryConfigFilename", mlserverRepositoryConfigFilename)
return jerr
}
err1 = ioutil.WriteFile(target, processedConfigJSON, f.Mode())

fInfo, _ := f.Info()
err1 = os.WriteFile(target, processedConfigJSON, fInfo.Mode())
if err1 != nil {
return fmt.Errorf("Error writing config file %s: %w", source, err1)
return fmt.Errorf("error writing config file %s: %w", source, err1)
}
continue
}
Expand All @@ -257,7 +258,7 @@ func adaptNativeModelLayout(files []os.FileInfo, modelID, modelPath, schemaPath,
}
err = os.Symlink(source, link)
if err != nil {
return fmt.Errorf("Error creating symlink to %s: %w", source, err)
return fmt.Errorf("error creating symlink to %s: %w", source, err)
}
}

Expand Down Expand Up @@ -346,7 +347,7 @@ func adaptModelLayout(modelID, modelType, modelPath, schemaPath, targetDir strin
"mlserverRepositoryConfigFilename", mlserverRepositoryConfigFilename)
return err
}
if err = ioutil.WriteFile(target, configJSON, 0664); err != nil {
if err = os.WriteFile(target, configJSON, 0664); err != nil {
return fmt.Errorf("Error writing generated config file for %s: %w", modelID, err)
}

Expand Down
9 changes: 4 additions & 5 deletions model-mesh-mlserver-adapter/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -18,7 +18,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -215,7 +214,7 @@ func TestProcessConfigJSON(t *testing.T) {
}

func assertGeneratedModelDirIsCorrect(sourceDir string, generatedDir string, modelID string, t *testing.T) {
generatedFiles, err := ioutil.ReadDir(generatedDir)
generatedFiles, err := os.ReadDir(generatedDir)
if err != nil {
t.Errorf("Could not read files in generated dir [%s]: %v", generatedDir, err)
}
Expand All @@ -227,7 +226,7 @@ func assertGeneratedModelDirIsCorrect(sourceDir string, generatedDir string, mod
if f.Name() == mlserverRepositoryConfigFilename {
configFileFound = true
// should have `name` field matching the modelID
configJSON, err := ioutil.ReadFile(filePath)
configJSON, err := os.ReadFile(filePath)
if err != nil {
t.Errorf("Unable to read config file %s: %v", filePath, err)
}
Expand All @@ -245,7 +244,7 @@ func assertGeneratedModelDirIsCorrect(sourceDir string, generatedDir string, mod

// if not the config file, it should be a symlink pointing to a file in the
// source dir that exists
if f.Mode()&os.ModeSymlink != os.ModeSymlink {
if f.Type()&os.ModeSymlink != os.ModeSymlink {
t.Errorf("Expected [%s] to be a symlink.", filePath)
}

Expand Down
2 changes: 1 addition & 1 deletion model-mesh-ovms-adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Loading

0 comments on commit 0ba2f47

Please sign in to comment.