Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit b9e5640

Browse files
committed
use golangci-lint, improve code quality
1 parent d6ec110 commit b9e5640

File tree

10 files changed

+54
-38
lines changed

10 files changed

+54
-38
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ go:
66
services:
77
- docker
88

9+
before_install:
10+
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.32.2
11+
912
script:
10-
- go vet ./...
1113
- make test
1214

1315
before_deploy: |

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 0.2.7
4+
5+
- Update dependencies
6+
37
### 0.2.6
48

59
- Update dependencies

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GOCLEAN=$(GOCMD) clean
44
GORUN=$(GOCMD) run
55
PROJECT=circa10a/k8s-label-rules-webhook
66
BINARY=webhook
7-
VERSION=0.2.6
7+
VERSION=0.2.7
88
GOBUILDFLAGS=-ldflags="-s -w -X main.Version=$(VERSION)"
99

1010
# First target for travis ci

api/docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ type swaggerInfo struct {
234234

235235
// SwaggerInfo holds exported Swagger Info so clients can modify it
236236
var SwaggerInfo = swaggerInfo{
237-
Version: "0.2.4",
237+
Version: "0.2.7",
238238
Host: "",
239239
BasePath: "",
240240
Schemes: []string{},

api/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"name": "MIT",
1212
"url": "https://github.com/circa10a/k8s-label-rules-webhook/blob/master/LICENSE"
1313
},
14-
"version": "0.2.4"
14+
"version": "0.2.7"
1515
},
1616
"paths": {
1717
"/": {

go.mod

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ require (
99
github.com/fatih/structs v1.1.0 // indirect
1010
github.com/gavv/httpexpect v2.0.0+incompatible
1111
github.com/gin-gonic/gin v1.6.3
12-
github.com/go-openapi/spec v0.19.10 // indirect
13-
github.com/go-openapi/swag v0.19.10 // indirect
12+
github.com/go-openapi/spec v0.19.12 // indirect
1413
github.com/go-playground/validator/v10 v10.4.1 // indirect
1514
github.com/google/go-querystring v1.0.0 // indirect
1615
github.com/gorilla/websocket v1.4.1 // indirect
@@ -26,9 +25,8 @@ require (
2625
github.com/sirupsen/logrus v1.7.0
2726
github.com/stretchr/testify v1.6.1
2827
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
29-
github.com/swaggo/gin-swagger v1.2.0
30-
github.com/swaggo/swag v1.6.8
31-
github.com/ugorji/go v1.1.13 // indirect
28+
github.com/swaggo/gin-swagger v1.3.0
29+
github.com/swaggo/swag v1.6.9
3230
github.com/valyala/fasthttp v1.7.0 // indirect
3331
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
3432
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
@@ -37,9 +35,10 @@ require (
3735
github.com/yudai/pp v2.0.1+incompatible // indirect
3836
github.com/zsais/go-gin-prometheus v0.1.0
3937
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
40-
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 // indirect
41-
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 // indirect
42-
golang.org/x/tools v0.0.0-20201019175715-b894a3290fff // indirect
38+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 // indirect
39+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf // indirect
40+
golang.org/x/text v0.3.4 // indirect
41+
golang.org/x/tools v0.0.0-20201105220310-78b158585360 // indirect
4342
google.golang.org/protobuf v1.25.0 // indirect
4443
gopkg.in/yaml.v2 v2.3.0
4544
)

go.sum

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ github.com/go-openapi/spec v0.19.0 h1:A4SZ6IWh3lnjH0rG0Z5lkxazMGBECtrZcbyYQi+64k
104104
github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
105105
github.com/go-openapi/spec v0.19.9 h1:9z9cbFuZJ7AcvOHKIY+f6Aevb4vObNDkTEyoMfO7rAc=
106106
github.com/go-openapi/spec v0.19.9/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28=
107-
github.com/go-openapi/spec v0.19.10 h1:pcNevfYytLaOQuTju0wm6OqcqU/E/pRwuSGigrLTI28=
108-
github.com/go-openapi/spec v0.19.10/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28=
107+
github.com/go-openapi/spec v0.19.12 h1:OO9WrvhDwtiMY/Opr1j1iFZzirI3JW4/bxNFRcntAr4=
108+
github.com/go-openapi/spec v0.19.12/go.mod h1:gwrgJS15eCUgjLpMjBJmbZezCsw88LmgeEip0M63doA=
109109
github.com/go-openapi/swag v0.17.0 h1:iqrgMg7Q7SvtbWLlltPrkMs0UBJI6oTSs79JFRUi880=
110110
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
111111
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
112112
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
113-
github.com/go-openapi/swag v0.19.10 h1:A1SWXruroGP15P1sOiegIPbaKio+G9N5TwWTFaVPmAU=
114-
github.com/go-openapi/swag v0.19.10/go.mod h1:Uc0gKkdR+ojzsEpjh39QChyu92vPgIr72POcgHMAgSY=
113+
github.com/go-openapi/swag v0.19.11 h1:RFTu/dlFySpyVvJDfp/7674JY4SDglYWKztbiIGFpmc=
114+
github.com/go-openapi/swag v0.19.11/go.mod h1:Uc0gKkdR+ojzsEpjh39QChyu92vPgIr72POcgHMAgSY=
115115
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
116116
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
117117
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
@@ -387,9 +387,11 @@ github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01S
387387
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E=
388388
github.com/swaggo/gin-swagger v1.2.0 h1:YskZXEiv51fjOMTsXrOetAjrMDfFaXD79PEoQBOe2W0=
389389
github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI=
390+
github.com/swaggo/gin-swagger v1.3.0 h1:eOmp7r57oUgZPw2dJOjcGNMse9cvXcI4tTqBcnZtPsI=
391+
github.com/swaggo/gin-swagger v1.3.0/go.mod h1:oy1BRA6WvgtCp848lhxce7BnWH4C8Bxa0m5SkWx+cS0=
390392
github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
391-
github.com/swaggo/swag v1.6.8 h1:z3ZNcpJs/NLMpZcKqXUsBELmmY2Ocy09JXKx5gu3L4M=
392-
github.com/swaggo/swag v1.6.8/go.mod h1:a0IpNeMfGidNOcm2TsqODUh9JHdHu3kxDA0UlGbBKjI=
393+
github.com/swaggo/swag v1.6.9 h1:BukKRwZjnEcUxQt7Xgfrt9fpav0hiWw9YimdNO9wssw=
394+
github.com/swaggo/swag v1.6.9/go.mod h1:a0IpNeMfGidNOcm2TsqODUh9JHdHu3kxDA0UlGbBKjI=
393395
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
394396
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
395397
github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0=
@@ -485,9 +487,9 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
485487
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
486488
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
487489
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
488-
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
489-
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg=
490-
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
490+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
491+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
492+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
491493
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
492494
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
493495
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -497,6 +499,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
497499
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
498500
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
499501
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
502+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
500503
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
501504
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
502505
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -527,13 +530,15 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7w
527530
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
528531
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
529532
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
530-
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 h1:5jaG59Zhd+8ZXe8C+lgiAGqkOaZBruqrWclLkgAww34=
531-
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
533+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf h1:kt3wY1Lu5MJAnKTfoMR52Cu4gwvna4VTzNOiT8tY73s=
534+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
532535
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
533536
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
534537
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
535538
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
536539
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
540+
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
541+
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
537542
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
538543
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
539544
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -554,8 +559,8 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn
554559
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
555560
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
556561
golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
557-
golang.org/x/tools v0.0.0-20201019175715-b894a3290fff h1:HiwHyqQ9ttqCHuTa++R4wNxOg6MY1hduSDT8j2aXoMM=
558-
golang.org/x/tools v0.0.0-20201019175715-b894a3290fff/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
562+
golang.org/x/tools v0.0.0-20201105220310-78b158585360 h1:/9CzsU8hOpnSUCtem1vfWNgsVeCTgkMdx+VE5YIYxnU=
563+
golang.org/x/tools v0.0.0-20201105220310-78b158585360/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
559564
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
560565
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
561566
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

main.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ var (
2626
TLSKey *string
2727
// TLSPort TLS listening port
2828
TLSPort *int
29-
// SwaggerAPIDocURLFlag Swagger URL Flag
30-
SwaggerAPIDocURLFlag *string
31-
// SwaggerAPIDocURLStr Swagger URL Flag
32-
SwaggerAPIDocURLStr string
3329
// R main rules struct to hold current ruleset
3430
R rules
3531
// Version is used to output the version of the application
@@ -69,7 +65,7 @@ func flags() {
6965
}
7066

7167
// @title k8s-label-rules-webhook
72-
// @version 0.2.3
68+
// @version 0.2.7
7369
// @description A kubernetes webhook to standardize labels on resources
7470

7571
// @contact.name GitHub
@@ -85,15 +81,24 @@ func main() {
8581
// Instantiate map to cache regex compilations in
8682
R.CompiledRegexs = make(map[string]*regexp.Regexp)
8783
// Load initial rules into memory
88-
R.load(*FilePath)
84+
err := R.load(*FilePath)
85+
if err != nil {
86+
log.Error(err)
87+
}
8988
// Initialize paths and handlers in routes.go
9089
routes(G)
9190
// Listen via https if TLS enabled
9291
if *TLS {
93-
G.RunTLS(fmt.Sprintf(":%v", *TLSPort), *TLSCert, *TLSKey)
92+
err = G.RunTLS(fmt.Sprintf(":%v", *TLSPort), *TLSCert, *TLSKey)
93+
if err != nil {
94+
log.Fatal(err)
95+
}
9496
}
9597
// Else listen on http
9698
// Defaults to port 8080, can be overridden via PORT env var.
9799
// Example: export PORT=3000
98-
G.Run()
100+
err = G.Run()
101+
if err != nil {
102+
log.Fatal(err)
103+
}
99104
}

routes_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/gavv/httpexpect"
10+
log "github.com/sirupsen/logrus"
1011
)
1112

1213
func init() {
@@ -16,7 +17,10 @@ func init() {
1617
// Init map to store compiled regexs
1718
R.CompiledRegexs = make(map[string]*regexp.Regexp)
1819
// Load initial rules into memory
19-
R.load(*FilePath)
20+
err := R.load(*FilePath)
21+
if err != nil {
22+
log.Error(err)
23+
}
2024
// load handlers into gin engine
2125
routes(G)
2226
}

rules.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ type ruleError struct {
3535
func (r *rules) load(path string) error {
3636
rulesData, _ := readFile(path)
3737
err := yaml.Unmarshal([]byte(rulesData), &r)
38-
if err != nil {
39-
log.Error(err)
40-
}
4138
r.compileRegex(true)
4239
// Should return nil
4340
return err
@@ -91,7 +88,7 @@ func (r *rules) ensureLabelsMatchRules(labels map[string]interface{}) error {
9188
}
9289
// Force all values to strings to prevent panic from interface conversion
9390
labelVal := fmt.Sprintf("%v", labels[rule.Key])
94-
regex, _ := r.CompiledRegexs[rule.Name]
91+
regex := r.CompiledRegexs[rule.Name]
9592
if !regex.MatchString(labelVal) {
9693
errStr := fmt.Sprintf("Value for label '%v' does not match expression '%v'", rule.Key, rule.Value.Regex)
9794
return errors.New(errStr)

0 commit comments

Comments
 (0)