From 5c72fa92d1dd7b7ddcb3897db5e614f67db89a9b Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Thu, 2 Jan 2025 21:10:29 +0100 Subject: [PATCH] feat: add e2e --- .../03-assert.yaml | 28 +++ .../03-install.yaml | 164 ++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml create mode 100644 tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml new file mode 100644 index 0000000000..79c1f8876c --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: prometheus-cr-collector +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus-cr-targetallocator +status: + observedGeneration: 1 + readyReplicas: 1 + replicas: 1 +--- +apiVersion: v1 +data: + targetallocator.yaml: + ( contains(@, join(':', ['service_monitor_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['pod_monitor_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['probe_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['scrape_config_namespace_selector', '{}'])) ): true +kind: ConfigMap +metadata: + name: prometheus-cr-v1beta1-targetallocator +--- \ No newline at end of file diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml new file mode 100644 index 0000000000..3eeb8fc9e0 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml @@ -0,0 +1,164 @@ +apiVersion: v1 +automountServiceAccountToken: true +kind: ServiceAccount +metadata: + name: ta +--- +apiVersion: v1 +automountServiceAccountToken: true +kind: ServiceAccount +metadata: + name: collector +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: targetallocator-prometheuscr +rules: +- apiGroups: + - "" + resources: + - pods + - nodes + - services + - endpoints + - configmaps + - secrets + - namespaces + verbs: + - get + - watch + - list +- apiGroups: + - apps + resources: + - statefulsets + - services + - endpoints + verbs: + - get + - watch + - list +- apiGroups: + - discovery.k8s.io + resources: + - endpointslices + verbs: + - get + - watch + - list +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: + - get + - watch + - list +- apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + - podmonitors + - scrapeconfigs + - probes + verbs: + - get + - watch + - list +- nonResourceURLs: + - /metrics + verbs: + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: collector-prometheuscr +rules: +- apiGroups: + - "" + resources: + - pods + - nodes + - nodes/metrics + - services + - endpoints + - namespaces + verbs: + - get + - watch + - list +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: + - get + - watch + - list +- nonResourceURLs: + - /metrics + - /metrics/cadvisor + verbs: + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: (join('-', ['ta', $namespace])) +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: targetallocator-prometheuscr +subjects: +- kind: ServiceAccount + name: ta + namespace: ($namespace) +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: (join('-', ['collector', $namespace])) +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: collector-prometheuscr +subjects: +- kind: ServiceAccount + name: collector + namespace: ($namespace) +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: prometheus-cr +spec: + config: | + receivers: + prometheus: + config: + scrape_configs: [] + + processors: + + exporters: + prometheus: + endpoint: 0.0.0.0:9090 + service: + pipelines: + metrics: + receivers: [prometheus] + exporters: [prometheus] + mode: statefulset + serviceAccount: collector + targetAllocator: + enabled: true + prometheusCR: + enabled: true + scrapeInterval: 1s + podMonitorNamespaceSelector: {} + serviceMonitorNamespaceSelector: {} + scrapeConfigNamespaceSelector: {} + probeNamespaceSelector: {} + serviceAccount: ta