Skip to content

Commit

Permalink
Merge pull request #9 from grzegorzgniadek/dev
Browse files Browse the repository at this point in the history
Prom metrics-release
  • Loading branch information
grzegorzgniadek authored Aug 20, 2024
2 parents 45bfa78 + c78e59b commit 9036e60
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.6.0
5 changes: 2 additions & 3 deletions charts/interpolator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.0
version: 0.6.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.0"

appVersion: "0.6.0"
19 changes: 14 additions & 5 deletions charts/interpolator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



![Version: 0.5.0](https://img.shields.io/badge/Version-0.5.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.5.0](https://img.shields.io/badge/AppVersion-0.5.0-informational?style=flat-square)
![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.6.0](https://img.shields.io/badge/AppVersion-0.6.0-informational?style=flat-square)

Interpolator Helm Chart

Expand All @@ -18,17 +18,26 @@ Interpolator Helm Chart

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| controllerManager.manager.args[0] | string | `"--leader-elect"` | |
| controllerManager.manager.args[1] | string | `"--health-probe-bind-address=:8081"` | |
| controllerManager.manager.args[0] | string | `"--metrics-bind-address=:8080"` | |
| controllerManager.manager.args[1] | string | `"--leader-elect"` | |
| controllerManager.manager.args[2] | string | `"--health-probe-bind-address=:8081"` | |
| controllerManager.manager.containerSecurityContext.allowPrivilegeEscalation | bool | `false` | |
| controllerManager.manager.containerSecurityContext.capabilities.drop[0] | string | `"ALL"` | |
| controllerManager.manager.image.repository | string | `"ghcr.io/grzegorzgniadek/interpolator-operator"` | |
| controllerManager.manager.image.tag | string | `"0.5.0"` | |
| controllerManager.manager.image.tag | string | `"0.6.0"` | |
| controllerManager.manager.imagePullPolicy | string | `"Always"` | |
| controllerManager.manager.resources.limits.cpu | string | `"200m"` | |
| controllerManager.manager.resources.limits.memory | string | `"128Mi"` | |
| controllerManager.manager.resources.requests.cpu | string | `"10m"` | |
| controllerManager.manager.resources.requests.memory | string | `"64Mi"` | |
| controllerManager.replicas | int | `1` | |
| controllerManager.serviceAccount.annotations | object | `{}` | |
| kubernetesClusterDomain | string | `"cluster.local"` | |
| kubernetesClusterDomain | string | `"cluster.local"` | |
| metricsService.enabled | bool | `true` | |
| metricsService.ports[0].name | string | `"metrics"` | |
| metricsService.ports[0].port | int | `8080` | |
| metricsService.ports[0].protocol | string | `"TCP"` | |
| metricsService.ports[0].targetPort | int | `8080` | |
| metricsService.type | string | `"ClusterIP"` | |
| prometheusMonitor.enabled | bool | `false` | |
| prometheusMonitor.interval | string | `"15s"` | |
15 changes: 15 additions & 0 deletions charts/interpolator/templates/metrics-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.prometheusMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "interpolator.fullname" . }}-metrics-monitor
labels:
{{- include "interpolator.labels" . | nindent 4 }}
spec:
endpoints:
- interval: {{ .Values.prometheusMonitor.interval }}
port: metrics
selector:
matchLabels:
control-plane: controller-manager
{{- end -}}
16 changes: 16 additions & 0 deletions charts/interpolator/templates/metrics-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.metricsService.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ include "interpolator.fullname" . }}-metrics-service
labels:
control-plane: controller-manager
{{- include "interpolator.labels" . | nindent 4 }}
spec:
type: {{ .Values.metricsService.type }}
selector:
control-plane: controller-manager
{{- include "interpolator.selectorLabels" . | nindent 4 }}
ports:
{{- .Values.metricsService.ports | toYaml | nindent 2 }}
{{- end -}}
14 changes: 13 additions & 1 deletion charts/interpolator/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
controllerManager:
manager:
args:
- --metrics-bind-address=:8080
- --leader-elect
- --health-probe-bind-address=:8081
containerSecurityContext:
Expand All @@ -10,7 +11,7 @@ controllerManager:
- ALL
image:
repository: ghcr.io/grzegorzgniadek/interpolator-operator
tag: 0.5.0
tag: 0.6.0
imagePullPolicy: Always
resources:
limits:
Expand All @@ -23,3 +24,14 @@ controllerManager:
serviceAccount:
annotations: {}
kubernetesClusterDomain: cluster.local
metricsService:
enabled: true
ports:
- name: metrics
port: 8080
protocol: TCP
targetPort: 8080
type: ClusterIP
prometheusMonitor:
enabled: false
interval: 15s
30 changes: 22 additions & 8 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Adds namespace to all resources.
namespace: interpolator-system
namePrefix: interpolator-
# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
Expand All @@ -22,18 +23,16 @@ resources:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml
- ../prometheus

# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
#patches:
patches:
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
- path: manager_metrics_patch.yaml
target:
kind: Deployment

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand All @@ -46,7 +45,6 @@ resources:

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
# Uncomment the following replacements to add the cert-manager CA injection annotations
#replacements:
# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
# kind: Certificate
# group: cert-manager.io
Expand Down Expand Up @@ -143,3 +141,19 @@ resources:
# delimiter: '.'
# index: 1
# create: true
replacements:
- source:
kind: Deployment
name: controller-manager
fieldPath: .metadata.namespace
targets:
- select:
kind: ClusterRoleBinding
name: manager-rolebinding
fieldPaths:
- .subjects.0.namespace
- select:
kind: RoleBinding
name: leader-election-rolebinding
fieldPaths:
- .subjects.0.namespace
4 changes: 3 additions & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
resources:
- manager.yaml
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
- metrics_service.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/grzegorzgniadek/interpolator-operator
newTag: "0.5.0"
newTag: "0.6.0"
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
control-plane: controller-manager
app.kubernetes.io/name: interpolator-operator
app.kubernetes.io/managed-by: kustomize
name: interpolator-operator-system
name: system
---
apiVersion: apps/v1
kind: Deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
control-plane: controller-manager
app.kubernetes.io/name: interpolator-operator
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-service
name: metrics-service
spec:
ports:
- name: http
Expand Down
2 changes: 1 addition & 1 deletion config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
control-plane: controller-manager
app.kubernetes.io/name: interpolator-operator
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-monitor
name: metrics-monitor
spec:
endpoints:
- path: /metrics
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ resources:
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
# if you do not want those helpers be installed with your Project.
- interpolator_editor_role.yaml
- interpolator_viewer_role.yaml

- editor_role.yaml
- viewer_role.yaml
File renamed without changes.
10 changes: 10 additions & 0 deletions internal/controller/interpolator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ func (r *InterpolatorReconciler) Reconcile(ctx context.Context, req ctrl.Request

// Fetch the Interpolator instance
interpolator := &interpolatorv1.Interpolator{}
interpolatorList := &interpolatorv1.InterpolatorList{}

if err := r.List(ctx, interpolatorList); err != nil {
log.Error(err, "failed to list custom resources")

return ctrl.Result{}, nil
}
count := len(interpolatorList.Items)
interCount.Set(float64(count))

err := r.Get(ctx, req.NamespacedName, interpolator)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down
20 changes: 20 additions & 0 deletions internal/controller/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controller

import (
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

var (
interCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "inter_count",
Help: "Count of inter resources",
},
)
)

func init() {
// Register custom metrics with the global prometheus registry
metrics.Registry.MustRegister(interCount)
}

0 comments on commit 9036e60

Please sign in to comment.