Skip to content

Commit

Permalink
Merge pull request bitcoin-dev-project#275 from bitcoin-dev-project/k…
Browse files Browse the repository at this point in the history
…8s-log-aggregation
  • Loading branch information
willcl-ark authored Feb 15, 2024
2 parents 3d0f7d5 + f518b5c commit 9599d4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 0 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ start:
kubectl apply -f src/templates/rpc/rbac-config.yaml
kubectl apply -f src/templates/rpc/warnet-rpc-service.yaml
kubectl apply -f src/templates/rpc/warnet-rpc-statefulset-dev.yaml
just installlogging
kubectl config set-context --current --namespace=warnet

echo waiting for rpc to come online
Expand Down Expand Up @@ -58,7 +57,6 @@ startd:
kubectl apply -f src/templates/rpc/rbac-config.yaml
kubectl apply -f src/templates/rpc/warnet-rpc-service.yaml
sed 's?/mnt/src?'`PWD`'?g' src/templates/rpc/warnet-rpc-statefulset-dev.yaml | kubectl apply -f -
just installlogging
kubectl config set-context --current --namespace=warnet

echo waiting for rpc to come online
Expand Down
13 changes: 11 additions & 2 deletions src/backends/kubernetes/kubernetes_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ def create_prometheus_container(self, tank) -> client.V1Container:
],
)

def check_logging_crds_installed(self):
logging_crd_name = "servicemonitors.monitoring.coreos.com"
api = client.ApiextensionsV1Api()
crds = api.list_custom_resource_definition()
if any(crd.metadata.name == logging_crd_name for crd in crds.items):
return True
return False

def apply_prometheus_service_monitors(self, tanks):
for tank in tanks:
if not tank.exporter:
Expand Down Expand Up @@ -628,7 +636,7 @@ def deploy_pods(self, warnet):
tank, bitcoind_container, self.get_pod_name(tank.index, ServiceType.BITCOIN)
)

if tank.exporter:
if tank.exporter and self.check_logging_crds_installed():
prometheus_container = self.create_prometheus_container(tank)
bitcoind_pod.spec.containers.append(prometheus_container)

Expand Down Expand Up @@ -664,7 +672,8 @@ def deploy_pods(self, warnet):
)

# add metrics scraping for tanks configured to export metrics
self.apply_prometheus_service_monitors(warnet.tanks)
if self.check_logging_crds_installed():
self.apply_prometheus_service_monitors(warnet.tanks)

self.log.debug("Containers and services created. Configuring IP addresses")
# now that the pods have had a second to create,
Expand Down
25 changes: 25 additions & 0 deletions src/templates/rpc/rbac-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ rules:
- apiGroups: [monitoring.coreos.com]
resources: [servicemonitors]
verbs: [get, list, create, update, patch, delete]
- apiGroups: [apiextensions.k8s.io]
resources: [customresourcedefinitions]
verbs: [get, list]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand All @@ -32,4 +35,26 @@ subjects:
roleRef:
kind: Role
name: pod-reader-exec
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: crd-viewer
rules:
- apiGroups: [apiextensions.k8s.io]
resources: [customresourcedefinitions]
verbs: [get, list, watch]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: crd-viewer-binding
subjects:
- kind: ServiceAccount
name: default
namespace: warnet
roleRef:
kind: ClusterRole
name: crd-viewer
apiGroup: rbac.authorization.k8s.io

0 comments on commit 9599d4b

Please sign in to comment.