diff --git a/.dockerignore b/.dockerignore index 320605f..f22e408 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,8 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-08-09T11:41:23Z by kres e62e51e. +# Generated on 2023-05-08T18:28:37Z by kres latest. -** +* !controlplane !loadbalancer !upstream diff --git a/.drone.yml b/.drone.yml index 4aa0282..bb88234 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,7 +1,7 @@ --- # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-11-01T07:58:51Z by kres 03328da. +# Generated on 2023-05-08T18:28:37Z by kres latest. kind: pipeline type: kubernetes @@ -174,7 +174,7 @@ steps: services: - name: docker - image: docker:20.10-dind + image: docker:23.0-dind entrypoint: - dockerd commands: @@ -212,6 +212,10 @@ trigger: exclude: - renovate/* - dependabot/* + event: + exclude: + - promote + - cron --- kind: pipeline diff --git a/.golangci.yml b/.golangci.yml index 38b2fe7..0bd100b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-09-13T13:45:46Z by kres latest. +# Generated on 2023-05-08T18:28:37Z by kres latest. # options for analysis running run: @@ -150,6 +150,12 @@ linters: - maligned - golint - scopelint + - varcheck + - deadcode + - structcheck + - ifshort + # disabled as it seems to be broken - goes into imported libraries and reports issues there + - musttag issues: exclude: [] diff --git a/Dockerfile b/Dockerfile index 0a88296..dbb6938 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -# syntax = docker/dockerfile-upstream:1.2.0-labs +# syntax = docker/dockerfile-upstream:1.5.2-labs # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-11-01T07:58:51Z by kres 03328da. +# Generated on 2023-05-08T18:28:37Z by kres latest. ARG TOOLCHAIN @@ -10,9 +10,9 @@ ARG TOOLCHAIN FROM scratch AS generate # runs markdownlint -FROM docker.io/node:19.0.0-alpine3.16 AS lint-markdown +FROM docker.io/node:20.0.0-alpine3.16 AS lint-markdown WORKDIR /src -RUN npm i -g markdownlint-cli@0.32.2 +RUN npm i -g markdownlint-cli@0.33.0 RUN npm i sentences-per-line@0.2.1 COPY .markdownlint.json . COPY ./README.md ./README.md @@ -29,18 +29,18 @@ ARG CGO_ENABLED ENV CGO_ENABLED ${CGO_ENABLED} ENV GOPATH /go ARG GOLANGCILINT_VERSION -RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \ +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \ && mv /go/bin/golangci-lint /bin/golangci-lint ARG GOFUMPT_VERSION RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \ && mv /go/bin/gofumpt /bin/gofumpt -RUN go install golang.org/x/vuln/cmd/govulncheck@latest \ +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/vuln/cmd/govulncheck@latest \ && mv /go/bin/govulncheck /bin/govulncheck ARG GOIMPORTS_VERSION -RUN go install golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION} \ +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION} \ && mv /go/bin/goimports /bin/goimports ARG DEEPCOPY_VERSION -RUN go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \ +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \ && mv /go/bin/deep-copy /bin/deep-copy # tools and sources diff --git a/Makefile b/Makefile index 47dcfc5..c2c61da 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-11-01T07:58:51Z by kres 03328da. +# Generated on 2023-05-08T18:28:37Z by kres latest. # common variables @@ -13,14 +13,14 @@ WITH_RACE ?= false REGISTRY ?= ghcr.io USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) -GOLANGCILINT_VERSION ?= v1.50.1 -GOFUMPT_VERSION ?= v0.4.0 -GO_VERSION ?= 1.19 -GOIMPORTS_VERSION ?= v0.2.0 +GOLANGCILINT_VERSION ?= v1.52.2 +GOFUMPT_VERSION ?= v0.5.0 +GO_VERSION ?= 1.20 +GOIMPORTS_VERSION ?= v0.8.0 PROTOBUF_GO_VERSION ?= 1.28.1 -GRPC_GO_VERSION ?= 1.2.0 -GRPC_GATEWAY_VERSION ?= 2.12.0 -VTPROTOBUF_VERSION ?= 0.3.0 +GRPC_GO_VERSION ?= 1.3.0 +GRPC_GATEWAY_VERSION ?= 2.15.2 +VTPROTOBUF_VERSION ?= 0.4.0 DEEPCOPY_VERSION ?= v0.5.5 GO_BUILDFLAGS ?= GO_LDFLAGS ?= @@ -58,7 +58,7 @@ COMMON_ARGS += --build-arg=GRPC_GATEWAY_VERSION="$(GRPC_GATEWAY_VERSION)" COMMON_ARGS += --build-arg=VTPROTOBUF_VERSION="$(VTPROTOBUF_VERSION)" COMMON_ARGS += --build-arg=DEEPCOPY_VERSION="$(DEEPCOPY_VERSION)" COMMON_ARGS += --build-arg=TESTPKGS="$(TESTPKGS)" -TOOLCHAIN ?= docker.io/golang:1.19-alpine +TOOLCHAIN ?= docker.io/golang:1.20-alpine # help menu diff --git a/go.mod b/go.mod index 73bc6c4..dd56a0d 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,20 @@ module github.com/siderolabs/go-loadbalancer -go 1.19 +go 1.20 replace inet.af/tcpproxy => github.com/smira/tcpproxy v0.0.0-20201015133617-de5f7797b95b require ( github.com/siderolabs/go-retry v0.3.2 - github.com/stretchr/testify v1.8.1 - go.uber.org/goleak v1.2.0 + github.com/stretchr/testify v1.8.2 + go.uber.org/goleak v1.2.1 inet.af/tcpproxy v0.0.0-20221017015627-91f861402626 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.1.0 // indirect + golang.org/x/sys v0.8.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a00d9e7..dd109c5 100644 --- a/go.sum +++ b/go.sum @@ -17,14 +17,12 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 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= -go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= -go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/loadbalancer/node.go b/loadbalancer/node.go index 7e03d10..cb06ab6 100644 --- a/loadbalancer/node.go +++ b/loadbalancer/node.go @@ -7,7 +7,6 @@ package loadbalancer import ( "context" "log" - "net" ) type node struct { @@ -16,7 +15,7 @@ type node struct { } func (upstream node) HealthCheck(ctx context.Context) error { - d := net.Dialer{} + d := probeDialer() c, err := d.DialContext(ctx, "tcp", upstream.address) if err != nil { diff --git a/loadbalancer/probe_all.go b/loadbalancer/probe_all.go new file mode 100644 index 0000000..a50ee32 --- /dev/null +++ b/loadbalancer/probe_all.go @@ -0,0 +1,23 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +//go:build !windows + +package loadbalancer + +import ( + "net" + "syscall" +) + +func probeDialer() *net.Dialer { + return &net.Dialer{ + // The dialer reduces the TIME-WAIT period to 1 seconds instead of the OS default of 60 seconds. + Control: func(network, address string, c syscall.RawConn) error { + return c.Control(func(fd uintptr) { + syscall.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{Onoff: 1, Linger: 1}) //nolint: errcheck + }) + }, + } +} diff --git a/loadbalancer/probe_windows.go b/loadbalancer/probe_windows.go new file mode 100644 index 0000000..9533084 --- /dev/null +++ b/loadbalancer/probe_windows.go @@ -0,0 +1,23 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +//go:build windows + +package loadbalancer + +import ( + "net" + "syscall" +) + +func probeDialer() *net.Dialer { + return &net.Dialer{ + // The dialer reduces the TIME-WAIT period to 1 seconds instead of the OS default of 60 seconds. + Control: func(network, address string, c syscall.RawConn) error { + return c.Control(func(fd uintptr) { + syscall.SetsockoptLinger(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{Onoff: 1, Linger: 1}) //nolint: errcheck + }) + }, + } +}