Skip to content

Commit

Permalink
chore: Bump golangci-lint action (#220)
Browse files Browse the repository at this point in the history
* bump lint action version

* update golangci-lint version in makefiles

* lint fixes for listener

* lint fixes for watcher and config update

* adjust config to not drop all the rules
  • Loading branch information
janmedrek authored Feb 29, 2024
1 parent 2d7cb2f commit acb38cf
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull-listener-pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
go-version: '1.21'
cache: false
- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4.0.0
with:
version: v1.54.1
version: v1.56.2
args: --verbose
working-directory: ./listener
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-runtime-watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
go-version: '1.21'
cache: false
- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4.0.0
with:
version: v1.54.2
version: v1.56.2
args: --verbose
working-directory: ./runtime-watcher
- name: Build
Expand Down
12 changes: 12 additions & 0 deletions listener/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ linters-settings:
- prefix(github.com/kyma-project)
cyclop:
max-complexity: 20
revive:
severity: error
rules:
- name: comment-spacings
disabled: true
- name: dot-imports
severity: warning
disabled: true
- name: line-length-limit
severity: warning
disabled: true
arguments: [ 120 ]
issues:
exclude-rules:
- path: "_test\\.go"
Expand Down
2 changes: 1 addition & 1 deletion listener/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ IMG := $(IMG_NAME):$(DOCKER_TAG)
GOLANG_CI_LINT = $(LOCALBIN)/golangci-lint

## Tool Versions
GOLANG_CI_LINT_VERSION ?= v1.54.1
GOLANG_CI_LINT_VERSION ?= v1.56.2

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
8 changes: 4 additions & 4 deletions listener/pkg/event/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestHandler(t *testing.T) {
// SETUP
log := setupLogger()
skrEventsListener := newTestListener(":8082", "kyma", log,
func(r *http.Request, watcherEvtObject *types.WatchEvent) error {
func(_ *http.Request, _ *types.WatchEvent) error {
return nil
})

Expand Down Expand Up @@ -98,7 +98,7 @@ func TestHandler(t *testing.T) {
"mismatching status code: expected %d, got %d", http.StatusOK, resp.StatusCode)
testEvt.mu.Lock()
defer testEvt.mu.Unlock()
assert.NotEqual(t, nil, testEvt.evt,
assert.NotNil(t, testEvt.evt,
"error reading event from channel: expected non nil event, got %v", testEvt.evt)
testWatcherEvtContents := listenerEvent.UnstructuredContent(testWatcherEvt)
for key, value := range testWatcherEvtContents {
Expand All @@ -112,14 +112,14 @@ func TestMiddleware(t *testing.T) {
// SETUP
log := setupLogger()
skrEventsListener := newTestListener(":8082", "kyma", log,
func(r *http.Request, watcherEvtObject *types.WatchEvent) error {
func(_ *http.Request, _ *types.WatchEvent) error {
return nil
})

const successfulResponseString = "SUCCESS"
const requestSizeLimitInBytes = 16384 // 16KB
handlerUnderTest := http.MaxBytesHandler(skrEventsListener.RequestSizeLimitingMiddleware(
func(writer http.ResponseWriter, request *http.Request) {
func(writer http.ResponseWriter, _ *http.Request) {
_, err := writer.Write([]byte(successfulResponseString))
if err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion listener/pkg/event/skr_events_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (l *SKREventListener) HandleSKREvent() http.HandlerFunc {
return func(writer http.ResponseWriter, req *http.Request) {
// http method support: POST only is allowed
if req.Method != http.MethodPost {
errorMessage := fmt.Sprintf("%s method is not allowed on this path", req.Method)
errorMessage := req.Method + " method is not allowed on this path"
l.Logger.Error(nil, errorMessage)
http.Error(writer, errorMessage, http.StatusMethodNotAllowed)
return
Expand Down
18 changes: 9 additions & 9 deletions listener/pkg/event/watcher_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
const hostname = "http://localhost:8082"

type unmarshalTestCase struct {
name string
urlPath string
expectedEvent *types.WatchEvent
errMsg string
httpStatus int
name string
urlPath string
expectedEvent *types.WatchEvent
expectedErrMsg string
expectedHTTPStatus int
}

func TestUnmarshalSKREvent(t *testing.T) {
Expand Down Expand Up @@ -60,12 +60,12 @@ func TestUnmarshalSKREvent(t *testing.T) {
currentWatcherEvent, err := listenerEvent.UnmarshalSKREvent(req)
// THEN
if err != nil {
require.Equal(t, testCase.errMsg, err.Message)
require.Equal(t, testCase.httpStatus, err.HTTPErrorCode)
require.Equal(t, testCase.expectedErrMsg, err.Message)
require.Equal(t, testCase.expectedHTTPStatus, err.HTTPErrorCode)
return
}
require.Equal(t, testCase.errMsg, "")
require.Equal(t, testCase.httpStatus, http.StatusOK)
require.Equal(t, testCase.expectedErrMsg, "")
require.Equal(t, testCase.expectedHTTPStatus, http.StatusOK)
require.Equal(t, testCase.expectedEvent, currentWatcherEvent)
})
}
Expand Down
12 changes: 12 additions & 0 deletions runtime-watcher/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ linters-settings:
funlen:
statements: 60
lines: 80
revive:
severity: error
rules:
- name: comment-spacings
disabled: true
- name: dot-imports
severity: warning
disabled: true
- name: line-length-limit
severity: warning
disabled: true
arguments: [ 120 ]
issues:
exclude-rules:
- path: "_test\\.go"
Expand Down
2 changes: 1 addition & 1 deletion runtime-watcher/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BUILD_VERSION := from_makefile
ENVTEST_K8S_VERSION = 1.24.1
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANG_CI_LINT = $(LOCALBIN)/golangci-lint
GOLANG_CI_LINT_VERSION ?= v1.54.2
GOLANG_CI_LINT_VERSION ?= v1.56.2

ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down
6 changes: 3 additions & 3 deletions runtime-watcher/internal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h *Handler) Handle(writer http.ResponseWriter, request *http.Request) {
return
}

h.logger.Info(fmt.Sprintf("Incoming admission review for: %s", admissionReview.Request.Kind.String()))
h.logger.Info("Incoming admission review for: " + admissionReview.Request.Kind.String())

moduleName, err := getModuleName(request.URL.Path)
if err != nil {
Expand Down Expand Up @@ -110,11 +110,11 @@ func getModuleName(urlPath string) (string, error) {
var moduleName string
_, err := fmt.Sscanf(urlPath, urlPathPattern, &moduleName)
if err != nil && !errors.Is(err, io.EOF) {
return "", fmt.Errorf("could not parse url path")
return "", errors.New("could not parse url path")
}

if err != nil && errors.Is(err, io.EOF) || moduleName == "" {
return "", fmt.Errorf("module name must not be empty")
return "", errors.New("module name must not be empty")
}

return moduleName, nil
Expand Down
2 changes: 1 addition & 1 deletion runtime-watcher/internal/handler_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func GetAdmissionHTTPRequest(operation admissionv1.Operation, watchedName, modul
if err != nil {
return nil, err
}
return httptest.NewRequest(http.MethodGet, fmt.Sprintf("/validate/%s", moduleName),
return httptest.NewRequest(http.MethodGet, "/validate/"+moduleName,
bytes.NewBuffer(bytesRequest)), nil
}

Expand Down
11 changes: 6 additions & 5 deletions runtime-watcher/internal/serverconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-logr/logr"
"github.com/kyma-project/runtime-watcher/skr/internal/serverconfig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_ParseFromEnv_PortUnsetShouldUseDefaultValue(t *testing.T) {
Expand All @@ -16,7 +17,7 @@ func Test_ParseFromEnv_PortUnsetShouldUseDefaultValue(t *testing.T) {

result, err := serverconfig.ParseFromEnv(logger)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 8443, result.Port)
}

Expand All @@ -27,7 +28,7 @@ func Test_ParseFromEnv_InvalidPortShouldUseDefaultValue(t *testing.T) {

result, err := serverconfig.ParseFromEnv(logger)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 8443, result.Port)
}

Expand All @@ -38,7 +39,7 @@ func Test_ParseFromEnv_InvalidPortRangeShouldUseDefaultValue(t *testing.T) {

result, err := serverconfig.ParseFromEnv(logger)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 8443, result.Port)
}

Expand All @@ -49,7 +50,7 @@ func Test_ParseFromEnv_ValidPort(t *testing.T) {

result, err := serverconfig.ParseFromEnv(logger)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 1234, result.Port)
}

Expand Down Expand Up @@ -124,7 +125,7 @@ func Test_ParseFromEnv_ValidConfig(t *testing.T) {

result, err := serverconfig.ParseFromEnv(logger)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 1234, result.Port)
assert.Equal(t, "ca_cert_path", result.CACertPath)
assert.Equal(t, "tls_cert_path", result.TLSCertPath)
Expand Down
2 changes: 1 addition & 1 deletion runtime-watcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
logger.Error(err, "necessary bootstrap settings missing")
return
}
logger.Info(fmt.Sprintf("Server config successfully parsed: %s", config.PrettyPrint()))
logger.Info("Server config successfully parsed: " + config.PrettyPrint())

restConfig := ctrl.GetConfigOrDie()
restClient, err := client.New(restConfig, client.Options{})
Expand Down

0 comments on commit acb38cf

Please sign in to comment.