File tree Expand file tree Collapse file tree 15 files changed +265
-110
lines changed
Expand file tree Collapse file tree 15 files changed +265
-110
lines changed Original file line number Diff line number Diff line change 11.github
2+ .gitignore
3+ .golangci.yaml
24.task
35charts
46test
57tmp
8+ CONTRIBUTING.md
9+ LICENSE
10+ README.md
Original file line number Diff line number Diff line change 1+ # syntax = docker/dockerfile:1-experimental
2+
13FROM golang:1.18.3 AS build
24
35ENV TASK_VER 3.13.0
@@ -11,11 +13,16 @@ RUN echo "Fetching dev dependencies" && \
1113
1214COPY . .
1315
14- RUN echo "Building" && \
16+ RUN \
17+ --mount=type=cache,target=/root/.cache/go-build \
18+ echo "Building" && \
1519 task build-bin && \
1620 echo
1721
18- RUN echo "Linting" && \
22+ RUN \
23+ --mount=type=cache,target=/root/.cache/go-build \
24+ --mount=type=cache,target=/root/.cache/golangci-lint \
25+ echo "Linting" && \
1926 task lint && \
2027 echo
2128
Original file line number Diff line number Diff line change @@ -57,34 +57,38 @@ tasks:
5757 CGO_ENABLED : " 0"
5858 GOARCH : " {{ ARCH }}"
5959 sources :
60- - main.go
61- - pkg
60+ - cmd/**/*
61+ - internal/**/*
62+ - pkg/**/*
6263 - go.mod
6364 - go.sum
6465 generates :
6566 - " {{ .BIN_NAME }}"
6667
68+ # TODO: Unit tests
6769 # test:
6870 # desc: Run tests.
6971 # cmds:
70- # # TODO: Unit tests
71- # # - go test ./... -v -short {{ .CLI_ARGS }}
72+ # - go test ./... -v -short {{ .CLI_ARGS }}
7273 # sources:
73- # - main.go
74- # - pkg
74+ # - cmd/**/*
75+ # - internal/**/*
76+ # - pkg/**/*
7577 # - go.mod
7678 # - go.sum
7779
7880 lint :
7981 desc : Run the linter.
8082 cmds :
81- - golangci-lint run ./... --timeout {{ .TIMEOUT }} {{ .CLI_ARGS }}
83+ - GOGC=100 golangci-lint run ./... --timeout {{ .TIMEOUT }} {{ .CLI_ARGS }}
8284 vars :
8385 TIMEOUT : 1m
8486 sources :
85- - main.go
86- - pkg
87- - .golangci.yaml
87+ - cmd/**/*
88+ - internal/**/*
89+ - pkg/**/*
90+ - go.mod
91+ - go.sum
8892
8993 tidy :
9094 desc : Tidy up go deps.
@@ -99,14 +103,7 @@ tasks:
99103 build :
100104 desc : Build the docker image and generate a unique tag to force redeployment.
101105 cmds :
102- - docker build --tag {{ .IMAGE_NAME }}:{{ .IMAGE_TAG }} --progress plain .
103- sources :
104- - Dockerfile
105- - cmd/**/*
106- - internal/**/*
107- - pkg/**/*
108- - go.mod
109- - go.sum
106+ - DOCKER_BUILDKIT=1 docker build --tag {{ .IMAGE_NAME }}:{{ .IMAGE_TAG }} .
110107
111108 template :
112109 desc : Provide the opa-exporter template and invoke it with a variable kubectl command.
@@ -119,6 +116,8 @@ tasks:
119116 --values charts/opa-exporter/values.yaml \
120117 --set image.tag={{ .IMAGE_TAG }} \
121118 --set exporter.interval=10s \
119+ --set exporter.logLevel=debug \
120+ --set exporter.logMode=development \
122121 charts/opa-exporter \
123122 > {{ .TMP_DIR }}/opa-exporter.yaml
124123 - kubectl --context {{ .CONTEXT }} {{ .ACTION }} --wait --filename {{ .TMP_DIR }}/opa-exporter.yaml
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ apiVersion: v2
22name : opa-exporter
33description : Helm chart for opa-exporter, a prometheus exporter for OPA Gatekeeper.
44type : application
5- version : 0.1.2
6- appVersion : 0.2 .0
5+ version : 0.1.3
6+ appVersion : 0.3 .0
77home : https://github.com/csullivanupgrade/opa-exporter
Original file line number Diff line number Diff line change 88 configuration-file : |
99 inCluster: {{ .Values.exporter.inCluster }}
1010 interval: {{ .Values.exporter.interval }}
11+ logMode: {{ .Values.exporter.logMode }}
12+ logLevel: {{ .Values.exporter.logLevel }}
1113 namespace: {{ .Values.exporter.namespace }}
1214 path: {{ .Values.exporter.path }}
1315 port: {{ .Values.exporter.port }}
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ exporter:
66 interval : " 60s"
77 # -- namespace the exporter is running in (does not affect operations - used for metrics FQDN)
88 namespace : default
9+ # -- log level to use, uses Zap levels
10+ logLevel : info
11+ # -- log mode to use:
12+ # ---- `development` adds extra stacktrace/codepath fields
13+ # ---- `nop` disables the logger
14+ logMode : production
915 # -- path for metrics server to listen
1016 path : " metrics"
1117 # -- port for the server to listen
Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "context"
45 "flag"
56
67 "github.com/csullivanupgrade/opa-exporter/internal/config"
8+ "github.com/csullivanupgrade/opa-exporter/internal/log"
79 "github.com/csullivanupgrade/opa-exporter/internal/server"
810)
911
1012func main () {
1113 configFile := flag .String ("config" , "" , "The path for the config file" )
1214 flag .Parse ()
1315 cfg := config .New (* configFile )
14- server .Run (* cfg )
16+
17+ logger := log .NewLogger (cfg .LogLevel , cfg .LogMode )
18+
19+ ctx , cancel := context .WithCancel (log .SetContext (context .Background (), logger ))
20+
21+ server .Run (ctx , * cfg )
22+ defer cancel ()
1523}
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ require (
5050 github.com/spf13/pflag v1.0.5 // indirect
5151 github.com/spf13/viper v1.12.0 // indirect
5252 github.com/subosito/gotenv v1.3.0 // indirect
53+ go.uber.org/atomic v1.7.0 // indirect
54+ go.uber.org/multierr v1.6.0 // indirect
55+ go.uber.org/zap v1.21.0 // indirect
5356 golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
5457 golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
5558 golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
Original file line number Diff line number Diff line change @@ -549,6 +549,7 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
549549go.uber.org/atomic v1.7.0 /go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc =
550550go.uber.org/goleak v1.1.10 /go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A =
551551go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 /go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ =
552+ go.uber.org/goleak v1.1.11 /go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ =
552553go.uber.org/goleak v1.1.12 /go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ =
553554go.uber.org/multierr v1.1.0 /go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0 =
554555go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4 =
@@ -558,6 +559,8 @@ go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
558559go.uber.org/zap v1.19.0 /go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI =
559560go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI =
560561go.uber.org/zap v1.19.1 /go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI =
562+ go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8 =
563+ go.uber.org/zap v1.21.0 /go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw =
561564golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 /go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4 =
562565golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3 /go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4 =
563566golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 /go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w =
You can’t perform that action at this time.
0 commit comments