Skip to content

Commit 45278ab

Browse files
committed
Provide metrics in prometheus
1 parent d700f6d commit 45278ab

12 files changed

Lines changed: 84 additions & 211 deletions

File tree

.github/workflows/test-e2e.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29+
- name: Install helm
30+
uses: azure/setup-helm@v4.3.0
31+
2932
- name: Running Test e2e
3033
run: |
3134
go mod tidy

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
120120

121121
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
122122
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
123-
# CertManager is installed by default; skip with:
124-
# - CERT_MANAGER_INSTALL_SKIP=true
125123
KIND_CLUSTER ?= func-operator-test-e2e
126124

127125
.PHONY: setup-test-e2e

config/default/kustomization.yaml

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resources:
2424
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2525
- ../certmanager
2626
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
27-
#- ../prometheus
27+
- ../prometheus
2828
# [METRICS] Expose the controller manager metrics service.
2929
- metrics_service.yaml
3030
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
@@ -35,7 +35,7 @@ resources:
3535

3636
# Uncomment the patches line if you enable Metrics
3737
patches:
38-
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
38+
# [METRICS] The following patch will enable the metrics endpoint using HTTP and the port :8080.
3939
# More info: https://book.kubebuilder.io/reference/metrics
4040
- path: manager_metrics_patch.yaml
4141
target:
@@ -75,48 +75,48 @@ replacements:
7575
delimiter: '.'
7676
index: 0
7777
create: true
78-
# - select: # Uncomment the following to set the Service name for TLS config in Prometheus ServiceMonitor
79-
# kind: ServiceMonitor
80-
# group: monitoring.coreos.com
81-
# version: v1
82-
# name: controller-manager-metrics-monitor
83-
# fieldPaths:
84-
# - spec.endpoints.0.tlsConfig.serverName
85-
# options:
86-
# delimiter: '.'
87-
# index: 0
88-
# create: true
89-
#
90-
# - source:
91-
# kind: Service
92-
# version: v1
93-
# name: controller-manager-metrics-service
94-
# fieldPath: metadata.namespace
95-
# targets:
96-
# - select:
97-
# kind: Certificate
98-
# group: cert-manager.io
99-
# version: v1
100-
# name: metrics-certs
101-
# fieldPaths:
102-
# - spec.dnsNames.0
103-
# - spec.dnsNames.1
104-
# options:
105-
# delimiter: '.'
106-
# index: 1
107-
# create: true
108-
# - select: # Uncomment the following to set the Service namespace for TLS in Prometheus ServiceMonitor
109-
# kind: ServiceMonitor
110-
# group: monitoring.coreos.com
111-
# version: v1
112-
# name: controller-manager-metrics-monitor
113-
# fieldPaths:
114-
# - spec.endpoints.0.tlsConfig.serverName
115-
# options:
116-
# delimiter: '.'
117-
# index: 1
118-
# create: true
119-
#
78+
- select: # Uncomment the following to set the Service name for TLS config in Prometheus ServiceMonitor
79+
kind: ServiceMonitor
80+
group: monitoring.coreos.com
81+
version: v1
82+
name: controller-manager-metrics-monitor
83+
fieldPaths:
84+
- spec.endpoints.0.tlsConfig.serverName
85+
options:
86+
delimiter: '.'
87+
index: 0
88+
create: true
89+
90+
- source:
91+
kind: Service
92+
version: v1
93+
name: controller-manager-metrics-service
94+
fieldPath: metadata.namespace
95+
targets:
96+
- select:
97+
kind: Certificate
98+
group: cert-manager.io
99+
version: v1
100+
name: metrics-certs
101+
fieldPaths:
102+
- spec.dnsNames.0
103+
- spec.dnsNames.1
104+
options:
105+
delimiter: '.'
106+
index: 1
107+
create: true
108+
- select: # Uncomment the following to set the Service namespace for TLS in Prometheus ServiceMonitor
109+
kind: ServiceMonitor
110+
group: monitoring.coreos.com
111+
version: v1
112+
name: controller-manager-metrics-monitor
113+
fieldPaths:
114+
- spec.endpoints.0.tlsConfig.serverName
115+
options:
116+
delimiter: '.'
117+
index: 1
118+
create: true
119+
120120
- source: # Uncomment the following block if you have any webhook
121121
kind: Service
122122
version: v1
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# This patch adds the args to allow exposing the metrics endpoint using HTTPS
1+
# This patch adds the args to allow exposing the metrics endpoint using HTTP
22
- op: add
33
path: /spec/template/spec/containers/0/args/0
4-
value: --metrics-bind-address=:8443
4+
value: --metrics-bind-address=:8080
5+
- op: add
6+
path: /spec/template/spec/containers/0/args/-
7+
value: --metrics-secure=false

config/default/metrics_service.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ metadata:
99
namespace: system
1010
spec:
1111
ports:
12-
- name: https
13-
port: 8443
12+
- name: http
13+
port: 8080
1414
protocol: TCP
15-
targetPort: 8443
15+
targetPort: 8080
1616
selector:
1717
control-plane: controller-manager
1818
app.kubernetes.io/name: func-operator

config/manager/kustomization.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
resources:
22
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller
7+
newName: localhost:5001/func-operator
8+
newTag: 0.0.1-d700f6d-20251217163200

config/prometheus/kustomization.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
resources:
22
- monitor.yaml
33

4-
# [PROMETHEUS-WITH-CERTS] The following patch configures the ServiceMonitor in ../prometheus
5-
# to securely reference certificates created and managed by cert-manager.
6-
# Additionally, ensure that you uncomment the [METRICS WITH CERTMANAGER] patch under config/default/kustomization.yaml
7-
# to mount the "metrics-server-cert" secret in the Manager Deployment.
4+
# [PROMETHEUS-WITH-CERTS] TLS is disabled for metrics - using HTTP instead
5+
# If you need TLS in the future, uncomment the patch below and ensure
6+
# the metrics-server-cert secret exists in the prometheus namespace
87
#patches:
98
# - path: monitor_tls_patch.yaml
109
# target:

config/prometheus/monitor.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@ metadata:
1111
spec:
1212
endpoints:
1313
- path: /metrics
14-
port: https # Ensure this is the name of the port that exposes HTTPS metrics
15-
scheme: https
14+
port: http
15+
scheme: http
1616
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
17-
tlsConfig:
18-
# TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables
19-
# certificate verification, exposing the system to potential man-in-the-middle attacks.
20-
# For production environments, it is recommended to use cert-manager for automatic TLS certificate management.
21-
# To apply this configuration, enable cert-manager and use the patch located at config/prometheus/servicemonitor_tls_patch.yaml,
22-
# which securely references the certificate from the 'metrics-server-cert' secret.
23-
insecureSkipVerify: true
2417
selector:
2518
matchLabels:
2619
control-plane: controller-manager

hack/create-kind-cluster.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ function install_certmanager() {
118118
kubectl wait deployment --all --timeout=-1s --for=condition=Available -n cert-manager
119119
}
120120

121+
function install_prometheus() {
122+
header_text "Installing Prometheus Operator"
123+
124+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
125+
helm repo update
126+
kubectl create namespace prometheus
127+
helm install prometheus prometheus-community/kube-prometheus-stack --namespace prometheus \
128+
--set grafana.enabled=false \
129+
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
130+
131+
header_text "Waiting for Prometheus operator to become ready"
132+
kubectl wait deployment --all --timeout=-1s --for=condition=Available --namespace prometheus
133+
}
134+
121135
if [ "$DELETE_CLUSTER_BEFORE" = "true" ]; then
122136
delete_existing_cluster
123137
fi
@@ -126,6 +140,7 @@ setup_local_registry
126140
create_kind_cluster
127141
connect_registry_to_cluster
128142
install_certmanager
143+
install_prometheus
129144
install_tekton
130145
install_knative_serving
131146

test/e2e/e2e_suite_test.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,17 @@ package e2e
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"os/exec"
2322
"testing"
2423

2524
. "github.com/onsi/ginkgo/v2"
2625
. "github.com/onsi/gomega"
26+
"github.com/onsi/gomega/format"
2727

2828
"github.com/creydr/func-operator/test/utils"
2929
)
3030

3131
var (
32-
// Optional Environment Variables:
33-
// - CERT_MANAGER_INSTALL_SKIP=true: Skips CertManager installation during test setup.
34-
// These variables are useful if CertManager is already installed, avoiding
35-
// re-installation and conflicts.
36-
skipCertManagerInstall = os.Getenv("CERT_MANAGER_INSTALL_SKIP") == "true"
37-
// isCertManagerAlreadyInstalled will be set true when CertManager CRDs be found on the cluster
38-
isCertManagerAlreadyInstalled = false
39-
4032
// projectImage is the name of the image which will be build and loaded
4133
// with the code source changes to be tested.
4234
projectImage = "localhost:5001/func-operator:v0.0.1"
@@ -58,26 +50,5 @@ var _ = BeforeSuite(func() {
5850
_, err := utils.Run(cmd)
5951
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build the manager(Operator) image")
6052

61-
// The tests-e2e are intended to run on a temporary cluster that is created and destroyed for testing.
62-
// To prevent errors when tests run in environments with CertManager already installed,
63-
// we check for its presence before execution.
64-
// Setup CertManager before the suite if not skipped and if not already installed
65-
if !skipCertManagerInstall {
66-
By("checking if cert manager is installed already")
67-
isCertManagerAlreadyInstalled = utils.IsCertManagerCRDsInstalled()
68-
if !isCertManagerAlreadyInstalled {
69-
_, _ = fmt.Fprintf(GinkgoWriter, "Installing CertManager...\n")
70-
Expect(utils.InstallCertManager()).To(Succeed(), "Failed to install CertManager")
71-
} else {
72-
_, _ = fmt.Fprintf(GinkgoWriter, "WARNING: CertManager is already installed. Skipping installation...\n")
73-
}
74-
}
75-
})
76-
77-
var _ = AfterSuite(func() {
78-
// Teardown CertManager after the suite if not skipped and if it was not already installed
79-
if !skipCertManagerInstall && !isCertManagerAlreadyInstalled {
80-
_, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling CertManager...\n")
81-
utils.UninstallCertManager()
82-
}
53+
format.MaxLength = format.MaxLength * 5 // TODO find a better way to not exceed the limit
8354
})

0 commit comments

Comments
 (0)