From dface1f2aa72b18b05f4c700002a83f6d5eb4ff2 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Fri, 28 Jul 2023 17:41:28 +0200 Subject: [PATCH] bump deps Signed-off-by: Jorge Turrado --- .devcontainer/Dockerfile | 2 +- .github/workflows/build_canary.yml | 2 +- .github/workflows/build_release.yml | 2 +- .github/workflows/e2e-tests.yaml | 2 +- .github/workflows/images.yaml | 6 +- .github/workflows/tests.yaml | 6 +- CHANGELOG.md | 3 + go.mod | 42 ++++---- go.sum | 77 ++++++------- interceptor/Dockerfile | 2 +- interceptor/forward_wait_func.go | 4 +- interceptor/main.go | 102 ++++++++---------- .../proxy_handlers_integration_test.go | 3 +- operator/Dockerfile | 2 +- operator/controllers/http/ping.go | 3 +- pkg/http/server.go | 10 +- pkg/k8s/deployment_cache_informer.go | 6 +- pkg/k8s/endpoints.go | 3 +- pkg/net/dial_context.go | 2 +- pkg/queue/queue.go | 4 +- pkg/queue/queue_rpc.go | 15 +-- pkg/queue/queue_test.go | 23 ++++ pkg/routing/table.go | 2 +- pkg/util/errors.go | 25 +++++ scaler/Dockerfile | 2 +- scaler/handlers.go | 5 - scaler/main.go | 70 ++++++------ scaler/queue_pinger.go | 12 +-- 28 files changed, 233 insertions(+), 204 deletions(-) create mode 100644 pkg/queue/queue_test.go create mode 100644 pkg/util/errors.go diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7698bc4ed..21bc589a7 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -FROM golang:1.19.7 +FROM golang:1.20.5 # Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive diff --git a/.github/workflows/build_canary.yml b/.github/workflows/build_canary.yml index 1380bcd5f..02c2aaae5 100644 --- a/.github/workflows/build_canary.yml +++ b/.github/workflows/build_canary.yml @@ -8,7 +8,7 @@ on: jobs: build: runs-on: ubuntu-20.04 - container: ghcr.io/kedacore/build-tools:1.19.5 + container: ghcr.io/kedacore/keda-tools:1.20.5 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index d004f2ecc..58390941e 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -7,7 +7,7 @@ on: jobs: build: runs-on: ubuntu-20.04 - container: ghcr.io/kedacore/build-tools:1.19.5 + container: ghcr.io/kedacore/keda-tools:1.20.5 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml index 7607fec99..2dcb97e03 100644 --- a/.github/workflows/e2e-tests.yaml +++ b/.github/workflows/e2e-tests.yaml @@ -98,7 +98,7 @@ jobs: - uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: "1.20" - name: Helm install uses: Azure/setup-helm@v3 diff --git a/.github/workflows/images.yaml b/.github/workflows/images.yaml index 9971d6100..d57e97e85 100644 --- a/.github/workflows/images.yaml +++ b/.github/workflows/images.yaml @@ -6,7 +6,7 @@ on: jobs: build_scaler: runs-on: ubuntu-latest - container: ghcr.io/kedacore/build-tools:1.19.5 + container: ghcr.io/kedacore/keda-tools:1.20.5 steps: - uses: actions/checkout@v3 - name: Register workspace path @@ -18,7 +18,7 @@ jobs: build_operator: runs-on: ubuntu-latest - container: ghcr.io/kedacore/build-tools:1.19.5 + container: ghcr.io/kedacore/keda-tools:1.20.5 steps: - uses: actions/checkout@v3 - name: Register workspace path @@ -30,7 +30,7 @@ jobs: build_interceptor: runs-on: ubuntu-latest - container: ghcr.io/kedacore/build-tools:1.19.5 + container: ghcr.io/kedacore/keda-tools:1.20.5 steps: - uses: actions/checkout@v3 - name: Register workspace path diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 70df4d17c..05d38e21c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,7 +9,7 @@ jobs: validate: name: validate - ${{ matrix.name }} runs-on: ${{ matrix.runner }} - container: ghcr.io/kedacore/build-tools:1.19.5 + container: ghcr.io/kedacore/keda-tools:1.20.5 strategy: matrix: include: @@ -67,12 +67,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v4.6.1 + - uses: actions/setup-python@v4.7.0 with: python-version: 3.x - uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: "1.20" - name: Get golangci run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2 - uses: pre-commit/action@v3.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index fdaec82ca..e6ff3ec44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ This changelog keeps track of work items that have been completed and are ready - **Scaler**: remplement custom interceptor metrics ([#718](https://github.com/kedacore/http-add-on/issues/718)) - **Operator**: Remove ScaledObject `name` & `app` custom labels ([#717](https://github.com/kedacore/http-add-on/issues/717)) +- **Interceptor**: fatal error: concurrent map iteration and map write ([#726](https://github.com/kedacore/http-add-on/issues/726)) +- **Interceptor**: Provide graceful shutdown for http servers on SIGINT and SIGTERM ([#731](https://github.com/kedacore/http-add-on/issues/731)) +- **Scaler**: Provide graceful shutdown for grpc server on SIGINT and SIGTERM ([#731](https://github.com/kedacore/http-add-on/issues/731)) ### Deprecations diff --git a/go.mod b/go.mod index 215f5a17d..dddcc80b2 100644 --- a/go.mod +++ b/go.mod @@ -1,28 +1,27 @@ module github.com/kedacore/http-add-on -go 1.19 +go 1.20 require ( github.com/go-logr/logr v1.2.4 github.com/go-logr/zapr v1.2.4 github.com/golang/mock v1.7.0-rc.1.0.20220812172401-5b455625bd2c github.com/hashicorp/go-immutable-radix/v2 v2.0.0 - github.com/kedacore/keda/v2 v2.11.1 + github.com/kedacore/keda/v2 v2.11.2 github.com/kelseyhightower/envconfig v1.4.0 github.com/onsi/ginkgo/v2 v2.11.0 - github.com/onsi/gomega v1.27.8 - github.com/pkg/errors v0.9.1 + github.com/onsi/gomega v1.27.10 github.com/stretchr/testify v1.8.4 github.com/tj/assert v0.0.3 go.uber.org/zap v1.24.0 golang.org/x/sync v0.3.0 - google.golang.org/grpc v1.56.1 - google.golang.org/protobuf v1.30.0 - k8s.io/api v0.27.3 - k8s.io/apimachinery v0.27.3 - k8s.io/client-go v0.27.3 - k8s.io/code-generator v0.27.3 - k8s.io/utils v0.0.0-20230505201702-9f6742963106 + google.golang.org/grpc v1.57.0 + google.golang.org/protobuf v1.31.0 + k8s.io/api v0.27.4 + k8s.io/apimachinery v0.27.4 + k8s.io/client-go v0.27.4 + k8s.io/code-generator v0.27.4 + k8s.io/utils v0.0.0-20230726121419-3b25d923346b sigs.k8s.io/controller-runtime v0.15.0 ) @@ -36,7 +35,7 @@ require ( github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect @@ -44,10 +43,10 @@ require ( github.com/google/gnostic v0.6.9 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect + github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.0 // indirect - github.com/imdario/mergo v0.3.15 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect + github.com/imdario/mergo v0.3.16 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect @@ -56,6 +55,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.4.0 // indirect @@ -63,13 +63,13 @@ require ( github.com/prometheus/procfs v0.10.1 // indirect github.com/spf13/pflag v1.0.5 // indirect go.uber.org/atomic v1.11.0 // indirect - go.uber.org/multierr v1.10.0 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.11.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + golang.org/x/mod v0.11.0 // indirect + golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.9.0 // indirect - golang.org/x/sys v0.9.0 // indirect - golang.org/x/term v0.9.0 // indirect - golang.org/x/text v0.10.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/term v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.9.3 // indirect gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index cb551af07..7baedfd60 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,9 @@ github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -90,8 +91,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20230309165930-d61513b1440d h1:um9/pc7tKMINFfP1eE7Wv6PRGXlcCSJkVajF7KJw3uQ= -github.com/google/pprof v0.0.0-20230309165930-d61513b1440d/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= +github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= +github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -100,17 +101,17 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/hashicorp/go-immutable-radix/v2 v2.0.0 h1:nq9lQ5I71Heg2lRb2/+szuIWKY3Y73d8YKyXyN91WzU= github.com/hashicorp/go-immutable-radix/v2 v2.0.0/go.mod h1:hgdqLXA4f6NIjRVisM1TJ9aOJVNRqKZj+xDGF6m7PBw= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= -github.com/hashicorp/golang-lru/v2 v2.0.0 h1:Lf+9eD8m5pncvHAOCQj49GSN6aQI8XGfI5OpXNkoWaA= -github.com/hashicorp/golang-lru/v2 v2.0.0/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= -github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/hashicorp/golang-lru/v2 v2.0.3 h1:kmRrRLlInXvng0SmLxmQpQkpbYAvcXm7NPDrgxJa9mE= +github.com/hashicorp/golang-lru/v2 v2.0.3/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kedacore/keda/v2 v2.11.1 h1:fDcXb/4LIOaKJwY7lExQ2x+EPgDtkboPRzSdTD98Bm8= -github.com/kedacore/keda/v2 v2.11.1/go.mod h1:eutYX+QXTi3QH90F7JvY3tYtV5Jq10o5f56Chk5IVF8= +github.com/kedacore/keda/v2 v2.11.2 h1:UgPww0NREqUkM1PGERUz+eb5PlO5oU8V/sT9Hh+ZD60= +github.com/kedacore/keda/v2 v2.11.2/go.mod h1:eutYX+QXTi3QH90F7JvY3tYtV5Jq10o5f56Chk5IVF8= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -138,8 +139,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= -github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= -github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -155,7 +156,7 @@ github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -188,8 +189,8 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= -go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -205,8 +206,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -221,8 +222,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= -golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.9.0 h1:BPpt2kU7oMRq3kCHAA1tbSEshXRw1LpG2ztgDwrzuAs= @@ -247,19 +248,19 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= -golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= +golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= -golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -299,8 +300,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.56.1 h1:z0dNfjIl0VpaZ9iSVjA6daGatAYwPGstTjt5vkRMFkQ= -google.golang.org/grpc v1.56.1/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -313,8 +314,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -334,16 +335,16 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -k8s.io/api v0.27.3 h1:yR6oQXXnUEBWEWcvPWS0jQL575KoAboQPfJAuKNrw5Y= -k8s.io/api v0.27.3/go.mod h1:C4BNvZnQOF7JA/0Xed2S+aUyJSfTGkGFxLXz9MnpIpg= +k8s.io/api v0.27.4 h1:0pCo/AN9hONazBKlNUdhQymmnfLRbSZjd5H5H3f0bSs= +k8s.io/api v0.27.4/go.mod h1:O3smaaX15NfxjzILfiln1D8Z3+gEYpjEpiNA/1EVK1Y= k8s.io/apiextensions-apiserver v0.27.2 h1:iwhyoeS4xj9Y7v8YExhUwbVuBhMr3Q4bd/laClBV6Bo= k8s.io/apiextensions-apiserver v0.27.2/go.mod h1:Oz9UdvGguL3ULgRdY9QMUzL2RZImotgxvGjdWRq6ZXQ= -k8s.io/apimachinery v0.27.3 h1:Ubye8oBufD04l9QnNtW05idcOe9Z3GQN8+7PqmuVcUM= -k8s.io/apimachinery v0.27.3/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E= -k8s.io/client-go v0.27.3 h1:7dnEGHZEJld3lYwxvLl7WoehK6lAq7GvgjxpA3nv1E8= -k8s.io/client-go v0.27.3/go.mod h1:2MBEKuTo6V1lbKy3z1euEGnhPfGZLKTS9tiJ2xodM48= -k8s.io/code-generator v0.27.3 h1:JRhRQkzKdQhHmv9s5f7vuqveL8qukAQ2IqaHm6MFspM= -k8s.io/code-generator v0.27.3/go.mod h1:DPung1sI5vBgn4AGKtlPRQAyagj/ir/4jI55ipZHVww= +k8s.io/apimachinery v0.27.4 h1:CdxflD4AF61yewuid0fLl6bM4a3q04jWel0IlP+aYjs= +k8s.io/apimachinery v0.27.4/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E= +k8s.io/client-go v0.27.4 h1:vj2YTtSJ6J4KxaC88P4pMPEQECWMY8gqPqsTgUKzvjk= +k8s.io/client-go v0.27.4/go.mod h1:ragcly7lUlN0SRPk5/ZkGnDjPknzb37TICq07WhI6Xc= +k8s.io/code-generator v0.27.4 h1:bw2xFEBnthhCSC7Bt6FFHhPTfWX21IJ30GXxOzywsFE= +k8s.io/code-generator v0.27.4/go.mod h1:DPung1sI5vBgn4AGKtlPRQAyagj/ir/4jI55ipZHVww= k8s.io/component-base v0.27.2 h1:neju+7s/r5O4x4/txeUONNTS9r1HsPbyoPBAtHsDCpo= k8s.io/component-base v0.27.2/go.mod h1:5UPk7EjfgrfgRIuDBFtsEFAe4DAvP3U+M8RTzoSJkpo= k8s.io/gengo v0.0.0-20230306165830-ab3349d207d4 h1:aClvVG6GbX10ISHcc24J+tqbr0S7fEe1MWkFJ7cWWCI= @@ -353,8 +354,8 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f h1:2kWPakN3i/k81b0gvD5C5FJ2kxm1WrQFanWchyKuqGg= k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f/go.mod h1:byini6yhqGC14c3ebc/QwanvYwhuMWF6yz2F8uwW8eg= -k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU= -k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= +k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= knative.dev/pkg v0.0.0-20230616134650-eb63a40adfb0 h1:weQWWxEEbNOPuL4qtGiBZuMSFhcjF/Cu163uktd/xFE= knative.dev/pkg v0.0.0-20230616134650-eb63a40adfb0/go.mod h1:dqC6IrvyBE7E+oZocs5PkVhq1G59pDTA7r8U17EAKMk= sigs.k8s.io/controller-runtime v0.15.0 h1:ML+5Adt3qZnMSYxZ7gAverBLNPSMQEibtzAgp0UPojU= diff --git a/interceptor/Dockerfile b/interceptor/Dockerfile index 89bcd5a8d..0e2356b6e 100644 --- a/interceptor/Dockerfile +++ b/interceptor/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${BUILDPLATFORM} ghcr.io/kedacore/build-tools:1.20.4 as builder +FROM --platform=${BUILDPLATFORM} ghcr.io/kedacore/keda-tools:1.20.5 as builder WORKDIR /workspace COPY go.* . RUN go mod download diff --git a/interceptor/forward_wait_func.go b/interceptor/forward_wait_func.go index 749970d2d..9ebc69b11 100644 --- a/interceptor/forward_wait_func.go +++ b/interceptor/forward_wait_func.go @@ -36,7 +36,7 @@ func newDeployReplicasForwardWaitFunc( if err != nil { // if we didn't get the initial deployment state, bail out return 0, fmt.Errorf( - "error getting state for deployment %s/%s (%s)", + "error getting state for deployment %s/%s: %w", deployNS, deployName, err, @@ -62,7 +62,7 @@ func newDeployReplicasForwardWaitFunc( // otherwise, if the context is marked done before // we're done waiting, fail. return 0, fmt.Errorf( - "context marked done while waiting for deployment %s to reach > 0 replicas (%w)", + "context marked done while waiting for deployment %s to reach > 0 replicas: %w", deployName, ctx.Err(), ) diff --git a/interceptor/main.go b/interceptor/main.go index 3314ee85d..c5c08876b 100644 --- a/interceptor/main.go +++ b/interceptor/main.go @@ -2,8 +2,8 @@ package main import ( "context" + "errors" "fmt" - "math/rand" "net/http" "os" "time" @@ -28,10 +28,6 @@ import ( "github.com/kedacore/http-add-on/pkg/util" ) -func init() { - rand.Seed(time.Now().UnixNano()) -} - // +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch // +kubebuilder:rbac:groups=http.keda.sh,resources=httpscaledobjects,verbs=get;list;watch @@ -41,14 +37,14 @@ func main() { fmt.Println("Error building logger", err) os.Exit(1) } + timeoutCfg := config.MustParseTimeouts() servingCfg := config.MustParseServing() if err := config.Validate(*servingCfg, *timeoutCfg); err != nil { lggr.Error(err, "invalid configuration") os.Exit(1) } - ctx := util.ContextWithLogger(context.Background(), lggr) - ctx, ctxDone := context.WithCancel(ctx) + lggr.Info( "starting interceptor", "timeoutConfig", @@ -94,73 +90,67 @@ func main() { lggr.Info("Interceptor starting") - errGrp, ctx := errgroup.WithContext(ctx) + ctx := ctrl.SetupSignalHandler() + ctx = util.ContextWithLogger(ctx, lggr) + + eg, ctx := errgroup.WithContext(ctx) // start the deployment cache updater - errGrp.Go(func() error { - defer ctxDone() - err := deployCache.Start(ctx) - lggr.Error(err, "deployment cache watcher failed") - return err + eg.Go(func() error { + lggr.Info("starting the deployment cache") + + deployCache.Start(ctx) + return nil }) // start the update loop that updates the routing table from // the ConfigMap that the operator updates as HTTPScaledObjects // enter and exit the system - errGrp.Go(func() error { - defer ctxDone() - err := routingTable.Start(ctx) - lggr.Error(err, "config map routing table updater failed") - return err + eg.Go(func() error { + lggr.Info("starting the routing table") + + if err := routingTable.Start(ctx); !util.IsIgnoredErr(err) { + lggr.Error(err, "routing table failed") + return err + } + + return nil }) // start the administrative server. this is the server // that serves the queue size API - errGrp.Go(func() error { - defer ctxDone() - lggr.Info( - "starting the admin server", - "port", - adminPort, - ) - err := runAdminServer( - ctx, - lggr, - q, - adminPort, - ) - lggr.Error(err, "admin server failed") - return err + eg.Go(func() error { + lggr.Info("starting the admin server", "port", adminPort) + + if err := runAdminServer(ctx, lggr, q, adminPort); !util.IsIgnoredErr(err) { + lggr.Error(err, "admin server failed") + return err + } + + return nil }) // start the proxy server. this is the server that // accepts, holds and forwards user requests - errGrp.Go(func() error { - defer ctxDone() - lggr.Info( - "starting the proxy server", - "port", - proxyPort, - ) - err := runProxyServer( - ctx, - lggr, - q, - waitFunc, - routingTable, - timeoutCfg, - proxyPort, - ) - lggr.Error(err, "proxy server failed") - return err + eg.Go(func() error { + lggr.Info("starting the proxy server", "port", proxyPort) + + if err := runProxyServer(ctx, lggr, q, waitFunc, routingTable, timeoutCfg, proxyPort); !util.IsIgnoredErr(err) { + lggr.Error(err, "proxy server failed") + return err + } + + return nil }) + build.PrintComponentInfo(lggr, "Interceptor") - // errGrp.Wait() should hang forever for healthy admin and proxy servers. - // if it returns an error, log and exit immediately. - waitErr := errGrp.Wait() - lggr.Error(waitErr, "error with interceptor") - os.Exit(1) + if err := eg.Wait(); err != nil && !errors.Is(err, context.Canceled) { + lggr.Error(err, "fatal error") + os.Exit(1) + } + + lggr.Info("Bye!") } func runAdminServer( diff --git a/interceptor/proxy_handlers_integration_test.go b/interceptor/proxy_handlers_integration_test.go index 3777a5665..d4530534c 100644 --- a/interceptor/proxy_handlers_integration_test.go +++ b/interceptor/proxy_handlers_integration_test.go @@ -13,7 +13,6 @@ import ( "time" "github.com/go-logr/logr" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" @@ -360,7 +359,7 @@ func splitHostPort(hostPortStr string) (string, int, error) { host := spl[0] port, err := strconv.Atoi(spl[1]) if err != nil { - return "", 0, errors.Wrap(err, "port was invalid") + return "", 0, fmt.Errorf("port was invalid: %w", err) } return host, port, nil } diff --git a/operator/Dockerfile b/operator/Dockerfile index 28474939f..bdbc840b4 100644 --- a/operator/Dockerfile +++ b/operator/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${BUILDPLATFORM} ghcr.io/kedacore/build-tools:1.20.4 as builder +FROM --platform=${BUILDPLATFORM} ghcr.io/kedacore/keda-tools:1.20.5 as builder WORKDIR /workspace COPY go.* . RUN go mod download diff --git a/operator/controllers/http/ping.go b/operator/controllers/http/ping.go index f2c4ce507..362a2aed9 100644 --- a/operator/controllers/http/ping.go +++ b/operator/controllers/http/ping.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" - "github.com/pkg/errors" "golang.org/x/sync/errgroup" "sigs.k8s.io/controller-runtime/pkg/client" @@ -28,7 +27,7 @@ func pingInterceptors( k8s.EndpointsFuncForControllerClient(cl), ) if err != nil { - return errors.Wrap(err, "pingInterceptors") + return fmt.Errorf("pingInterceptors: %w", err) } errGrp, _ := errgroup.WithContext(ctx) for _, endpointURL := range endpointURLs { diff --git a/pkg/http/server.go b/pkg/http/server.go index de1beff74..501887ea0 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -2,8 +2,9 @@ package http import ( "context" - "fmt" "net/http" + + "github.com/kedacore/http-add-on/pkg/util" ) func ServeContext(ctx context.Context, addr string, hdl http.Handler) error { @@ -14,9 +15,12 @@ func ServeContext(ctx context.Context, addr string, hdl http.Handler) error { go func() { <-ctx.Done() - if err := srv.Shutdown(ctx); err != nil { - fmt.Println("failed shutting down server:", err) + + if err := srv.Shutdown(context.Background()); err != nil { + logger := util.LoggerFromContext(ctx) + logger.Error(err, "failed shutting down server") } }() + return srv.ListenAndServe() } diff --git a/pkg/k8s/deployment_cache_informer.go b/pkg/k8s/deployment_cache_informer.go index 80ca6b5cc..716743819 100644 --- a/pkg/k8s/deployment_cache_informer.go +++ b/pkg/k8s/deployment_cache_informer.go @@ -7,7 +7,6 @@ import ( "time" "github.com/go-logr/logr" - "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/watch" @@ -32,11 +31,8 @@ func (i *InformerBackedDeploymentCache) MarshalJSON() ([]byte, error) { return json.Marshal(&depls) } -func (i *InformerBackedDeploymentCache) Start(ctx context.Context) error { +func (i *InformerBackedDeploymentCache) Start(ctx context.Context) { i.deplInformer.Informer().Run(ctx.Done()) - return errors.Wrap( - ctx.Err(), "deployment cache informer was stopped", - ) } func (i *InformerBackedDeploymentCache) Get( diff --git a/pkg/k8s/endpoints.go b/pkg/k8s/endpoints.go index fc386c9a6..c11a9b05d 100644 --- a/pkg/k8s/endpoints.go +++ b/pkg/k8s/endpoints.go @@ -5,7 +5,6 @@ import ( "fmt" "net/url" - "github.com/pkg/errors" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -29,7 +28,7 @@ func EndpointsForService( ) ([]*url.URL, error) { endpoints, err := endpointsFn(ctx, ns, serviceName) if err != nil { - return nil, errors.Wrap(err, "pkg.k8s.EndpointsForService") + return nil, fmt.Errorf("pkg.k8s.EndpointsForService: %w", err) } ret := []*url.URL{} for _, subset := range endpoints.Subsets { diff --git a/pkg/net/dial_context.go b/pkg/net/dial_context.go index 3010465b7..4b6a70bbd 100644 --- a/pkg/net/dial_context.go +++ b/pkg/net/dial_context.go @@ -50,7 +50,7 @@ func DialContextWithRetry(coreDialer *net.Dialer, backoff wait.Backoff) DialCont select { case <-ctx.Done(): t.Stop() - return nil, fmt.Errorf("context timed out: %s", ctx.Err()) + return nil, fmt.Errorf("context timed out: %w", ctx.Err()) case <-t.C: t.Stop() } diff --git a/pkg/queue/queue.go b/pkg/queue/queue.go index 99b799f7f..36d9ccdec 100644 --- a/pkg/queue/queue.go +++ b/pkg/queue/queue.go @@ -85,6 +85,8 @@ func (r *Memory) Current() (*Counts, error) { r.mut.RLock() defer r.mut.RUnlock() cts := NewCounts() - cts.Counts = r.countMap + for key, val := range r.countMap { + cts.Counts[key] = val + } return cts, nil } diff --git a/pkg/queue/queue_rpc.go b/pkg/queue/queue_rpc.go index 4ff3ed9b6..53c6c4642 100644 --- a/pkg/queue/queue_rpc.go +++ b/pkg/queue/queue_rpc.go @@ -7,7 +7,6 @@ import ( "net/url" "github.com/go-logr/logr" - "github.com/pkg/errors" ) const countsPath = "/queue" @@ -66,22 +65,12 @@ func GetCounts( interceptorURL.Path = countsPath resp, err := httpCl.Get(interceptorURL.String()) if err != nil { - errMsg := fmt.Sprintf( - "requesting the queue counts from %s", - interceptorURL.String(), - ) - return nil, errors.Wrap(err, errMsg) + return nil, fmt.Errorf("requesting the queue counts from %s: %w", interceptorURL.String(), err) } defer resp.Body.Close() counts := NewCounts() if err := json.NewDecoder(resp.Body).Decode(counts); err != nil { - return nil, errors.Wrap( - err, - fmt.Sprintf( - "decoding response from the interceptor at %s", - interceptorURL.String(), - ), - ) + return nil, fmt.Errorf("decoding response from the interceptor at %s: %w", interceptorURL.String(), err) } return counts, nil diff --git a/pkg/queue/queue_test.go b/pkg/queue/queue_test.go new file mode 100644 index 000000000..e8212a95d --- /dev/null +++ b/pkg/queue/queue_test.go @@ -0,0 +1,23 @@ +package queue + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCurrent(t *testing.T) { + r := require.New(t) + memory := NewMemory() + err := memory.Resize("host1", 1) + r.NoError(err) + current, err := memory.Current() + r.NoError(err) + r.Equal(current.Counts, memory.countMap) + + err = memory.Resize("host1", 1) + r.NoError(err) + err = memory.Resize("host2", 1) + r.NoError(err) + r.NotEqual(current.Counts, memory.countMap) +} diff --git a/pkg/routing/table.go b/pkg/routing/table.go index a54ab167b..2762d5df1 100644 --- a/pkg/routing/table.go +++ b/pkg/routing/table.go @@ -2,11 +2,11 @@ package routing import ( "context" + "errors" "net/http" "sync" "time" - "github.com/pkg/errors" "golang.org/x/sync/errgroup" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/cache" diff --git a/pkg/util/errors.go b/pkg/util/errors.go new file mode 100644 index 000000000..9e448dee2 --- /dev/null +++ b/pkg/util/errors.go @@ -0,0 +1,25 @@ +package util + +import ( + "context" + "errors" + "net/http" +) + +var ( + ignoredErrs = []error{ + nil, + context.Canceled, + http.ErrServerClosed, + } +) + +func IsIgnoredErr(err error) bool { + for _, ignoredErr := range ignoredErrs { + if errors.Is(err, ignoredErr) { + return true + } + } + + return false +} diff --git a/scaler/Dockerfile b/scaler/Dockerfile index 5416a5975..61cafbd7a 100644 --- a/scaler/Dockerfile +++ b/scaler/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${BUILDPLATFORM} ghcr.io/kedacore/build-tools:1.20.4 as builder +FROM --platform=${BUILDPLATFORM} ghcr.io/kedacore/keda-tools:1.20.5 as builder WORKDIR /workspace COPY go.* . RUN go mod download diff --git a/scaler/handlers.go b/scaler/handlers.go index bee3d2f52..351603a69 100644 --- a/scaler/handlers.go +++ b/scaler/handlers.go @@ -7,7 +7,6 @@ package main import ( "context" "errors" - "math/rand" "strconv" "time" @@ -20,10 +19,6 @@ import ( "github.com/kedacore/http-add-on/pkg/k8s" ) -func init() { - rand.Seed(time.Now().UnixNano()) -} - const ( keyInterceptorTargetPendingRequests = "interceptorTargetPendingRequests" ) diff --git a/scaler/main.go b/scaler/main.go index ccceb4103..94b4b130e 100644 --- a/scaler/main.go +++ b/scaler/main.go @@ -6,6 +6,7 @@ package main import ( "context" + "errors" "fmt" "log" "net" @@ -28,6 +29,7 @@ import ( "github.com/kedacore/http-add-on/pkg/build" "github.com/kedacore/http-add-on/pkg/k8s" pkglog "github.com/kedacore/http-add-on/pkg/log" + "github.com/kedacore/http-add-on/pkg/util" ) // +kubebuilder:rbac:groups="",namespace=keda,resources=configmaps,verbs=get;list;watch @@ -88,49 +90,57 @@ func main() { sharedInformerFactory := informers.NewSharedInformerFactory(httpCl, cfg.ConfigMapCacheRsyncPeriod) httpsoInformer := informershttpv1alpha1.New(sharedInformerFactory, "", nil).HTTPScaledObjects() - ctx, done := context.WithCancel( - context.Background(), - ) - defer done() + ctx := ctrl.SetupSignalHandler() + ctx = util.ContextWithLogger(ctx, lggr) - grp, ctx := errgroup.WithContext(ctx) + eg, ctx := errgroup.WithContext(ctx) // start the deployment informer - grp.Go(func() error { - defer done() - return deployInformer.Start(ctx) + eg.Go(func() error { + lggr.Info("starting the deployment informer") + + deployInformer.Start(ctx) + return nil }) // start the httpso informer - grp.Go(func() error { - defer done() + eg.Go(func() error { + lggr.Info("starting the httpso informer") + httpsoInformer.Informer().Run(ctx.Done()) - return ctx.Err() + return nil }) - grp.Go(func() error { - defer done() - return pinger.start( - ctx, - time.NewTicker(cfg.QueueTickDuration), - deployInformer, - ) + eg.Go(func() error { + lggr.Info("starting the queue pinger") + + if err := pinger.start(ctx, time.NewTicker(cfg.QueueTickDuration), deployInformer); !util.IsIgnoredErr(err) { + lggr.Error(err, "queue pinger failed") + return err + } + + return nil }) - grp.Go(func() error { - defer done() - return startGrpcServer( - ctx, - lggr, - grpcPort, - pinger, - httpsoInformer, - int64(targetPendingRequests), - ) + eg.Go(func() error { + lggr.Info("starting the grpc server") + + if err := startGrpcServer(ctx, lggr, grpcPort, pinger, httpsoInformer, int64(targetPendingRequests)); !util.IsIgnoredErr(err) { + lggr.Error(err, "grpc server failed") + return err + } + + return nil }) build.PrintComponentInfo(lggr, "Scaler") - lggr.Error(grp.Wait(), "one or more of the servers failed") + + if err := eg.Wait(); err != nil && !errors.Is(err, context.Canceled) { + lggr.Error(err, "fatal error") + os.Exit(1) + } + + lggr.Info("Bye!") } func startGrpcServer( @@ -172,7 +182,7 @@ func startGrpcServer( go func() { <-ctx.Done() - lis.Close() + grpcServer.GracefulStop() }() return grpcServer.Serve(lis) diff --git a/scaler/queue_pinger.go b/scaler/queue_pinger.go index f69a5fb6e..6f139613f 100644 --- a/scaler/queue_pinger.go +++ b/scaler/queue_pinger.go @@ -4,12 +4,12 @@ package main import ( "context" + "fmt" "net/http" "sync" "time" "github.com/go-logr/logr" - "github.com/pkg/errors" "golang.org/x/sync/errgroup" "github.com/kedacore/http-add-on/pkg/k8s" @@ -93,19 +93,13 @@ func (q *queuePinger) start( ctx.Err(), "context marked done. stopping queuePinger loop", ) - return errors.Wrap( - ctx.Err(), - "context marked done. stopping queuePinger loop", - ) + return fmt.Errorf("context marked done. stopping queuePinger loop: %w", ctx.Err()) // do our regularly scheduled work case <-ticker.C: err := q.fetchAndSaveCounts(ctx) if err != nil { lggr.Error(err, "getting request counts") - return errors.Wrap( - err, - "error getting request counts", - ) + return fmt.Errorf("error getting request counts: %w", err) } // handle changes to the interceptor fleet // Deployment