Skip to content

Commit f34e7f6

Browse files
authored
Fixed the rest of the lint errors and updating the linters to match what is typically used in other sub-projects (#134)
1 parent 0a100c6 commit f34e7f6

19 files changed

+63
-76
lines changed

.golangci.yml

+18-22
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,41 @@ run:
22
timeout: 5m
33
allow-parallel-runners: true
44

5+
# Settings related to issues
56
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
7+
# Which dirs to exclude: issues from them won't be reported
8+
exclude-dirs:
9+
- bin
1910
linters:
2011
disable-all: true
2112
enable:
22-
- dupl
23-
- errcheck
2413
- copyloopvar
14+
- dupword
15+
- durationcheck
16+
- fatcontext
17+
- gci
2518
- ginkgolinter
19+
- gocritic
20+
- govet
21+
- loggercheck
22+
- misspell
23+
- perfsprint
24+
- revive
25+
- unconvert
26+
- makezero
27+
- errcheck
2628
- goconst
2729
- gocyclo
2830
- gofmt
2931
- goimports
3032
- gosimple
31-
- govet
3233
- ineffassign
33-
- lll
34-
- misspell
3534
- nakedret
3635
- prealloc
37-
- revive
38-
- staticcheck
3936
- typecheck
40-
- unconvert
4137
- unparam
4238
- unused
43-
39+
4440
linters-settings:
4541
revive:
4642
rules:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ ci-lint: golangci-lint
122122
$(GOLANGCI_LINT) run --timeout 15m0s
123123

124124
.PHONY: verify
125-
verify: vet fmt-verify manifests generate ## ci-lint add back when all lint errors are fixed
125+
verify: vet fmt-verify manifests generate ci-lint
126126
git --no-pager diff --exit-code config api client-go
127127

128128
##@ Build

api/v1alpha1/inferencemodel_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type InferenceModelSpec struct {
4141
// The name of the model as the users set in the "model" parameter in the requests.
4242
// The name should be unique among the workloads that reference the same backend pool.
4343
// This is the parameter that will be used to match the request with. In the future, we may
44-
// allow to match on other request parameters. The other approach to support matching on
44+
// allow to match on other request parameters. The other approach to support matching
4545
// on other request parameters is to use a different ModelName per HTTPFilter.
4646
// Names can be reserved without implementing an actual model in the pool.
4747
// This can be done by specifying a target model and setting the weight to zero,

config/crd/bases/inference.networking.x-k8s.io_inferencemodels.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ spec:
6868
The name of the model as the users set in the "model" parameter in the requests.
6969
The name should be unique among the workloads that reference the same backend pool.
7070
This is the parameter that will be used to match the request with. In the future, we may
71-
allow to match on other request parameters. The other approach to support matching on
71+
allow to match on other request parameters. The other approach to support matching
7272
on other request parameters is to use a different ModelName per HTTPFilter.
7373
Names can be reserved without implementing an actual model in the pool.
7474
This can be done by specifying a target model and setting the weight to zero,

pkg/ext-proc/backend/datastore.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package backend
22

33
import (
4-
"fmt"
4+
"errors"
55
"math/rand"
66
"sync"
77

@@ -53,7 +53,7 @@ func (ds *K8sDatastore) getInferencePool() (*v1alpha1.InferencePool, error) {
5353
ds.poolMu.RLock()
5454
defer ds.poolMu.RUnlock()
5555
if ds.inferencePool == nil {
56-
return nil, fmt.Errorf("InferencePool hasn't been initialized yet")
56+
return nil, errors.New("InferencePool hasn't been initialized yet")
5757
}
5858
return ds.inferencePool, nil
5959
}

pkg/ext-proc/backend/endpointslice_reconciler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package backend
22

33
import (
44
"context"
5-
"fmt"
5+
"strconv"
66

77
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
88
discoveryv1 "k8s.io/api/discovery/v1"
@@ -57,7 +57,7 @@ func (c *EndpointSliceReconciler) updateDatastore(
5757
if c.validPod(endpoint) {
5858
pod := Pod{
5959
Name: endpoint.TargetRef.Name,
60-
Address: endpoint.Addresses[0] + ":" + fmt.Sprint(inferencePool.Spec.TargetPortNumber),
60+
Address: endpoint.Addresses[0] + ":" + strconv.Itoa(int(inferencePool.Spec.TargetPortNumber)),
6161
}
6262
podMap[pod] = true
6363
c.Datastore.pods.Store(pod, true)

pkg/ext-proc/backend/inferencepool_reconciler.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package backend
33
import (
44
"context"
55

6-
"sigs.k8s.io/controller-runtime/pkg/client"
7-
86
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
97
"k8s.io/apimachinery/pkg/runtime"
108
"k8s.io/client-go/tools/record"
119
"k8s.io/klog/v2"
1210
ctrl "sigs.k8s.io/controller-runtime"
11+
"sigs.k8s.io/controller-runtime/pkg/client"
1312
)
1413

1514
// InferencePoolReconciler utilizes the controller runtime to reconcile Instance Gateway resources

pkg/ext-proc/backend/vllm/metrics_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package vllm
22

33
import (
4-
"fmt"
4+
"errors"
55
"testing"
66

7-
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
8-
97
dto "github.com/prometheus/client_model/go"
108
"github.com/stretchr/testify/assert"
119
"google.golang.org/protobuf/proto"
10+
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
1211
)
1312

1413
func TestPromToPodMetrics(t *testing.T) {
@@ -215,7 +214,7 @@ func TestPromToPodMetrics(t *testing.T) {
215214
MaxActiveModels: 0,
216215
},
217216
initialPodMetrics: &backend.PodMetrics{},
218-
expectedErr: fmt.Errorf("strconv.Atoi: parsing '2a': invalid syntax"),
217+
expectedErr: errors.New("strconv.Atoi: parsing '2a': invalid syntax"),
219218
},
220219
}
221220
for _, tc := range testCases {

pkg/ext-proc/handlers/request.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package handlers
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"strconv"
78

89
configPb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
910
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
10-
klog "k8s.io/klog/v2"
11-
1211
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
1312
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/scheduling"
13+
klog "k8s.io/klog/v2"
1414
)
1515

1616
// HandleRequestBody handles body of the request to the backend server, such as parsing the "model"
@@ -31,7 +31,7 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
3131
// Resolve target models.
3232
model, ok := rb["model"].(string)
3333
if !ok {
34-
return nil, fmt.Errorf("model not found in request")
34+
return nil, errors.New("model not found in request")
3535
}
3636
klog.V(3).Infof("Model requested: %v", model)
3737
modelName := model
@@ -87,7 +87,7 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
8787
},
8888
},
8989
// We need to update the content length header if the body is mutated, see Envoy doc:
90-
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_proc/v3/processing_mode.proto#enum-extensions-filters-http-ext-proc-v3-processingmode-bodysendmode
90+
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_proc/v3/processing_mode.proto
9191
{
9292
Header: &configPb.HeaderValue{
9393
Key: "Content-Length",

pkg/ext-proc/handlers/server.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77
envoyTypePb "github.com/envoyproxy/go-control-plane/envoy/type/v3"
88
"google.golang.org/grpc/codes"
99
"google.golang.org/grpc/status"
10-
klog "k8s.io/klog/v2"
11-
1210
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
1311
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
1412
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/scheduling"
13+
klog "k8s.io/klog/v2"
1514
)
1615

1716
func NewServer(pp PodProvider, scheduler Scheduler, targetPodHeader string, datastore ModelDataStore) *Server {
@@ -73,7 +72,7 @@ func (s *Server) Process(srv extProcPb.ExternalProcessor_ProcessServer) error {
7372
return status.Errorf(codes.Unknown, "cannot receive stream request: %v", err)
7473
}
7574

76-
resp := &extProcPb.ProcessingResponse{}
75+
var resp *extProcPb.ProcessingResponse
7776
switch v := req.Request.(type) {
7877
case *extProcPb.ProcessingRequest_RequestHeaders:
7978
resp = HandleRequestHeaders(reqCtx, req)

pkg/ext-proc/main.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ import (
1616
healthPb "google.golang.org/grpc/health/grpc_health_v1"
1717
"google.golang.org/grpc/status"
1818
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
19+
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
20+
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend/vllm"
21+
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/handlers"
22+
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/scheduling"
1923
"k8s.io/apimachinery/pkg/runtime"
2024
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2125
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2226
klog "k8s.io/klog/v2"
2327
ctrl "sigs.k8s.io/controller-runtime"
24-
25-
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
26-
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend/vllm"
27-
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/handlers"
28-
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/scheduling"
2928
)
3029

3130
var (

pkg/ext-proc/scheduling/filter.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package scheduling
22

33
import (
4-
"fmt"
4+
"errors"
55
"math"
66

7-
klog "k8s.io/klog/v2"
8-
97
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
8+
klog "k8s.io/klog/v2"
109
)
1110

1211
type Filter interface {
@@ -86,7 +85,7 @@ func toFilterFunc(pp podPredicate) filterFunc {
8685
}
8786
}
8887
if len(filtered) == 0 {
89-
return nil, fmt.Errorf("no pods left")
88+
return nil, errors.New("no pods left")
9089
}
9190
return filtered, nil
9291
}

pkg/ext-proc/scheduling/filter_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package scheduling
22

33
import (
4-
"fmt"
4+
"errors"
55
"testing"
66

77
"github.com/google/go-cmp/cmp"
8-
98
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
109
)
1110

@@ -21,7 +20,7 @@ func TestFilter(t *testing.T) {
2120
{
2221
name: "simple filter without successor, failure",
2322
filter: &filter{filter: func(req *LLMRequest, pods []*backend.PodMetrics) ([]*backend.PodMetrics, error) {
24-
return nil, fmt.Errorf("filter error")
23+
return nil, errors.New("filter error")
2524
}},
2625
err: true,
2726
},

pkg/ext-proc/scheduling/scheduler.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import (
77

88
"google.golang.org/grpc/codes"
99
"google.golang.org/grpc/status"
10-
klog "k8s.io/klog/v2"
11-
1210
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
11+
klog "k8s.io/klog/v2"
1312
)
1413

1514
const (

pkg/ext-proc/test/benchmark/benchmark.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import (
1010
"github.com/bojand/ghz/runner"
1111
"github.com/jhump/protoreflect/desc"
1212
"google.golang.org/protobuf/proto"
13-
klog "k8s.io/klog/v2"
14-
1513
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
1614
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
1715
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/test"
16+
klog "k8s.io/klog/v2"
1817
)
1918

2019
var (

pkg/ext-proc/test/hermetic_test.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@ package test
44
import (
55
"context"
66
"fmt"
7-
"log"
87
"testing"
98
"time"
109

11-
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
12-
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
13-
1410
configPb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
1511
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
1612
"github.com/google/go-cmp/cmp"
17-
"google.golang.org/protobuf/testing/protocmp"
18-
1913
"google.golang.org/grpc"
2014
"google.golang.org/grpc/credentials/insecure"
15+
"google.golang.org/protobuf/testing/protocmp"
16+
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
17+
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
2118
)
2219

2320
const (
@@ -145,13 +142,13 @@ func setUpServer(t *testing.T, pods []*backend.PodMetrics, models map[string]*v1
145142
// Create a grpc connection
146143
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
147144
if err != nil {
148-
log.Fatalf("Failed to connect to %v: %v", address, err)
145+
t.Fatalf("Failed to connect to %v: %v", address, err)
149146
}
150147

151148
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
152149
client, err = extProcPb.NewExternalProcessorClient(conn).Process(ctx)
153150
if err != nil {
154-
log.Fatalf("Failed to create client: %v", err)
151+
t.Fatalf("Failed to create client: %v", err)
155152
}
156153
return client, func() {
157154
cancel()

pkg/ext-proc/test/utils.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ import (
66
"net"
77
"time"
88

9+
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
910
"google.golang.org/grpc"
1011
"google.golang.org/grpc/reflection"
11-
klog "k8s.io/klog/v2"
12-
13-
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
14-
1512
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
1613
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/backend"
1714
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/handlers"
1815
"inference.networking.x-k8s.io/llm-instance-gateway/pkg/ext-proc/scheduling"
16+
klog "k8s.io/klog/v2"
1917
)
2018

2119
func StartExtProc(port int, refreshPodsInterval, refreshMetricsInterval time.Duration, pods []*backend.PodMetrics, models map[string]*v1alpha1.InferenceModel) *grpc.Server {
@@ -46,7 +44,12 @@ func startExtProc(port int, pp *backend.Provider, models map[string]*v1alpha1.In
4644

4745
klog.Infof("Starting gRPC server on port :%v", port)
4846
reflection.Register(s)
49-
go s.Serve(lis)
47+
go func() {
48+
err := s.Serve(lis)
49+
if err != nil {
50+
klog.Fatalf("Ext-proc failed with the err: %v", err)
51+
}
52+
}()
5053
return s
5154
}
5255

0 commit comments

Comments
 (0)