From 31c583d9f9da93f5bbcc43b1473ff0b65362f397 Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Wed, 7 Dec 2022 20:04:48 -0500 Subject: [PATCH 1/3] add skaffold, multitarget builds, fix port in chart --- .earthlyignore | 1 + .tool-versions | 1 + Earthfile | 55 +++++++++++++------ .../templates/controller.yaml | 10 ++-- .../templates/podmonitor.yaml | 2 + .../templates/servicemonitor.yaml | 2 + .../values.schema.json | 18 ++++++ charts/prom-aggregation-gateway/values.yaml | 6 ++ main.go | 12 ++++ skaffold.yaml | 23 ++++++++ 10 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 .earthlyignore create mode 100644 skaffold.yaml diff --git a/.earthlyignore b/.earthlyignore new file mode 100644 index 0000000..69d65e3 --- /dev/null +++ b/.earthlyignore @@ -0,0 +1 @@ +/Earthfile diff --git a/.tool-versions b/.tool-versions index 483f28a..a825184 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,4 @@ # asdf plugin add earthly https://github.com/YR-ZR0/asdf-earthly earthly 0.6.30 golang 1.19.3 +skaffold 2.0.3 diff --git a/Earthfile b/Earthfile index add0752..4fcb3f5 100644 --- a/Earthfile +++ b/Earthfile @@ -24,7 +24,6 @@ ci-helm: BUILD +test-helm build: - BUILD +build-binary BUILD +build-docker BUILD +build-helm @@ -32,6 +31,22 @@ release: BUILD +release-binary BUILD +build-docker +go-deps: + FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} + + WORKDIR /src + COPY go.mod go.sum /src + RUN go mod download + +build-binary: + FROM +go-deps + + WORKDIR /src + COPY . /src + RUN go build -o prom-aggregation-gateway . + + SAVE ARTIFACT ./prom-aggregation-gateway + build-docker: FROM alpine:${ALPINE_VERSION} COPY +build-binary/prom-aggregation-gateway . @@ -41,29 +56,35 @@ build-docker: continuous-deploy: BUILD +release-helm -go-deps: - FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} +build-binaries: + FROM golang:${GOLANG_VERSION} WORKDIR /src - COPY go.mod go.sum /src - RUN go mod download - SAVE ARTIFACT go.mod AS LOCAL go.mod - SAVE ARTIFACT go.sum AS LOCAL go.sum + RUN go install github.com/mitchellh/gox@latest -build-binary: - FROM +go-deps + COPY go.mod go.sum /src + RUN go mod download - WORKDIR /src COPY . /src - RUN go build -o prom-aggregation-gateway . - SAVE ARTIFACT ./prom-aggregation-gateway AS LOCAL ./dist/ + RUN \ + GOFLAGS="-trimpath" \ + GO111MODULE=on \ + CGO_ENABLED=0 \ + gox \ + -parallel=3 \ + -ldflags "-X main.version=${version}" \ + -output="_dist/prom-aggregation-gateway-${version}-{{.OS}}-{{.Arch}}" \ + -osarch='darwin/amd64 darwin/arm64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x windows/amd64' \ + . -release-binary: - FROM +build-binary + SAVE ARTIFACT _dist AS LOCAL ./dist - COPY +build-binary/prom-aggregation-gateway . +release-binaries: + FROM alpine:${ALPINE_VERSION} + + COPY +build-binaries/_dist . # install github cli RUN FILE=ghcli.tgz \ @@ -79,9 +100,9 @@ release-binary: && gh version RUN apk add --no-cache git - + ENV GH_TOKEN $token - RUN --push gh release create ${version} ./prom-aggregation-gateway + RUN --push gh release create ${version} ./dist/* lint-golang: FROM +go-deps diff --git a/charts/prom-aggregation-gateway/templates/controller.yaml b/charts/prom-aggregation-gateway/templates/controller.yaml index 162fca4..197988e 100644 --- a/charts/prom-aggregation-gateway/templates/controller.yaml +++ b/charts/prom-aggregation-gateway/templates/controller.yaml @@ -24,8 +24,10 @@ spec: - name: prom-aggregation-gateway image: {{ .Values.controller.image.repository }}:{{ .Values.controller.image.tag }} args: - - --listen=":8080" - - --metricsListen=":8888" + - --listen + - :8080 + - --metricsListen + - :8888 ports: - name: http containerPort: 8080 @@ -33,11 +35,11 @@ spec: containerPort: 8888 livenessProbe: httpGet: - path: /-/healthy + path: /healthy port: http readinessProbe: httpGet: - path: /-/ready + path: /ready port: http {{- with .Values.controller.resources }} resources: {{ . | toYaml | nindent 12 }} diff --git a/charts/prom-aggregation-gateway/templates/podmonitor.yaml b/charts/prom-aggregation-gateway/templates/podmonitor.yaml index 082563c..f548aef 100644 --- a/charts/prom-aggregation-gateway/templates/podmonitor.yaml +++ b/charts/prom-aggregation-gateway/templates/podmonitor.yaml @@ -1,3 +1,4 @@ +{{- if .Values.podMonitor.create }} apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: @@ -8,3 +9,4 @@ spec: {{- include "prom-aggregation-gateway.selectorLabels" . | nindent 6 }} podMetricsEndpoints: - port: metrics +{{- end }} diff --git a/charts/prom-aggregation-gateway/templates/servicemonitor.yaml b/charts/prom-aggregation-gateway/templates/servicemonitor.yaml index 532c285..34e9b65 100644 --- a/charts/prom-aggregation-gateway/templates/servicemonitor.yaml +++ b/charts/prom-aggregation-gateway/templates/servicemonitor.yaml @@ -1,3 +1,4 @@ +{{- if .Values.serviceMonitor.create }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: @@ -8,3 +9,4 @@ spec: {{- include "prom-aggregation-gateway.selectorLabels" . | nindent 6 }} endpoints: - port: http +{{- end }} diff --git a/charts/prom-aggregation-gateway/values.schema.json b/charts/prom-aggregation-gateway/values.schema.json index d588d5e..8450a8b 100644 --- a/charts/prom-aggregation-gateway/values.schema.json +++ b/charts/prom-aggregation-gateway/values.schema.json @@ -56,6 +56,24 @@ "type": "integer" } } + }, + "podMonitor": { + "type": "object", + "additionalProperties": false, + "properties": { + "create": { + "type": "boolean" + } + } + }, + "serviceMonitor": { + "type": "object", + "additionalProperties": false, + "properties": { + "create": { + "type": "boolean" + } + } } } } diff --git a/charts/prom-aggregation-gateway/values.yaml b/charts/prom-aggregation-gateway/values.yaml index 1a5acca..4e777a7 100644 --- a/charts/prom-aggregation-gateway/values.yaml +++ b/charts/prom-aggregation-gateway/values.yaml @@ -7,9 +7,15 @@ controller: type: Deployment +podMonitor: + create: true + service: create: true annotations: {} type: LoadBalancer port: 8080 nodePort: 12345 + +serviceMonitor: + create: true diff --git a/main.go b/main.go index bba82c3..5cf91da 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "log" "net/http" "os" @@ -12,17 +13,28 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) +var version = "0.0.0" + func handleHealthCheck(c *gin.Context) { c.Header("Content-Type", "application/json") c.JSON(http.StatusOK, `{"alive": true}`) } func main() { + var ( + showVersion = false + ) listen := flag.String("listen", ":80", "Address and port to listen on.") metricsListen := flag.String("metricsListen", ":8888", "Address and port serve the metrics endpoint on") cors := flag.String("cors", "*", "The 'Access-Control-Allow-Origin' value to be returned.") + flag.BoolVar(&showVersion, "version", false, "Display the version") flag.Parse() + if showVersion { + fmt.Printf("%s\n", version) + return + } + sigChannel := make(chan os.Signal, 1) signal.Notify(sigChannel, syscall.SIGTERM, syscall.SIGINT) diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..12ec1e0 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,23 @@ +# nonk8s +apiVersion: skaffold/v4beta1 +kind: Config +metadata: + name: prom-aggregation-gateway +build: + artifacts: + - image: ghcr.io/zapier/prom-aggregation-gateway + custom: + buildCommand: earthly +build-docker --version=dev + tagPolicy: + customTemplate: + template: dev +manifests: + helm: + releases: + - name: prom-aggregation-gateway + chartPath: ./charts/prom-aggregation-gateway + createNamespace: true + setValues: + image.tag: dev + podMonitor.create: false + serviceMonitor.create: false From 60618a17deab95b4651caf49311c1fb11e7ca68c Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Wed, 7 Dec 2022 20:07:23 -0500 Subject: [PATCH 2/3] bump helm chart --- charts/prom-aggregation-gateway/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/prom-aggregation-gateway/Chart.yaml b/charts/prom-aggregation-gateway/Chart.yaml index 5432973..50b6d0d 100644 --- a/charts/prom-aggregation-gateway/Chart.yaml +++ b/charts/prom-aggregation-gateway/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: prom-aggregation-gateway -version: 0.4.0 +version: 0.4.1 home: https://github.com/zapier/prom-aggregation-gateway maintainers: - name: djeebus From c3ef464cbe399a69cc54360f3caf5639e6705ef2 Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Wed, 7 Dec 2022 20:27:57 -0500 Subject: [PATCH 3/3] remove unused ARG --- Earthfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Earthfile b/Earthfile index 4fcb3f5..242cae9 100644 --- a/Earthfile +++ b/Earthfile @@ -133,7 +133,6 @@ test-golang: RUN go test . test-helm: - ARG ct_args='' FROM quay.io/helmpack/chart-testing:v${CHART_TESTING_VERSION} # install kubeconform