Skip to content

Commit

Permalink
Adding the needed configs for LVM Operator Metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Arun Kumar Mohan <amohan@redhat.com>
  • Loading branch information
aruniiird committed Jan 15, 2022
1 parent 1a07580 commit d2f3c90
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
3 changes: 0 additions & 3 deletions Dockerfile.combined
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile.exporter
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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

Expand All @@ -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 -

Expand Down
11 changes: 9 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions config/rbac/lvm_metric_service_config.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d2f3c90

Please sign in to comment.