Skip to content

Commit 923176a

Browse files
authored
Merge pull request #3 from shu-unifra/scroll-monitor
support grafana domain
2 parents 85ecf66 + ea567d9 commit 923176a

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

src/commands/setup/domains.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ export default class SetupDomains extends Command {
183183
ROLLUPSCAN_API_URI: `${protocol}://rollup-explorer-backend.${urlEnding}/api`,
184184
EXTERNAL_EXPLORER_URI_L2: `${protocol}://blockscout.${urlEnding}`,
185185
ADMIN_SYSTEM_DASHBOARD_URI: `${protocol}://admin-system-dashboard.${urlEnding}`,
186+
GRAFANA_URI: `${protocol}://grafana.${urlEnding}`,
186187
};
187188

189+
188190
if (usesAnvil) {
189191
domainConfig.EXTERNAL_RPC_URI_L1 = `${protocol}://l1-devnet.${urlEnding}`;
190192
domainConfig.EXTERNAL_EXPLORER_URI_L1 = `${protocol}://l1-explorer.${urlEnding}`;
@@ -198,6 +200,7 @@ export default class SetupDomains extends Command {
198200
RPC_GATEWAY_HOST: `l2-rpc.${urlEnding}`,
199201
BLOCKSCOUT_HOST: `blockscout.${urlEnding}`,
200202
ADMIN_SYSTEM_DASHBOARD_HOST: `admin-system-dashboard.${urlEnding}`,
203+
GRAFANA_HOST: `grafana.${urlEnding}`,
201204
...(usesAnvil ? { L1_DEVNET_HOST: `l1-devnet.${urlEnding}`, L1_EXPLORER_HOST: `l1-explorer.${urlEnding}` } : {}),
202205
};
203206
} else {
@@ -239,6 +242,10 @@ export default class SetupDomains extends Command {
239242
message: 'Enter ADMIN_SYSTEM_DASHBOARD_HOST:',
240243
default: existingConfig.ingress?.ADMIN_SYSTEM_DASHBOARD_HOST || 'admin-system-dashboard.scrollsdk',
241244
}),
245+
GRAFANA_HOST: await input({
246+
message: 'Enter GRAFANA_HOST:',
247+
default: existingConfig.ingress?.GRAFANA_HOST || 'grafana.scrollsdk',
248+
}),
242249
};
243250

244251
if (usesAnvil) {
@@ -273,6 +280,10 @@ export default class SetupDomains extends Command {
273280
message: 'Enter ADMIN_SYSTEM_DASHBOARD_URI:',
274281
default: existingConfig.frontend?.ADMIN_SYSTEM_DASHBOARD_URI || `${protocol}://${ingressConfig.ADMIN_SYSTEM_DASHBOARD_HOST}`,
275282
}),
283+
GRAFANA_URI: await input({
284+
message: 'Enter GRAFANA_URI:',
285+
default: existingConfig.frontend?.GRAFANA_URI || `${protocol}://${ingressConfig.GRAFANA_HOST}`,
286+
}),
276287
};
277288

278289
if (usesAnvil) {

src/commands/setup/prep-charts.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default class SetupPrepCharts extends Command {
5959
'L1_DEVNET_HOST': 'ingress.L1_DEVNET_HOST',
6060
'L1_EXPLORER_HOST': 'ingress.L1_EXPLORER_HOST',
6161
'RPC_GATEWAY_WS_HOST': 'ingress.RPC_GATEWAY_WS_HOST',
62+
'GRAFANA_HOST': 'ingress.GRAFANA_HOST',
6263
// Add more mappings as needed
6364
}
6465

@@ -236,6 +237,46 @@ export default class SetupPrepCharts extends Command {
236237
}
237238
}
238239

240+
if (productionYaml.grafana) {
241+
let ingressUpdated = false;
242+
let ingressValue = productionYaml.grafana.ingress;
243+
if (ingressValue && typeof ingressValue === 'object' && 'hosts' in ingressValue) {
244+
const hosts = ingressValue.hosts as Array<string>;
245+
if (Array.isArray(hosts)) {
246+
for (let i = 0; i < hosts.length; i++) {
247+
if (typeof (hosts[i]) === 'string') {
248+
let configValue: string | undefined;
249+
configValue = this.getConfigValue("ingress.GRAFANA_HOST");
250+
251+
if (configValue && (configValue !== hosts[i])) {
252+
changes.push({ key: `ingress.hosts[${i}]`, oldValue: hosts[i], newValue: configValue });
253+
hosts[i] = configValue;
254+
ingressUpdated = true;
255+
}
256+
}
257+
}
258+
}
259+
}
260+
261+
if (ingressUpdated) {
262+
updated = true;
263+
// Update the tls section if it exists
264+
for (const [ingressKey, ingressValue] of Object.entries(productionYaml.grafana.ingress)) {
265+
if (ingressValue && typeof ingressValue === 'object' && 'tls' in ingressValue && 'hosts' in ingressValue) {
266+
const tlsEntries = ingressValue.tls as Array<{ hosts: string[] }>;
267+
const hosts = ingressValue.hosts as Array<{ host: string }>;
268+
if (Array.isArray(tlsEntries) && Array.isArray(hosts)) {
269+
tlsEntries.forEach((tlsEntry) => {
270+
if (Array.isArray(tlsEntry.hosts)) {
271+
tlsEntry.hosts = hosts.map((host) => host.host);
272+
}
273+
});
274+
}
275+
}
276+
}
277+
}
278+
}
279+
239280
if (updated) {
240281
this.log(`\nFor ${chalk.cyan(file)}:`)
241282
this.log(chalk.green('Changes:'))

src/commands/setup/tls.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,98 @@ spec:
117117
const ingressTypes = ['main', 'websocket']
118118
let updated = false
119119

120+
121+
/*
122+
grafana:
123+
ingress:
124+
enabled: true
125+
annotations:
126+
kubernetes.io/ingress.class: "nginx"
127+
nginx.ingress.kubernetes.io/ssl-redirect: "true"
128+
tls:
129+
- secretName: admin-system-dashboard-tls
130+
hosts:
131+
- grafana.scsdk.unifra.xyz
132+
hosts:
133+
- grafana.scsdk.unifra.xyz
134+
*/
135+
if (yamlContent.grafana && yamlContent.grafana.ingress) {
136+
const originalContent = yaml.dump(yamlContent.grafana.ingress, { lineWidth: -1, noRefs: true })
137+
let ingressUpdated = false;
138+
let ingress = yamlContent.grafana.ingress;
139+
if (!ingress.annotations) {
140+
ingress.annotations = {};
141+
}
142+
143+
if (ingress.annotations['cert-manager.io/cluster-issuer'] !== issuer) {
144+
ingress.annotations['cert-manager.io/cluster-issuer'] = issuer
145+
ingressUpdated = true
146+
}
147+
148+
149+
// Update or add TLS configuration
150+
if (ingress.hosts && ingress.hosts.length > 0) {
151+
const firstHost = ingress.hosts[0];
152+
if (typeof firstHost === 'string') {
153+
const hostname = firstHost
154+
const secretName = `${chart}-grafana-tls`;
155+
//const secretName = ingressType === 'main' ? `${chart}-tls` : `${chart}-${ingressType}-tls`
156+
157+
if (!ingress.tls) {
158+
ingress.tls = [{
159+
secretName: secretName,
160+
hosts: [hostname],
161+
}]
162+
ingressUpdated = true
163+
} else if (ingress.tls.length === 0) {
164+
ingress.tls.push({
165+
secretName: secretName,
166+
hosts: [hostname],
167+
})
168+
ingressUpdated = true
169+
} else {
170+
// Update existing TLS configuration
171+
ingress.tls.forEach((tlsConfig: any) => {
172+
if (!tlsConfig.secretName || tlsConfig.secretName !== secretName) {
173+
tlsConfig.secretName = secretName
174+
ingressUpdated = true
175+
}
176+
if (!tlsConfig.hosts || !tlsConfig.hosts.includes(hostname)) {
177+
tlsConfig.hosts = [hostname]
178+
ingressUpdated = true
179+
}
180+
})
181+
}
182+
}
183+
}
184+
185+
if (ingressUpdated) {
186+
updated = true
187+
const updatedContent = yaml.dump(ingress, { lineWidth: -1, noRefs: true })
188+
189+
if (this.debugMode) {
190+
this.log(chalk.yellow(`\nProposed changes for ${chart} :`))
191+
this.log(chalk.red('- Original content:'))
192+
this.log(originalContent)
193+
this.log(chalk.green('+ Updated content:'))
194+
this.log(updatedContent)
195+
196+
const confirmUpdate = await confirm({
197+
message: chalk.cyan(`Do you want to apply these changes to ${chart}?`),
198+
})
199+
200+
if (!confirmUpdate) {
201+
this.log(chalk.yellow(`Skipped updating ${chart}`));
202+
}
203+
}
204+
205+
this.log(chalk.green(`Updated TLS configuration for ${chart} `))
206+
} else {
207+
this.log(chalk.green(`No changes needed for ${chart} ()`))
208+
}
209+
210+
}
211+
120212
for (const ingressType of ingressTypes) {
121213
if (yamlContent.ingress?.[ingressType]) {
122214
const originalContent = yaml.dump(yamlContent.ingress[ingressType], { lineWidth: -1, noRefs: true })
@@ -259,6 +351,7 @@ spec:
259351
'rollup-explorer-backend',
260352
'l2-rpc',
261353
'l1-devnet',
354+
'scroll-monitor'
262355
]
263356

264357
for (const chart of chartsToUpdate) {

0 commit comments

Comments
 (0)