@r8s/grafana 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ export interface GrafanaProps {
2
+ /** Resource name */
3
+ name?: string;
4
+ /** Kubernetes namespace */
5
+ namespace?: string;
6
+ /** Grafana version (default: 10.3.0) */
7
+ version?: string;
8
+ /**
9
+ * Admin credentials. If `existingSecret` is set, that Secret must already
10
+ * exist (with a `password` key). Otherwise a Secret named `<name>-admin`
11
+ * is created with the given `password` (or a generated one if omitted).
12
+ */
13
+ admin?: {
14
+ password?: string;
15
+ existingSecret?: string;
16
+ };
17
+ /** Data source configurations */
18
+ datasources?: Array<{
19
+ name: string;
20
+ type: string;
21
+ url: string;
22
+ access?: string;
23
+ }>;
24
+ /** Persistent storage (default: 10Gi) */
25
+ storage?: string;
26
+ /** Ingress host */
27
+ host?: string;
28
+ /** TLS config */
29
+ tls?: {
30
+ secretName: string;
31
+ clusterIssuer: string;
32
+ };
33
+ }
34
+ /**
35
+ * Grafana deployment with persistent storage.
36
+ *
37
+ * Standalone Grafana (Deployment + Service + PVC) with optional datasource
38
+ * provisioning via ConfigMap and TLS ingress. Dashboards are kept in the
39
+ * PVC; point `datasources` at your Prometheus/Loki instances to have them
40
+ * available on first login.
41
+ *
42
+ * @example
43
+ * <Grafana
44
+ * name="grafana"
45
+ * namespace="monitoring"
46
+ * host="grafana.example.com"
47
+ * datasources={[{ name: 'Prometheus', type: 'prometheus', url: 'http://prometheus:9090' }]}
48
+ * />
49
+ */
50
+ export declare function Grafana(props: GrafanaProps): import("@r8s/core").r8sElement;
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE;QACN,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB,CAAA;IACD,iCAAiC;IACjC,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAC,CAAA;IACF,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mBAAmB;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB;IACjB,GAAG,CAAC,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,aAAa,EAAE,MAAM,CAAA;KACtB,CAAA;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,kCAiM1C"}
package/dist/index.js ADDED
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Grafana = Grafana;
4
+ const core_1 = require("@r8s/core");
5
+ /**
6
+ * Grafana deployment with persistent storage.
7
+ *
8
+ * Standalone Grafana (Deployment + Service + PVC) with optional datasource
9
+ * provisioning via ConfigMap and TLS ingress. Dashboards are kept in the
10
+ * PVC; point `datasources` at your Prometheus/Loki instances to have them
11
+ * available on first login.
12
+ *
13
+ * @example
14
+ * <Grafana
15
+ * name="grafana"
16
+ * namespace="monitoring"
17
+ * host="grafana.example.com"
18
+ * datasources={[{ name: 'Prometheus', type: 'prometheus', url: 'http://prometheus:9090' }]}
19
+ * />
20
+ */
21
+ function Grafana(props) {
22
+ const { name = 'grafana', namespace = 'monitoring', version = '10.3.0', admin, datasources = [], storage = '10Gi', host, tls, } = props;
23
+ const adminSecretName = admin?.existingSecret ?? `${name}-admin`;
24
+ const resources = [];
25
+ // Admin credentials Secret — created unless the user points at an
26
+ // existing one. Without this the Deployment references a Secret that
27
+ // never exists and the pod fails with CreateContainerConfigError.
28
+ if (!admin?.existingSecret) {
29
+ resources.push((0, core_1.jsx)('Secret', {
30
+ apiVersion: 'v1',
31
+ kind: 'Secret',
32
+ metadata: { name: adminSecretName, namespace },
33
+ type: 'Opaque',
34
+ stringData: {
35
+ username: 'admin',
36
+ password: admin?.password ?? 'admin',
37
+ },
38
+ }));
39
+ }
40
+ // ConfigMap for datasources
41
+ if (datasources.length > 0) {
42
+ resources.push((0, core_1.jsx)('ConfigMap', {
43
+ apiVersion: 'v1',
44
+ kind: 'ConfigMap',
45
+ metadata: { name: `${name}-datasources`, namespace },
46
+ data: {
47
+ 'datasources.yaml': JSON.stringify({
48
+ apiVersion: 1,
49
+ datasources: datasources.map((ds) => ({
50
+ name: ds.name,
51
+ type: ds.type,
52
+ url: ds.url,
53
+ access: ds.access || 'proxy',
54
+ isDefault: false,
55
+ })),
56
+ }, null, 2),
57
+ },
58
+ }));
59
+ }
60
+ // Deployment
61
+ const volumeMounts = [
62
+ { name: 'storage', mountPath: '/var/lib/grafana' },
63
+ ];
64
+ const volumes = [
65
+ { name: 'storage', persistentVolumeClaim: { claimName: `${name}-pvc` } },
66
+ ];
67
+ if (datasources.length > 0) {
68
+ volumeMounts.push({ name: 'datasources', mountPath: '/etc/grafana/provisioning/datasources' });
69
+ // The ConfigMap volume source is required — a volume without a source
70
+ // is rejected by the Kubernetes API.
71
+ volumes.push({ name: 'datasources', configMap: { name: `${name}-datasources` } });
72
+ }
73
+ resources.push((0, core_1.jsx)('Deployment', {
74
+ apiVersion: 'apps/v1',
75
+ kind: 'Deployment',
76
+ metadata: { name, namespace },
77
+ spec: {
78
+ replicas: 1,
79
+ selector: { matchLabels: { app: name } },
80
+ template: {
81
+ metadata: { labels: { app: name } },
82
+ spec: {
83
+ containers: [
84
+ {
85
+ name: 'grafana',
86
+ image: `grafana/grafana:${version}`,
87
+ ports: [{ containerPort: 3000, name: 'http' }],
88
+ env: [
89
+ {
90
+ name: 'GF_SECURITY_ADMIN_PASSWORD__FILE',
91
+ value: `/etc/grafana/admin/password`,
92
+ },
93
+ { name: 'GF_INSTALL_PLUGINS', value: 'grafana-clock-panel' },
94
+ ],
95
+ volumeMounts: [...volumeMounts, { name: 'admin', mountPath: '/etc/grafana/admin' }],
96
+ resources: {
97
+ requests: { memory: '256Mi', cpu: '250m' },
98
+ limits: { memory: '512Mi', cpu: '500m' },
99
+ },
100
+ },
101
+ ],
102
+ volumes: [
103
+ ...volumes,
104
+ {
105
+ name: 'admin',
106
+ secret: { secretName: adminSecretName },
107
+ },
108
+ ],
109
+ },
110
+ },
111
+ },
112
+ }));
113
+ // Service
114
+ resources.push((0, core_1.jsx)('Service', {
115
+ apiVersion: 'v1',
116
+ kind: 'Service',
117
+ metadata: { name, namespace },
118
+ spec: {
119
+ selector: { app: name },
120
+ ports: [{ port: 80, targetPort: 3000 }],
121
+ },
122
+ }));
123
+ // PVC
124
+ resources.push((0, core_1.jsx)('PersistentVolumeClaim', {
125
+ apiVersion: 'v1',
126
+ kind: 'PersistentVolumeClaim',
127
+ metadata: { name: `${name}-pvc`, namespace },
128
+ spec: {
129
+ accessModes: ['ReadWriteOnce'],
130
+ resources: { requests: { storage } },
131
+ },
132
+ }));
133
+ // Ingress
134
+ if (host) {
135
+ const ingressSpec = {
136
+ rules: [
137
+ {
138
+ host,
139
+ http: {
140
+ paths: [
141
+ {
142
+ path: '/',
143
+ pathType: 'Prefix',
144
+ backend: {
145
+ service: { name, port: { number: 80 } },
146
+ },
147
+ },
148
+ ],
149
+ },
150
+ },
151
+ ],
152
+ };
153
+ if (tls) {
154
+ ingressSpec.tls = [
155
+ {
156
+ hosts: [host],
157
+ secretName: tls.secretName,
158
+ },
159
+ ];
160
+ }
161
+ resources.push((0, core_1.jsx)('Ingress', {
162
+ apiVersion: 'networking.k8s.io/v1',
163
+ kind: 'Ingress',
164
+ metadata: {
165
+ name,
166
+ namespace,
167
+ annotations: tls
168
+ ? {
169
+ 'cert-manager.io/cluster-issuer': tls.clusterIssuer,
170
+ }
171
+ : undefined,
172
+ },
173
+ spec: ingressSpec,
174
+ }));
175
+ }
176
+ return (0, core_1.jsx)(core_1.Fragment, { children: resources });
177
+ }
178
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAoDA,0BAiMC;AArPD,oCAAyC;AAoCzC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,OAAO,CAAC,KAAmB;IACzC,MAAM,EACJ,IAAI,GAAG,SAAS,EAChB,SAAS,GAAG,YAAY,EACxB,OAAO,GAAG,QAAQ,EAClB,KAAK,EACL,WAAW,GAAG,EAAE,EAChB,OAAO,GAAG,MAAM,EAChB,IAAI,EACJ,GAAG,GACJ,GAAG,KAAK,CAAA;IAET,MAAM,eAAe,GAAG,KAAK,EAAE,cAAc,IAAI,GAAG,IAAI,QAAQ,CAAA;IAChE,MAAM,SAAS,GAA6B,EAAE,CAAA;IAE9C,kEAAkE;IAClE,qEAAqE;IACrE,kEAAkE;IAClE,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC;QAC3B,SAAS,CAAC,IAAI,CACZ,IAAA,UAAG,EAAC,QAAQ,EAAE;YACZ,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE;YAC9C,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,QAAQ,EAAE,OAAO;gBACjB,QAAQ,EAAE,KAAK,EAAE,QAAQ,IAAI,OAAO;aACrC;SACF,CAAC,CACH,CAAA;IACH,CAAC;IAED,4BAA4B;IAC5B,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,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BACR,IAAI;gBACJ,SAAS;gBACT,WAAW,EAAE,GAAG;oBACd,CAAC,CAAC;wBACE,gCAAgC,EAAE,GAAG,CAAC,aAAa;qBACpD;oBACH,CAAC,CAAC,SAAS;aACd;YACD,IAAI,EAAE,WAAW;SAClB,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,IAAA,UAAG,EAAC,eAAQ,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAA;AAC/C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@r8s/grafana",
3
+ "version": "0.1.0",
4
+ "description": "Grafana observability dashboard components for r8s",
5
+ "license": "MIT",
6
+ "author": "Berget AI AB",
7
+ "homepage": "https://r8s.berget.ai",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/berget-ai/r8s.git",
11
+ "directory": "packages/grafana"
12
+ },
13
+ "bugs": "https://github.com/berget-ai/r8s/issues",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "keywords": [
21
+ "grafana",
22
+ "dashboards",
23
+ "monitoring",
24
+ "observability",
25
+ "metrics"
26
+ ],
27
+ "r8s": {
28
+ "category": "Observability"
29
+ },
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "scripts": {
33
+ "build": "tsc --build",
34
+ "test": "vitest run",
35
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
36
+ },
37
+ "dependencies": {
38
+ "@r8s/core": "^0.1.0",
39
+ "@r8s/k8s-types": "^0.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.3.0",
43
+ "vitest": "^1.0.0"
44
+ }
45
+ }