diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml index a5593b8b..91ebca5b 100644 --- a/.github/workflows/pr-build.yaml +++ b/.github/workflows/pr-build.yaml @@ -59,7 +59,7 @@ jobs: - id: profiles name: Determine test profiles run: | - profiles=$(ls deploy/tests/cases | jq -R -s -c 'split("\n")[:-1]') + profiles=$(ls config/tests/cases | jq -R -s -c 'split("\n")[:-1]') echo $profiles echo "::set-output name=matrix::$profiles" diff --git a/.goreleaser.yaml b/.goreleaser.yaml index fa2a3044..27c616ef 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,7 +1,7 @@ project_name: mongodb-query-exporter builds: -- id: cli +- id: main main: cmd/main.go binary: mongodb-query-exporter goos: @@ -12,10 +12,10 @@ builds: - CGO_ENABLED=0 archives: -- id: cli +- id: main name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" builds: - - cli + - main checksum: name_template: 'checksums.txt' @@ -35,11 +35,11 @@ sboms: dockers: - image_templates: - - ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }}-amd64 dockerfile: Dockerfile use: buildx ids: - - cli + - main build_flag_templates: - --platform=linux/amd64 - --label=org.opencontainers.image.title={{ .ProjectName }} @@ -51,12 +51,12 @@ dockers: - --label=org.opencontainers.image.revision={{ .FullCommit }} - --label=org.opencontainers.image.licenses=MIT - image_templates: - - "ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }}-arm64v8" + - "ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }}-arm64v8" goarch: arm64 dockerfile: Dockerfile use: buildx ids: - - cli + - main build_flag_templates: - --platform=linux/arm64/v8 - --label=org.opencontainers.image.title={{ .ProjectName }} @@ -69,14 +69,14 @@ dockers: - --label=org.opencontainers.image.licenses=MIT docker_manifests: -- name_template: ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }} +- name_template: ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }} image_templates: - - ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }}-arm64v8 + - ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }}-amd64 + - ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }}-arm64v8 - name_template: ghcr.io/raffis/{{ .ProjectName }}:latest image_templates: - - ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/raffis/{{ .ProjectName }}:{{ .Version }}-arm64v8 + - ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }}-amd64 + - ghcr.io/raffis/{{ .ProjectName }}:v{{ .Version }}-arm64v8 signs: - cmd: cosign @@ -96,9 +96,9 @@ docker_signs: - cmd: cosign env: - COSIGN_EXPERIMENTAL=1 - artifacts: images + artifacts: all output: true args: - 'sign' - '${artifact}' - - --yes + - --yes \ No newline at end of file diff --git a/Makefile b/Makefile index a7015216..83e31f4e 100644 --- a/Makefile +++ b/Makefile @@ -81,28 +81,19 @@ CLUSTER=kind kind-test: ## Deploy including test kind load docker-image ${IMG} --name ${CLUSTER} kubectl --context kind-${CLUSTER} -n mongo-system delete pods --all - kustomize build deploy/tests/cases/${TEST_PROFILE} --enable-helm | kubectl --context kind-${CLUSTER} apply -f - + kustomize build config/tests/cases/${TEST_PROFILE} --enable-helm | kubectl --context kind-${CLUSTER} apply -f - kubectl --context kind-${CLUSTER} -n mongo-system wait --for=jsonpath='{.status.conditions[1].reason}'=PodCompleted pods -l app.kubernetes.io/managed-by!=Helm -l verify=yes --timeout=3m - kustomize build deploy/tests/cases/${TEST_PROFILE} --enable-helm | kubectl --context kind-${CLUSTER} delete -f - + kustomize build config/tests/cases/${TEST_PROFILE} --enable-helm | kubectl --context kind-${CLUSTER} delete -f - .PHONY: deploy deploy: cd deploy/exporter && $(KUSTOMIZE) edit set image ghcr.io/raffis/mongodb-query-exporter=${IMG} - $(KUSTOMIZE) build deploy/exporter | kubectl apply -f - + $(KUSTOMIZE) build config/base | kubectl apply -f - .PHONY: undeploy undeploy: ## Undeploy exporter from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - -.PHONY: deploy-test -deploy-test: - cd deploy/test && $(KUSTOMIZE) edit set image ghcr.io/raffis/mongodb-query-exporter=${IMG} - $(KUSTOMIZE) build deploy/test | kubectl apply -f - - -.PHONY: undeploy-test -undeploy-test: ## Undeploy exporter from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. - $(KUSTOMIZE) build config/test | kubectl delete --ignore-not-found=$(ignore-not-found) -f - - .PHONY: all style fmt build test vet # go-install-tool will 'go install' any package $2 and install it to $1 diff --git a/README.md b/README.md index 9ce50ee4..78c0033d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Prometheus MongoDB query exporter [![release](https://github.com/raffis/mongodb-query-exporter/actions/workflows/release.yaml/badge.svg)](https://github.com/raffis/mongodb-query-exporter/actions/workflows/release.yaml) -[![Go Report Card](https://goreportcard.com/badge/github.com/raffis/mongodb-query-exporter/v2)](https://goreportcard.com/report/github.com/raffis/mongodb-query-exporter/v2) -[![PkgGoDev](https://pkg.go.dev/badge/github.com/raffis/mongodb-query-exporter/v2)](https://pkg.go.dev/github.com/raffis/mongodb-query-exporter/v2) +[![Go Report Card](https://goreportcard.com/badge/github.com/raffis/mongodb-query-exporter/v3)](https://goreportcard.com/report/github.com/raffis/mongodb-query-exporter/v3) [![Coverage Status](https://coveralls.io/repos/github/raffis/mongodb-query-exporter/badge.svg?branch=master)](https://coveralls.io/github/raffis/mongodb-query-exporter?branch=master) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/mongodb-query-exporter)](https://artifacthub.io/packages/search?repo=mongodb-query-exporter) diff --git a/chart/mongodb-query-exporter/Chart.yaml b/chart/mongodb-query-exporter/Chart.yaml index 665e978f..a8fef82d 100644 --- a/chart/mongodb-query-exporter/Chart.yaml +++ b/chart/mongodb-query-exporter/Chart.yaml @@ -15,4 +15,4 @@ keywords: name: mongodb-query-exporter sources: - https://github.com/raffis/mongodb-query-exporter -version: 3.0.2 +version: 4.0.0 diff --git a/chart/mongodb-query-exporter/templates/deployment.yaml b/chart/mongodb-query-exporter/templates/deployment.yaml index 84134763..5e0566e5 100644 --- a/chart/mongodb-query-exporter/templates/deployment.yaml +++ b/chart/mongodb-query-exporter/templates/deployment.yaml @@ -121,3 +121,7 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.topologySpreadConstraints }} + topologySpreadConstraints: + {{- toYaml .Values.topologySpreadConstraints | nindent 8 }} + {{- end }} diff --git a/chart/mongodb-query-exporter/templates/podsecuritypolicy.yaml b/chart/mongodb-query-exporter/templates/podsecuritypolicy.yaml deleted file mode 100644 index 3de9f16b..00000000 --- a/chart/mongodb-query-exporter/templates/podsecuritypolicy.yaml +++ /dev/null @@ -1,42 +0,0 @@ -{{- if .Values.podSecurityPolicy.enabled -}} -apiVersion: policy/v1beta1 -kind: PodSecurityPolicy -metadata: - name: {{ template "mongodb-query-exporter.fullname" . }} - {{- with ( include "mongodb-query-exporter.labels" . ) }} - labels: - {{- . }} - {{- end }} - {{- with .Values.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - privileged: false - allowPrivilegeEscalation: false - requiredDropCapabilities: - - ALL - volumes: - - 'secret' - hostNetwork: false - hostIPC: false - hostPID: false - runAsUser: - rule: 'MustRunAs' - ranges: - - min: 1 - max: 65535 - seLinux: - rule: 'RunAsAny' - supplementalGroups: - rule: 'MustRunAs' - ranges: - - min: 1 - max: 65535 - fsGroup: - rule: 'MustRunAs' - ranges: - - min: 1 - max: 65535 - readOnlyRootFilesystem: true -{{- end }} diff --git a/chart/mongodb-query-exporter/templates/role.yaml b/chart/mongodb-query-exporter/templates/role.yaml deleted file mode 100644 index a4e6bcd6..00000000 --- a/chart/mongodb-query-exporter/templates/role.yaml +++ /dev/null @@ -1,20 +0,0 @@ -{{- if .Values.podSecurityPolicy.enabled -}} -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ template "mongodb-query-exporter.fullname" . }} - {{- with ( include "mongodb-query-exporter.labels" . ) }} - labels: - {{- . }} - {{- end }} - {{- with .Values.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -rules: -- apiGroups: ['extensions'] - resources: ['podsecuritypolicies'] - verbs: ['use'] - resourceNames: - - {{ template "mongodb-query-exporter.fullname" . }} -{{- end }} diff --git a/chart/mongodb-query-exporter/templates/rolebinding.yaml b/chart/mongodb-query-exporter/templates/rolebinding.yaml deleted file mode 100644 index 8e641c34..00000000 --- a/chart/mongodb-query-exporter/templates/rolebinding.yaml +++ /dev/null @@ -1,26 +0,0 @@ -{{- if .Values.podSecurityPolicy.enabled }} -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: {{ template "mongodb-query-exporter.fullname" . }} - {{- with ( include "mongodb-query-exporter.labels" . ) }} - labels: - {{- . }} - {{- end }} - {{- with .Values.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: {{ template "mongodb-query-exporter.fullname" . }} -subjects: -- kind: ServiceAccount - {{- if .Values.serviceAccount.create }} - name: {{ template "mongodb-query-exporter.fullname" . }} - {{- else }} - name: {{ .Values.serviceAccount.name }} - {{- end }} - namespace: {{ .Release.Namespace }} -{{- end }} diff --git a/chart/mongodb-query-exporter/values.yaml b/chart/mongodb-query-exporter/values.yaml index 3c293be2..641b4320 100644 --- a/chart/mongodb-query-exporter/values.yaml +++ b/chart/mongodb-query-exporter/values.yaml @@ -1,5 +1,13 @@ +image: + pullPolicy: IfNotPresent + repository: ghcr.io/raffis/mongodb-query-exporter + tag: + + affinity: {} +topologySpreadConstraints: [] + chartLabels: true labels: {} @@ -10,11 +18,6 @@ extraArgs: fullnameOverride: "" -image: - pullPolicy: IfNotPresent - repository: ghcr.io/raffis/mongodb-query-exporter - tag: - imagePullSecrets: [] livenessProbe: @@ -156,11 +159,6 @@ serviceAccount: # fullname template. name: -# Creates a PodSecurityPolicy and the role/rolebinding -# allowing the serviceaccount to use it -podSecurityPolicy: - enabled: false - # Prometheus operator ServiceMonitor serviceMonitor: enabled: false diff --git a/cmd/main.go b/cmd/main.go index 4a41d788..bc445d12 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -8,11 +8,11 @@ import ( "os/user" "time" - "github.com/raffis/mongodb-query-exporter/v2/collector" - "github.com/raffis/mongodb-query-exporter/v2/config" - v1 "github.com/raffis/mongodb-query-exporter/v2/config/v1" - v2 "github.com/raffis/mongodb-query-exporter/v2/config/v2" - v3 "github.com/raffis/mongodb-query-exporter/v2/config/v3" + "github.com/raffis/mongodb-query-exporter/v3/internal/collector" + "github.com/raffis/mongodb-query-exporter/v3/internal/config" + v1 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v1" + v2 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v2" + v3 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v3" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -41,7 +41,6 @@ var ( panic(err) } - //reg := prometheus.NewRegistry() prometheus.MustRegister(c) promCollector = c _ = c.StartCacheInvalidator() diff --git a/deploy/base/deployment.yaml b/config/base/deployment.yaml similarity index 100% rename from deploy/base/deployment.yaml rename to config/base/deployment.yaml diff --git a/deploy/base/kustomization.yaml b/config/base/kustomization.yaml similarity index 100% rename from deploy/base/kustomization.yaml rename to config/base/kustomization.yaml diff --git a/deploy/base/service.yaml b/config/base/service.yaml similarity index 100% rename from deploy/base/service.yaml rename to config/base/service.yaml diff --git a/deploy/tests/base/default/kustomization.yaml b/config/tests/base/default/kustomization.yaml similarity index 100% rename from deploy/tests/base/default/kustomization.yaml rename to config/tests/base/default/kustomization.yaml diff --git a/deploy/tests/base/default/namespace.yaml b/config/tests/base/default/namespace.yaml similarity index 100% rename from deploy/tests/base/default/namespace.yaml rename to config/tests/base/default/namespace.yaml diff --git a/deploy/tests/base/mongodb/kustomization.yaml b/config/tests/base/mongodb/kustomization.yaml similarity index 100% rename from deploy/tests/base/mongodb/kustomization.yaml rename to config/tests/base/mongodb/kustomization.yaml diff --git a/deploy/tests/base/mongodb/root-secret.yaml b/config/tests/base/mongodb/root-secret.yaml similarity index 100% rename from deploy/tests/base/mongodb/root-secret.yaml rename to config/tests/base/mongodb/root-secret.yaml diff --git a/deploy/tests/cases/mongodb-v5/configmap.yaml b/config/tests/cases/mongodb-v5/configmap.yaml similarity index 100% rename from deploy/tests/cases/mongodb-v5/configmap.yaml rename to config/tests/cases/mongodb-v5/configmap.yaml diff --git a/deploy/tests/cases/mongodb-v5/kustomization.yaml b/config/tests/cases/mongodb-v5/kustomization.yaml similarity index 100% rename from deploy/tests/cases/mongodb-v5/kustomization.yaml rename to config/tests/cases/mongodb-v5/kustomization.yaml diff --git a/deploy/tests/cases/mongodb-v5/verify-get-metrics.yaml b/config/tests/cases/mongodb-v5/verify-get-metrics.yaml similarity index 100% rename from deploy/tests/cases/mongodb-v5/verify-get-metrics.yaml rename to config/tests/cases/mongodb-v5/verify-get-metrics.yaml diff --git a/go.mod b/go.mod index b6427ca4..fca15a18 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/raffis/mongodb-query-exporter/v2 +module github.com/raffis/mongodb-query-exporter/v3 go 1.20 diff --git a/collector/collector.go b/internal/collector/collector.go similarity index 100% rename from collector/collector.go rename to internal/collector/collector.go diff --git a/collector/collector_test.go b/internal/collector/collector_test.go similarity index 100% rename from collector/collector_test.go rename to internal/collector/collector_test.go diff --git a/collector/logger.go b/internal/collector/logger.go similarity index 100% rename from collector/logger.go rename to internal/collector/logger.go diff --git a/collector/mongodb.go b/internal/collector/mongodb.go similarity index 100% rename from collector/mongodb.go rename to internal/collector/mongodb.go diff --git a/collector/mongodb_test.go b/internal/collector/mongodb_test.go similarity index 100% rename from collector/mongodb_test.go rename to internal/collector/mongodb_test.go diff --git a/config/config.go b/internal/config/config.go similarity index 92% rename from config/config.go rename to internal/config/config.go index 5396a83e..70038ff3 100644 --- a/config/config.go +++ b/internal/config/config.go @@ -4,7 +4,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - "github.com/raffis/mongodb-query-exporter/v2/collector" + "github.com/raffis/mongodb-query-exporter/v3/internal/collector" ) // Config defaults diff --git a/config/v1/config.go b/internal/config/v1/config.go similarity index 94% rename from config/v1/config.go rename to internal/config/v1/config.go index ba0cb2b4..04f6968b 100644 --- a/config/v1/config.go +++ b/internal/config/v1/config.go @@ -6,9 +6,9 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - "github.com/raffis/mongodb-query-exporter/v2/collector" - "github.com/raffis/mongodb-query-exporter/v2/config" - "github.com/raffis/mongodb-query-exporter/v2/x/zap" + "github.com/raffis/mongodb-query-exporter/v3/internal/collector" + "github.com/raffis/mongodb-query-exporter/v3/internal/config" + "github.com/raffis/mongodb-query-exporter/v3/internal/x/zap" "go.mongodb.org/mongo-driver/mongo/options" ) diff --git a/config/v1/config_test.go b/internal/config/v1/config_test.go similarity index 100% rename from config/v1/config_test.go rename to internal/config/v1/config_test.go diff --git a/config/v2/config.go b/internal/config/v2/config.go similarity index 95% rename from config/v2/config.go rename to internal/config/v2/config.go index 5e6f1d18..f6fde0ba 100644 --- a/config/v2/config.go +++ b/internal/config/v2/config.go @@ -8,9 +8,9 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - "github.com/raffis/mongodb-query-exporter/v2/collector" - "github.com/raffis/mongodb-query-exporter/v2/config" - "github.com/raffis/mongodb-query-exporter/v2/x/zap" + "github.com/raffis/mongodb-query-exporter/v3/internal/collector" + "github.com/raffis/mongodb-query-exporter/v3/internal/config" + "github.com/raffis/mongodb-query-exporter/v3/internal/x/zap" "go.mongodb.org/mongo-driver/mongo/options" ) diff --git a/config/v2/config_test.go b/internal/config/v2/config_test.go similarity index 97% rename from config/v2/config_test.go rename to internal/config/v2/config_test.go index 24c80c5c..ed7c86d1 100644 --- a/config/v2/config_test.go +++ b/internal/config/v2/config_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/raffis/mongodb-query-exporter/v2/x/zap" + "github.com/raffis/mongodb-query-exporter/v3/internal/x/zap" "github.com/tj/assert" ) diff --git a/config/v3/config.go b/internal/config/v3/config.go similarity index 95% rename from config/v3/config.go rename to internal/config/v3/config.go index 87a73cfa..6d5d3f9d 100644 --- a/config/v3/config.go +++ b/internal/config/v3/config.go @@ -8,9 +8,9 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - "github.com/raffis/mongodb-query-exporter/v2/collector" - "github.com/raffis/mongodb-query-exporter/v2/config" - "github.com/raffis/mongodb-query-exporter/v2/x/zap" + "github.com/raffis/mongodb-query-exporter/v3/internal/collector" + "github.com/raffis/mongodb-query-exporter/v3/internal/config" + "github.com/raffis/mongodb-query-exporter/v3/internal/x/zap" "go.mongodb.org/mongo-driver/mongo/options" ) diff --git a/config/v3/config_test.go b/internal/config/v3/config_test.go similarity index 97% rename from config/v3/config_test.go rename to internal/config/v3/config_test.go index 9e7d925b..717cf26a 100644 --- a/config/v3/config_test.go +++ b/internal/config/v3/config_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/raffis/mongodb-query-exporter/v2/x/zap" + "github.com/raffis/mongodb-query-exporter/v3/internal/x/zap" "github.com/tj/assert" ) diff --git a/x/zap/zap.go b/internal/x/zap/zap.go similarity index 100% rename from x/zap/zap.go rename to internal/x/zap/zap.go