Skip to content

Commit ea567d9

Browse files
committed
feat: Add logic to support Grafana's TLS configuration in the scrollsdk setup tls command
1 parent aa0a4c2 commit ea567d9

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

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)