From aa1bf33856c6a2abaae56c1564ff24fcb9ab5c04 Mon Sep 17 00:00:00 2001 From: CJ_Clippy Date: Thu, 20 Jun 2024 15:23:01 -0800 Subject: [PATCH] add grafana --- Makefile | 4 +- infrastructure/controllers/grafana.yaml | 66 +++++++++++++++++++ infrastructure/controllers/kustomization.yaml | 1 + .../infra/vultr-delete-orphaned-resources.js | 4 +- scripts/flux-bootstrap-staging.expect | 6 ++ scripts/flux-bootstrap-staging.sh | 7 +- 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 infrastructure/controllers/grafana.yaml create mode 100755 scripts/flux-bootstrap-staging.expect diff --git a/Makefile b/Makefile index ea46b11..ea03657 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ flux-prod: ./scripts/flux-bootstrap-prod.sh flux-staging: - ./scripts/flux-bootstrap-staging.sh + (cd ./scripts; ./flux-bootstrap-staging.expect) dev: kind namespaces secrets chisel velero @@ -50,7 +50,7 @@ chisel: ./scripts/k8s-chisel-operator.sh deps: - sudo pamac install make entr nvm minikube kubectl docker helm + sudo pamac install make entr nvm minikube kubectl docker helm expect curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash echo "go to https://github.com/txn2/kubefwd/releases/latest to get kubefwd" diff --git a/infrastructure/controllers/grafana.yaml b/infrastructure/controllers/grafana.yaml new file mode 100644 index 0000000..30d2bb9 --- /dev/null +++ b/infrastructure/controllers/grafana.yaml @@ -0,0 +1,66 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: grafana + +--- +apiVersion: source.toolkit.fluxcd.io/v1 +kind: HelmRepository +metadata: + name: grafana + namespace: grafana +spec: + interval: 24h + url: https://grafana.github.io/helm-charts + +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: grafana + namespace: grafana +spec: + interval: 30m + chart: + spec: + chart: grafana + version: "8.0.2" + sourceRef: + kind: HelmRepository + name: grafana + namespace: grafana + interval: 12h + values: + dashboardProviders: + dashboardproviders.yaml: + apiVersion: 1 + providers: + - name: 'grafana-dashboards-kubernetes' + orgId: 1 + folder: 'Kubernetes' + type: file + disableDeletion: true + editable: true + options: + path: /var/lib/grafana/dashboards/grafana-dashboards-kubernetes + dashboards: + grafana-dashboards-kubernetes: + k8s-system-api-server: + url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-system-api-server.json + token: '' + k8s-system-coredns: + url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-system-coredns.json + token: '' + k8s-views-global: + url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-global.json + token: '' + k8s-views-namespaces: + url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-namespaces.json + token: '' + k8s-views-nodes: + url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-nodes.json + token: '' + k8s-views-pods: + url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-pods.json + token: '' diff --git a/infrastructure/controllers/kustomization.yaml b/infrastructure/controllers/kustomization.yaml index 4079c0a..a5a569d 100644 --- a/infrastructure/controllers/kustomization.yaml +++ b/infrastructure/controllers/kustomization.yaml @@ -4,3 +4,4 @@ resources: - external-dns.yaml - cert-manager.yaml - ingress-nginx.yaml + - grafana.yaml \ No newline at end of file diff --git a/packages/infra/vultr-delete-orphaned-resources.js b/packages/infra/vultr-delete-orphaned-resources.js index 7820e82..ce47e96 100644 --- a/packages/infra/vultr-delete-orphaned-resources.js +++ b/packages/infra/vultr-delete-orphaned-resources.js @@ -1,8 +1,8 @@ #!/usr/bin/env node - import dotenv from 'dotenv' -dotenv.config({ path: '../../.env' }) +import { join } from 'node:path' +dotenv.config({ path: join(import.meta.dirname, '../../.env') }) const apiV2Base = 'https://api.vultr.com/v2' diff --git a/scripts/flux-bootstrap-staging.expect b/scripts/flux-bootstrap-staging.expect new file mode 100755 index 0000000..884bf28 --- /dev/null +++ b/scripts/flux-bootstrap-staging.expect @@ -0,0 +1,6 @@ +#!/usr/bin/expect + +spawn ./flux-bootstrap-staging.sh +expect -re ".*Please give the key access to your repository\?.*\[y/N\]" +send -- "y\r" +interact \ No newline at end of file diff --git a/scripts/flux-bootstrap-staging.sh b/scripts/flux-bootstrap-staging.sh index afcb3ea..2f12cd3 100755 --- a/scripts/flux-bootstrap-staging.sh +++ b/scripts/flux-bootstrap-staging.sh @@ -1,4 +1,6 @@ -#!/bin/bash +#!/usr/bin/sh + + ## this way is annoying because deployment asks for git password # flux bootstrap git \ @@ -9,9 +11,10 @@ # --token-auth=true \ # --path=clusters/staging + ## this way is more automatic although it does ask for yes/no confirmation that the ssh key has repo access flux bootstrap git \ --url="ssh://git@gitea.futureporn.net:2222/futureporn/fp" \ --branch=main \ --path="clusters/staging" \ - --private-key-file=/home/cj/.ssh/fp-flux \ No newline at end of file + --private-key-file=/home/cj/.ssh/fp-flux