Skip to content

Commit 7f3562c

Browse files
authored
Update to Go 1.20 and update Go module dependencies (#23)
1 parent 15c70a8 commit 7f3562c

File tree

8 files changed

+98
-561
lines changed

8 files changed

+98
-561
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ executors:
1010
# also be updated.
1111
golang:
1212
docker:
13-
- image: circleci/golang:1.17
13+
- image: cimg/go:1.20.3
1414

1515
jobs:
1616
test:

.promu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
go:
2-
version: 1.17
2+
version: 1.20
33
cgo: true
44
repository:
55
path: github.com/treydock/cgroup_exporter

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Needs to be defined before including Makefile.common to auto-generate targets
22
DOCKER_ARCHS ?= amd64 arm64 ppc64le
33
DOCKER_REPO ?= treydock
4-
GOLANGCI_LINT_VERSION ?= v1.50.1
4+
export GOPATH ?= $(firstword $(subst :, ,$(shell go env GOPATH)))
55

66
include Makefile.common
77

Makefile.common

Lines changed: 41 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,6 @@ GO_VERSION ?= $(shell $(GO) version)
3636
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
3737
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
3838

39-
GOVENDOR :=
40-
GO111MODULE :=
41-
ifeq (, $(PRE_GO_111))
42-
ifneq (,$(wildcard go.mod))
43-
# Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
44-
GO111MODULE := on
45-
46-
ifneq (,$(wildcard vendor))
47-
# Always use the local vendor/ directory to satisfy the dependencies.
48-
GOOPTS := $(GOOPTS) -mod=vendor
49-
endif
50-
endif
51-
else
52-
ifneq (,$(wildcard go.mod))
53-
ifneq (,$(wildcard vendor))
54-
$(warning This repository requires Go >= 1.11 because of Go modules)
55-
$(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
56-
endif
57-
else
58-
# This repository isn't using Go modules (yet).
59-
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
60-
endif
61-
endif
6239
PROMU := $(FIRST_GOPATH)/bin/promu
6340
pkgs = ./...
6441

@@ -78,17 +55,26 @@ ifneq ($(shell which gotestsum),)
7855
endif
7956
endif
8057

81-
PROMU_VERSION ?= 0.12.0
58+
PROMU_VERSION ?= 0.14.0
8259
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
8360

61+
SKIP_GOLANGCI_LINT :=
8462
GOLANGCI_LINT :=
8563
GOLANGCI_LINT_OPTS ?=
86-
GOLANGCI_LINT_VERSION ?= v1.39.0
64+
GOLANGCI_LINT_VERSION ?= v1.51.2
8765
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8866
# windows isn't included here because of the path separator being different.
8967
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
9068
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
91-
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
69+
# If we're in CI and there is an Actions file, that means the linter
70+
# is being run in Actions, so we don't need to run it here.
71+
ifneq (,$(SKIP_GOLANGCI_LINT))
72+
GOLANGCI_LINT :=
73+
else ifeq (,$(CIRCLE_JOB))
74+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
75+
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
76+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
77+
endif
9278
endif
9379
endif
9480

@@ -105,6 +91,8 @@ BUILD_DOCKER_ARCHS = $(addprefix common-docker-,$(DOCKER_ARCHS))
10591
PUBLISH_DOCKER_ARCHS = $(addprefix common-docker-publish-,$(DOCKER_ARCHS))
10692
TAG_DOCKER_ARCHS = $(addprefix common-docker-tag-latest-,$(DOCKER_ARCHS))
10793

94+
SANITIZED_DOCKER_IMAGE_TAG := $(subst +,-,$(DOCKER_IMAGE_TAG))
95+
10896
ifeq ($(GOHOSTARCH),amd64)
10997
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
11098
# Only supported on amd64
@@ -118,7 +106,7 @@ endif
118106
%: common-% ;
119107

120108
.PHONY: common-all
121-
common-all: precheck style check_license lint unused build test
109+
common-all: precheck style check_license lint yamllint unused build test
122110

123111
.PHONY: common-style
124112
common-style:
@@ -144,87 +132,72 @@ common-check_license:
144132
.PHONY: common-deps
145133
common-deps:
146134
@echo ">> getting dependencies"
147-
ifdef GO111MODULE
148-
GO111MODULE=$(GO111MODULE) $(GO) mod download
149-
else
150-
$(GO) get $(GOOPTS) -t ./...
151-
endif
135+
$(GO) mod download
152136

153137
.PHONY: update-go-deps
154138
update-go-deps:
155139
@echo ">> updating Go dependencies"
156140
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
157-
$(GO) get $$m; \
141+
$(GO) get -d $$m; \
158142
done
159-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
160-
ifneq (,$(wildcard vendor))
161-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
162-
endif
143+
$(GO) mod tidy
163144

164145
.PHONY: common-test-short
165146
common-test-short: $(GOTEST_DIR)
166147
@echo ">> running short tests"
167-
GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
148+
$(GOTEST) -short $(GOOPTS) $(pkgs)
168149

169150
.PHONY: common-test
170151
common-test: $(GOTEST_DIR)
171152
@echo ">> running all tests"
172-
GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
153+
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
173154

174155
$(GOTEST_DIR):
175156
@mkdir -p $@
176157

177158
.PHONY: common-format
178159
common-format:
179160
@echo ">> formatting code"
180-
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
161+
$(GO) fmt $(pkgs)
181162

182163
.PHONY: common-vet
183164
common-vet:
184165
@echo ">> vetting code"
185-
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
166+
$(GO) vet $(GOOPTS) $(pkgs)
186167

187168
.PHONY: common-lint
188169
common-lint: $(GOLANGCI_LINT)
189170
ifdef GOLANGCI_LINT
190171
@echo ">> running golangci-lint"
191-
ifdef GO111MODULE
192172
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
193173
# Otherwise staticcheck might fail randomly for some reason not yet explained.
194-
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
195-
GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
196-
else
197-
$(GOLANGCI_LINT) run $(pkgs)
174+
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
175+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
198176
endif
177+
178+
.PHONY: common-yamllint
179+
common-yamllint:
180+
@echo ">> running yamllint on all YAML files in the repository"
181+
ifeq (, $(shell which yamllint))
182+
@echo "yamllint not installed so skipping"
183+
else
184+
yamllint .
199185
endif
200186

201187
# For backward-compatibility.
202188
.PHONY: common-staticcheck
203189
common-staticcheck: lint
204190

205191
.PHONY: common-unused
206-
common-unused: $(GOVENDOR)
207-
ifdef GOVENDOR
208-
@echo ">> running check for unused packages"
209-
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
210-
else
211-
ifdef GO111MODULE
192+
common-unused:
212193
@echo ">> running check for unused/missing packages in go.mod"
213-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
214-
ifeq (,$(wildcard vendor))
194+
$(GO) mod tidy
215195
@git diff --exit-code -- go.sum go.mod
216-
else
217-
@echo ">> running check for unused packages in vendor/"
218-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
219-
@git diff --exit-code -- go.sum go.mod vendor/
220-
endif
221-
endif
222-
endif
223196

224197
.PHONY: common-build
225198
common-build: promu
226199
@echo ">> building binaries"
227-
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
200+
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
228201

229202
.PHONY: common-tarball
230203
common-tarball: promu
@@ -234,7 +207,7 @@ common-tarball: promu
234207
.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
235208
common-docker: $(BUILD_DOCKER_ARCHS)
236209
$(BUILD_DOCKER_ARCHS): common-docker-%:
237-
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" \
210+
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \
238211
-f $(DOCKERFILE_PATH) \
239212
--build-arg ARCH="$*" \
240213
--build-arg OS="linux" \
@@ -243,19 +216,19 @@ $(BUILD_DOCKER_ARCHS): common-docker-%:
243216
.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS)
244217
common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
245218
$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
246-
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)"
219+
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)"
247220

248221
DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
249222
.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
250223
common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
251224
$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
252-
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
253-
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
225+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
226+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
254227

255228
.PHONY: common-docker-manifest
256229
common-docker-manifest:
257-
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(DOCKER_IMAGE_TAG))
258-
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)"
230+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(SANITIZED_DOCKER_IMAGE_TAG))
231+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)"
259232

260233
.PHONY: promu
261234
promu: $(PROMU)
@@ -280,12 +253,6 @@ $(GOLANGCI_LINT):
280253
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
281254
endif
282255

283-
ifdef GOVENDOR
284-
.PHONY: $(GOVENDOR)
285-
$(GOVENDOR):
286-
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
287-
endif
288-
289256
.PHONY: precheck
290257
precheck::
291258

cgroup_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626
"sync"
2727

28+
"github.com/alecthomas/kingpin/v2"
2829
"github.com/containerd/cgroups"
2930
"github.com/go-kit/log"
3031
"github.com/go-kit/log/level"
@@ -34,7 +35,6 @@ import (
3435
"github.com/prometheus/common/promlog/flag"
3536
"github.com/prometheus/common/version"
3637
"github.com/prometheus/procfs"
37-
"gopkg.in/alecthomas/kingpin.v2"
3838
)
3939

4040
const (

cgroup_exporter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
"testing"
2626
"time"
2727

28+
kingpin "github.com/alecthomas/kingpin/v2"
2829
"github.com/go-kit/log"
29-
kingpin "gopkg.in/alecthomas/kingpin.v2"
3030
)
3131

3232
const (

go.mod

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
module github.com/treydock/cgroup_exporter
22

3-
go 1.17
3+
go 1.20
44

55
require (
6-
github.com/containerd/cgroups v1.0.3
7-
github.com/go-kit/log v0.2.0
8-
github.com/prometheus/client_golang v1.12.1
9-
github.com/prometheus/common v0.32.1
10-
github.com/prometheus/procfs v0.7.3
11-
gopkg.in/alecthomas/kingpin.v2 v2.2.6
6+
github.com/alecthomas/kingpin/v2 v2.3.2
7+
github.com/containerd/cgroups v1.1.0
8+
github.com/go-kit/log v0.2.1
9+
github.com/prometheus/client_golang v1.15.1
10+
github.com/prometheus/common v0.43.0
11+
github.com/prometheus/procfs v0.9.0
1212
)
1313

1414
require (
15-
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
1615
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
1716
github.com/beorn7/perks v1.0.1 // indirect
18-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
19-
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
20-
github.com/docker/go-units v0.4.0 // indirect
21-
github.com/go-logfmt/logfmt v0.5.1 // indirect
17+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
18+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
19+
github.com/docker/go-units v0.5.0 // indirect
20+
github.com/go-logfmt/logfmt v0.6.0 // indirect
2221
github.com/godbus/dbus/v5 v5.1.0 // indirect
2322
github.com/gogo/protobuf v1.3.2 // indirect
24-
github.com/golang/protobuf v1.5.2 // indirect
25-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
23+
github.com/golang/protobuf v1.5.3 // indirect
24+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
2625
github.com/opencontainers/runtime-spec v1.0.2 // indirect
27-
github.com/pkg/errors v0.9.1 // indirect
28-
github.com/prometheus/client_model v0.2.0 // indirect
29-
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
30-
google.golang.org/protobuf v1.27.1 // indirect
26+
github.com/prometheus/client_model v0.4.0 // indirect
27+
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
28+
golang.org/x/sys v0.8.0 // indirect
29+
google.golang.org/protobuf v1.30.0 // indirect
3130
)

0 commit comments

Comments
 (0)