Skip to content

Commit

Permalink
branch 'community-main' - deleteme
Browse files Browse the repository at this point in the history
  • Loading branch information
spolti committed Dec 12, 2023
2 parents b53c140 + 014856c commit fd3a3ac
Show file tree
Hide file tree
Showing 81 changed files with 212 additions and 266 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
35 changes: 22 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ 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
go.uber.org/zap v1.23.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.24.0
golang.org/x/sync v0.1.0
google.golang.org/api v0.114.0
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.30.0
// controller-runtime dependency is only used for logging
sigs.k8s.io/controller-runtime v0.11.2
sigs.k8s.io/controller-runtime v0.14.6
)

require (
Expand All @@ -42,11 +42,13 @@ require (
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
Expand All @@ -61,15 +63,22 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.23.5 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
k8s.io/apimachinery v0.26.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

// Update to avoid CVE-2022-27191, CVE-2021-43565, CVE-2020-29652
replace golang.org/x/crypto => golang.org/x/crypto v0.14.0

// Update to avoid CVE-2023-3978, CVE-2023-39325, CVE-2023-44487
replace golang.org/x/net => golang.org/x/net v0.17.0
replace (
// Update to avoid CVE-2022-27191, CVE-2021-43565, CVE-2020-29652
golang.org/x/crypto => golang.org/x/crypto v0.14.0
// Update to avoid CVE-2023-3978, CVE-2023-39325, CVE-2023-44487
golang.org/x/net => golang.org/x/net v0.17.0
// remove when upgrade to controller-runtime 0.15.x or apimachinery to 0.27.x
// Fixes github.com/elazarl/goproxy Denial of Service (DoS)
// This dependency was removed from apimachinery 0.27.0
// Even the controller-runtime being used only for logging, the version 0.15.0 brings
// apimachinery 0.27.0 that brings a lot more of indirect dependencies that we don't want to pull
k8s.io/apimachinery => k8s.io/apimachinery v0.27.0
)
122 changes: 26 additions & 96 deletions go.sum

Large diffs are not rendered by default.

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
Loading

0 comments on commit fd3a3ac

Please sign in to comment.