Skip to content

Commit

Permalink
bump go version from 1.17 to 1.19
Browse files Browse the repository at this point in the history
chore: Go lang 1.17 and a little bit old and 1.19 as well.
However, before taking a greater step to higher version would might be better
to break it in smaller changes since the amount of changes that this update
has required is a little bit high, here is a small description of what was
changed by this update:

- Outdated linters:
  - WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
  - WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
  - WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.

- Deprecation of the io/ioutils package:
  - SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os]
    - Used the `os` package and the needed code changes applied

- At puller/config.go
  - ( undefined: GetEnvString)
  - Fixed by `import . "github.com/kserve/modelmesh-runtime-adapter/internal/envconfig"`

- Some comments and headers adjusted
- small identation changes made as part of go fmt.

Fixes #64

Signed-off-by: Spolti <[email protected]>
  • Loading branch information
spolti committed Nov 1, 2023
1 parent 693291a commit 1b40deb
Show file tree
Hide file tree
Showing 82 changed files with 166 additions and 177 deletions.
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.43.0
rev: v1.51.1
hooks:
- id: golangci-lint
- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
2 changes: 1 addition & 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ run: use.develop

.PHONY: test
## Run tests
test:
test: fmt
./scripts/run_tests.sh

.PHONY: fmt
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
10 changes: 5 additions & 5 deletions internal/envconfig/envconfig.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 @@ -21,7 +21,7 @@ import (
"github.com/go-logr/logr"
)

// Returns the string value of environment variable "key" or the default value
// GetEnvString Returns the string value of environment variable "key" or the default value
// if "key" is not set. Note if the environment variable is set to an empty
// string, this will return an empty string, not defaultValue.
func GetEnvString(key string, defaultValue string) string {
Expand All @@ -31,7 +31,7 @@ func GetEnvString(key string, defaultValue string) string {
return defaultValue
}

// Returns the integer of value environment variable "key" or the default value
// GetEnvInt Returns the integer of value environment variable "key" or the default value
// if "key" is not set. Note if the environment variable is set to a non
// integer, including an empty string, this will fail and exit.
func GetEnvInt(key string, defaultValue int, log logr.Logger) int {
Expand All @@ -58,7 +58,7 @@ func GetEnvFloat(key string, defaultValue float64, log logr.Logger) float64 {
return defaultValue
}

// Returns the bool value of environment variable "key" or the default value
// GetEnvBool Returns the bool value of environment variable "key" or the default value
// if "key" is not set. Note if the environment variable is set to a non
// boolean, including an empty string, this will fail and exit.
func GetEnvBool(key string, defaultValue bool, log logr.Logger) bool {
Expand All @@ -73,7 +73,7 @@ func GetEnvBool(key string, defaultValue bool, log logr.Logger) bool {
return defaultValue
}

// Returns the duration value of environment variable "key" or a default value
// GetEnvDuration Returns the duration value of environment variable "key" or a default value
// Note if the environment variable cannot be parsed as a duration, including an
// empty string, this will fail and exit.
func GetEnvDuration(key string, defaultValue time.Duration, log logr.Logger) time.Duration {
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
9 changes: 5 additions & 4 deletions internal/util/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package util

import (
Expand All @@ -22,7 +23,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 @@ -38,7 +39,7 @@ func RemoveFileFromListOfFileInfo(filename string, files []os.FileInfo) (bool, [
return true, files[:len(files)-1]
}

// Check if a file exists at path
// FileExists Check if a file exists at path
func FileExists(path string) (bool, error) {
if _, err := os.Stat(path); err == nil {
return true, nil
Expand All @@ -49,7 +50,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
Loading

0 comments on commit 1b40deb

Please sign in to comment.