From d2f3c90009d35ed85257faccf083a46f42848e1d Mon Sep 17 00:00:00 2001 From: Arun Kumar Mohan Date: Sat, 15 Jan 2022 11:47:59 +0530 Subject: [PATCH] Adding the needed configs for LVM Operator Metrics Signed-off-by: Arun Kumar Mohan --- Dockerfile.combined | 3 --- Dockerfile.exporter | 31 ++++++++++++++++++++++ Makefile | 5 ++++ config/manager/manager.yaml | 11 ++++++-- config/prometheus/monitor.yaml | 6 +++++ config/rbac/lvm_metric_service_config.yaml | 15 +++++++++++ 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 Dockerfile.exporter create mode 100644 config/rbac/lvm_metric_service_config.yaml diff --git a/Dockerfile.combined b/Dockerfile.combined index 37b50c6db..32c9604d1 100644 --- a/Dockerfile.combined +++ b/Dockerfile.combined @@ -19,16 +19,13 @@ COPY pkg/ pkg/ # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o vgmanager cmd/vgmanager/main.go -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o metricsexporter cmd/metricsexporter/metrics_exporter.go # vgmanager needs 'nsenter' and other basic linux utils to correctly function FROM centos:8 WORKDIR / COPY --from=builder /workspace/manager . COPY --from=builder /workspace/vgmanager . -COPY --from=builder /workspace/metricsexporter . USER 65532:65532 -EXPOSE 23532 # '/manager' is lvm-operator entrypoint ENTRYPOINT ["/manager"] diff --git a/Dockerfile.exporter b/Dockerfile.exporter new file mode 100644 index 000000000..3cf35320f --- /dev/null +++ b/Dockerfile.exporter @@ -0,0 +1,31 @@ +# Build the manager binary +FROM golang:1.16 as builder + +WORKDIR /workspace +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download + +# Copy the go source +COPY api/ api/ +COPY controllers/ controllers/ +COPY cmd/ cmd/ +COPY pkg/ pkg/ + +# Build +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o metricsexporter cmd/metricsexporter/metrics_exporter.go + +# vgmanager needs 'nsenter' and other basic linux utils to correctly function +# FROM centos:8 +FROM alpine:edge +# get ca-cert package +RUN apk add --no-cache ca-certificates +WORKDIR / +COPY --from=builder /workspace/metricsexporter . +EXPOSE 23532 + +# '/metricsexporter' is lvm-operator's metric exporter entrypoint +ENTRYPOINT ["/metricsexporter"] diff --git a/Makefile b/Makefile index 126bebdde..8f5309c98 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ REGISTRY_NAMESPACE ?= ocs-dev IMAGE_TAG ?= latest IMAGE_NAME ?= lvm-operator VGMANAGER_IMAGE_NAME ?= vgmanager +EXPORTER_IMG_NAME ?= metricsexporter # IMG defines the image used for the operator. IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) @@ -43,6 +44,7 @@ RBAC_PROXY_IMG ?= gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 BUNDLE_IMAGE_NAME ?= $(IMAGE_NAME)-bundle BUNDLE_IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(BUNDLE_IMAGE_NAME):$(IMAGE_TAG) +EXPORTER_IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(EXPORTER_IMG_NAME):$(IMAGE_TAG) # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.22 @@ -138,6 +140,7 @@ docker-build-vgmanager: ## Build docker image with vgmanager. docker-build-combined: ## Build docker image with manager and vgmanager docker build -f Dockerfile.combined -t ${IMG} . + docker build -f Dockerfile.exporter -t ${EXPORTER_IMG} . docker-push: ## Push docker image with the manager. docker push ${IMG} @@ -146,6 +149,7 @@ docker-push-vgmanager: ## Push docker image with the vgmanager. docker push ${VGMANAGER_IMG} docker-push-combined: docker-push ## Push docker image containing both manager and vgmanager binaries + docker push ${EXPORTER_IMG} ##@ Deployment @@ -157,6 +161,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} + cd config/manager && $(KUSTOMIZE) edit set image exporter=${EXPORTER_IMG} cd config/default && $(KUSTOMIZE) edit set image rbac-proxy=$(RBAC_PROXY_IMG) $(KUSTOMIZE) build config/default | kubectl apply -f - diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 86033a3a3..31a9bbae4 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -12,15 +12,18 @@ metadata: namespace: system labels: control-plane: controller-manager + exporter: lvm-exporter spec: selector: matchLabels: control-plane: controller-manager + exporter: lvm-exporter replicas: 1 template: metadata: labels: control-plane: controller-manager + exporter: lvm-exporter spec: securityContext: runAsNonRoot: true @@ -66,9 +69,13 @@ spec: envFrom: - configMapRef: name: lvm-operator-manager-config - - name: metrics-exporter + - name: metricsexporter command: - /metricsexporter - image: controller:latest + image: exporter:latest + imagePullPolicy: Always + ports: + - containerPort: 23532 + name: http serviceAccountName: controller-manager terminationGracePeriodSeconds: 10 diff --git a/config/prometheus/monitor.yaml b/config/prometheus/monitor.yaml index 97bd8eab8..4d0c74c3e 100644 --- a/config/prometheus/monitor.yaml +++ b/config/prometheus/monitor.yaml @@ -15,6 +15,12 @@ spec: bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token tlsConfig: insecureSkipVerify: true + - path: /metrics + port: lvm-metrics + scheme: http + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + insecureSkipVerify: true selector: matchLabels: app.kubernetes.io/compose: metrics diff --git a/config/rbac/lvm_metric_service_config.yaml b/config/rbac/lvm_metric_service_config.yaml new file mode 100644 index 000000000..0dd9b8e3a --- /dev/null +++ b/config/rbac/lvm_metric_service_config.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: lvm-node-metrics + namespace: system + labels: + app.kubernetes.io/compose: metrics +spec: + selector: + exporter: lvm-operator + ports: + - name: lvm-metrics + protocol: TCP + port: 23532 + targetPort: 23532