From 3f05075cddc04a2063e79968e08d8a5d9c059f74 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Mon, 20 Nov 2023 00:13:52 +0100
Subject: [PATCH] fix(dns): Fix some remaining issues with monitoring

This patch fixes the current issues with Service Discovery by adding a
port to the service with the correct name for the ServiceMonitor, as
well as adding the missing network policy.
---
 apps/k8s01/dns/dns.yaml                 |  4 ++++
 apps/k8s01/dns/kustomization.yaml       |  3 +++
 apps/k8s01/dns/networkpolicy-patch.yaml | 12 ++++++++++++
 apps/k8s01/dns/servicemonitor.yaml      |  2 +-
 4 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 apps/k8s01/dns/networkpolicy-patch.yaml

diff --git a/apps/k8s01/dns/dns.yaml b/apps/k8s01/dns/dns.yaml
index f15483a90..6d9c52daf 100644
--- a/apps/k8s01/dns/dns.yaml
+++ b/apps/k8s01/dns/dns.yaml
@@ -182,6 +182,10 @@ spec:
       protocol: TCP
       port: 80
       targetPort: 80
+    - name: metrics
+      protocol: TCP
+      port: 8080
+      targetPort: 80
 ---
 apiVersion: policy/v1
 kind: PodDisruptionBudget
diff --git a/apps/k8s01/dns/kustomization.yaml b/apps/k8s01/dns/kustomization.yaml
index c576d92cd..38942f3a6 100644
--- a/apps/k8s01/dns/kustomization.yaml
+++ b/apps/k8s01/dns/kustomization.yaml
@@ -8,4 +8,7 @@ resources:
   - networkpolicy.yaml
   - servicemonitor.yaml
   - ../../../shared/networkpolicies/allow-from-same-namespace.yaml
+  - ../../../shared/networkpolicies/allow-from-monitoring.yaml
   - ../../../shared/resourcequotas/default.yaml
+patchesStrategicMerge:
+  - networkpolicy-patch.yaml
diff --git a/apps/k8s01/dns/networkpolicy-patch.yaml b/apps/k8s01/dns/networkpolicy-patch.yaml
new file mode 100644
index 000000000..0f6c2deed
--- /dev/null
+++ b/apps/k8s01/dns/networkpolicy-patch.yaml
@@ -0,0 +1,12 @@
+---
+apiVersion: networking.k8s.io/v1
+kind: NetworkPolicy
+metadata:
+  name: allow-from-monitoring
+spec:
+  podSelector:
+    matchExpressions:
+      - key:  app
+        operator: In
+        values:
+          - resolver
\ No newline at end of file
diff --git a/apps/k8s01/dns/servicemonitor.yaml b/apps/k8s01/dns/servicemonitor.yaml
index 530defd10..ed4498c55 100644
--- a/apps/k8s01/dns/servicemonitor.yaml
+++ b/apps/k8s01/dns/servicemonitor.yaml
@@ -10,5 +10,5 @@ spec:
     matchLabels:
       app: resolver
   endpoints:
-    - port: http
+    - port: metrics
       path: /metrics
-- 
GitLab