From 3830b0ed79c2dad58570e4ef0d74c77b0ad4f831 Mon Sep 17 00:00:00 2001 From: Sargun Dhillon Date: Fri, 8 Jan 2021 01:00:22 -0800 Subject: [PATCH 1/5] Fix key name in log entry --- internal/queue/queue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/queue/queue.go b/internal/queue/queue.go index 8f73477be..352c6600d 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -124,7 +124,7 @@ func (q *Queue) Run(ctx context.Context, workers int) { func (q *Queue) worker(ctx context.Context, i int) { ctx = log.WithLogger(ctx, log.G(ctx).WithFields(map[string]interface{}{ "workerId": i, - "Queue": q.name, + "queue": q.name, })) for q.handleQueueItem(ctx) { } From 99ad66814bec72a22be4dd5a0c94aedd1d506642 Mon Sep 17 00:00:00 2001 From: Pires Date: Sun, 10 Jan 2021 13:24:31 +0000 Subject: [PATCH 2/5] build: use Go 1.15 Signed-off-by: Pires --- .circleci/config.yml | 6 +++--- Dockerfile | 2 +- Makefile | 2 +- go.mod | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6735264d8..e45598966 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: validate: resource_class: xlarge docker: - - image: circleci/golang:1.13 + - image: circleci/golang:1.15 environment: GO111MODULE: "on" GOPROXY: https://proxy.golang.org @@ -30,7 +30,7 @@ jobs: test: resource_class: xlarge docker: - - image: circleci/golang:1.13 + - image: circleci/golang:1.15 environment: GO111MODULE: "on" working_directory: /go/src/github.com/virtual-kubelet/virtual-kubelet @@ -114,7 +114,7 @@ jobs: command: | mkdir $HOME/.go export PATH=$HOME/.go/bin:${PATH} - curl -fsSL -o "/tmp/go.tar.gz" "https://dl.google.com/go/go1.13.12.linux-amd64.tar.gz" + curl -fsSL -o "/tmp/go.tar.gz" "https://dl.google.com/go/go1.15.6.linux-amd64.tar.gz" tar -C $HOME/.go --strip-components=1 -xzf "/tmp/go.tar.gz" go version make e2e diff --git a/Dockerfile b/Dockerfile index d09a5579a..2842ac163 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13 as builder +FROM golang:1.15 as builder ENV PATH /go/bin:/usr/local/go/bin:$PATH ENV GOPATH /go COPY . /go/src/github.com/virtual-kubelet/virtual-kubelet diff --git a/Makefile b/Makefile index e8a9f4b79..8073e6df0 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ include Makefile.e2e # Also, we will want to lock our tool versions using go mod: # https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module gobin_tool ?= $(shell which gobin || echo $(GOPATH)/bin/gobin) -goimports := golang.org/x/tools/cmd/goimports@release-branch.go1.13 +goimports := golang.org/x/tools/cmd/goimports@release-branch.go1.15 gocovmerge := github.com/wadey/gocovmerge@b5bfa59ec0adc420475f97f89b58045c721d761c goreleaser := github.com/goreleaser/goreleaser@v0.82.2 gox := github.com/mitchellh/gox@v1.0.1 diff --git a/go.mod b/go.mod index 3c446ca84..ded351ecf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/virtual-kubelet/virtual-kubelet -go 1.13 +go 1.15 require ( contrib.go.opencensus.io/exporter/jaeger v0.1.0 From 9e522952c39b0e2f62e90b8f019c59d49959a66f Mon Sep 17 00:00:00 2001 From: Pires Date: Sun, 10 Jan 2021 15:34:23 +0000 Subject: [PATCH 3/5] e2e: test with Kubernetes to 1.20.1 Signed-off-by: Pires --- .circleci/config.yml | 20 +++++++++---- hack/skaffold/virtual-kubelet/skaffold.yml | 2 +- test/e2e/README.md | 35 ++++++++++++++-------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6735264d8..2ba099e30 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,4 @@ -version: 2 +version: 2.0 jobs: validate: resource_class: xlarge @@ -52,18 +52,18 @@ jobs: e2e: machine: - image: circleci/classic:201808-01 + image: ubuntu-1604:202010-01 working_directory: /home/circleci/go/src/github.com/virtual-kubelet/virtual-kubelet environment: CHANGE_MINIKUBE_NONE_USER: true GOPATH: /home/circleci/go KUBECONFIG: /home/circleci/.kube/config - KUBERNETES_VERSION: v1.17.6 + KUBERNETES_VERSION: v1.20.1 MINIKUBE_HOME: /home/circleci - MINIKUBE_VERSION: v1.2.0 + MINIKUBE_VERSION: v1.16.0 MINIKUBE_WANTUPDATENOTIFICATION: false MINIKUBE_WANTREPORTERRORPROMPT: false - SKAFFOLD_VERSION: v0.33.0 + SKAFFOLD_VERSION: v1.17.2 GO111MODULE: "on" steps: - checkout @@ -81,6 +81,16 @@ jobs: curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/${SKAFFOLD_VERSION}/skaffold-linux-amd64 chmod +x skaffold sudo mv skaffold /usr/local/bin/ + - run: + name: Install Minikube dependencies + command: | + sudo apt-get update && sudo apt-get install -y apt-transport-https curl + curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - + cat < Date: Sun, 10 Jan 2021 12:58:28 +0000 Subject: [PATCH 4/5] log: add klog/v2 Fixes #924 Signed-off-by: Pires --- go.sum | 1 + log/klogv2/klogv2.go | 95 +++++++++++++++++++++++++++++++++++++++ log/klogv2/klogv2_test.go | 28 ++++++++++++ log/logrus/logrus.go | 12 ++--- 4 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 log/klogv2/klogv2.go create mode 100644 log/klogv2/klogv2_test.go diff --git a/go.sum b/go.sum index c66c3063d..6d61a23c2 100644 --- a/go.sum +++ b/go.sum @@ -645,6 +645,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= diff --git a/log/klogv2/klogv2.go b/log/klogv2/klogv2.go new file mode 100644 index 000000000..298abaa91 --- /dev/null +++ b/log/klogv2/klogv2.go @@ -0,0 +1,95 @@ +// Copyright © 2021 The virtual-kubelet authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package klogv2 implements a virtual-kubelet/log.Logger using klogv2 as a backend +// +// You can use this by creating a klogv2 logger and calling `FromKlogv2(fields)`. +// If you want this to be the default logger for virtual-kubelet, set `log.L` to the value returned by `FromKlogv2` +// +// We recommend reading the klog conventions to build a better understanding of levels and when they should apply +// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md +package klogv2 + +import ( + "github.com/virtual-kubelet/virtual-kubelet/log" + "k8s.io/klog/v2" +) + +// adapter implements the `log.Logger` interface for klogv2 +type adapter struct { + fields map[string]interface{} +} + +// FromKlogv2 creates a new `log.Logger` from the provided entry +func FromKlogv2(fields map[string]interface{}) log.Logger { + return &adapter{fields} +} + +func (l *adapter) Debug(args ...interface{}) { + klog.V(4).Info(args, l.fields) +} + +func (l *adapter) Debugf(format string, args ...interface{}) { + klog.V(4).Infof(format, args, l.fields) +} + +func (l *adapter) Info(args ...interface{}) { + klog.Info(args, l.fields) +} + +func (l *adapter) Infof(format string, args ...interface{}) { + klog.Infof(format, args, l.fields) +} + +func (l *adapter) Warn(args ...interface{}) { + klog.Warning(args, l.fields) +} + +func (l *adapter) Warnf(format string, args ...interface{}) { + klog.Warningf(format, args, l.fields) +} + +func (l *adapter) Error(args ...interface{}) { + klog.Error(args, l.fields) +} + +func (l *adapter) Errorf(format string, args ...interface{}) { + klog.Errorf(format, args, l.fields) +} + +func (l *adapter) Fatal(args ...interface{}) { + klog.Fatal(args, l.fields) +} + +func (l *adapter) Fatalf(format string, args ...interface{}) { + klog.Fatalf(format, args, l.fields) +} + +// WithField adds a field to the log entry. +func (l *adapter) WithField(key string, val interface{}) log.Logger { + fields := map[string]interface{}{ + key: val, + } + return FromKlogv2(fields) +} + +// WithFields adds multiple fields to a log entry. +func (l *adapter) WithFields(fields log.Fields) log.Logger { + return FromKlogv2(fields) +} + +// WithError adds an error to the log entry +func (l *adapter) WithError(err error) log.Logger { + return l.WithField("err", err) +} diff --git a/log/klogv2/klogv2_test.go b/log/klogv2/klogv2_test.go new file mode 100644 index 000000000..d150ae850 --- /dev/null +++ b/log/klogv2/klogv2_test.go @@ -0,0 +1,28 @@ +// Copyright © 2021 The virtual-kubelet authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package klogv2 + +import ( + "testing" + + "github.com/virtual-kubelet/virtual-kubelet/log" +) + +func TestImplementsLoggerInterface(t *testing.T) { + l := FromKlogv2(nil) + + if _, ok := l.(log.Logger); !ok { + t.Fatal("does not implement log.Logger interface") + } +} diff --git a/log/logrus/logrus.go b/log/logrus/logrus.go index 644f13ab7..e208905cb 100644 --- a/log/logrus/logrus.go +++ b/log/logrus/logrus.go @@ -22,27 +22,27 @@ import ( "github.com/virtual-kubelet/virtual-kubelet/log" ) -// Adapter implements the `log.Logger` interface for logrus -type Adapter struct { +// adapter implements the `log.Logger` interface for logrus +type adapter struct { *logrus.Entry } // FromLogrus creates a new `log.Logger` from the provided entry func FromLogrus(entry *logrus.Entry) log.Logger { - return &Adapter{entry} + return &adapter{entry} } // WithField adds a field to the log entry. -func (l *Adapter) WithField(key string, val interface{}) log.Logger { +func (l *adapter) WithField(key string, val interface{}) log.Logger { return FromLogrus(l.Entry.WithField(key, val)) } // WithFields adds multiple fields to a log entry. -func (l *Adapter) WithFields(f log.Fields) log.Logger { +func (l *adapter) WithFields(f log.Fields) log.Logger { return FromLogrus(l.Entry.WithFields(logrus.Fields(f))) } // WithError adds an error to the log entry -func (l *Adapter) WithError(err error) log.Logger { +func (l *adapter) WithError(err error) log.Logger { return FromLogrus(l.Entry.WithError(err)) } From be76c022ae9c2a56abbbd416c6fb78c1dadccc8e Mon Sep 17 00:00:00 2001 From: Pires Date: Mon, 11 Jan 2021 18:17:01 +0000 Subject: [PATCH 5/5] log: validate log.Logger impl at compile time Signed-off-by: Pires --- log/klogv2/klogv2.go | 3 +++ log/klogv2/klogv2_test.go | 28 ---------------------------- log/logrus/logrus.go | 3 +++ log/logrus/logrus_test.go | 30 ------------------------------ 4 files changed, 6 insertions(+), 58 deletions(-) delete mode 100644 log/klogv2/klogv2_test.go delete mode 100644 log/logrus/logrus_test.go diff --git a/log/klogv2/klogv2.go b/log/klogv2/klogv2.go index 298abaa91..57bfac83c 100644 --- a/log/klogv2/klogv2.go +++ b/log/klogv2/klogv2.go @@ -26,6 +26,9 @@ import ( "k8s.io/klog/v2" ) +// Ensure log.Logger is fully implemented during compile time. +var _ log.Logger = (*adapter)(nil) + // adapter implements the `log.Logger` interface for klogv2 type adapter struct { fields map[string]interface{} diff --git a/log/klogv2/klogv2_test.go b/log/klogv2/klogv2_test.go deleted file mode 100644 index d150ae850..000000000 --- a/log/klogv2/klogv2_test.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2021 The virtual-kubelet authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// 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 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package klogv2 - -import ( - "testing" - - "github.com/virtual-kubelet/virtual-kubelet/log" -) - -func TestImplementsLoggerInterface(t *testing.T) { - l := FromKlogv2(nil) - - if _, ok := l.(log.Logger); !ok { - t.Fatal("does not implement log.Logger interface") - } -} diff --git a/log/logrus/logrus.go b/log/logrus/logrus.go index e208905cb..31974604a 100644 --- a/log/logrus/logrus.go +++ b/log/logrus/logrus.go @@ -22,6 +22,9 @@ import ( "github.com/virtual-kubelet/virtual-kubelet/log" ) +// Ensure log.Logger is fully implemented during compile time. +var _ log.Logger = (*adapter)(nil) + // adapter implements the `log.Logger` interface for logrus type adapter struct { *logrus.Entry diff --git a/log/logrus/logrus_test.go b/log/logrus/logrus_test.go deleted file mode 100644 index f51667108..000000000 --- a/log/logrus/logrus_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright © 2017 The virtual-kubelet authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// 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 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logrus - -import ( - "testing" - - "github.com/sirupsen/logrus" - "github.com/virtual-kubelet/virtual-kubelet/log" -) - -func TestImplementsLoggerInterface(t *testing.T) { - l := FromLogrus(&logrus.Entry{}) - - if _, ok := l.(log.Logger); !ok { - t.Fatal("does not implement log.Logger interface") - } -}