|
1 | 1 | import { werft, exec } from './shell';
|
2 | 2 | import * as shell from 'shelljs';
|
3 | 3 | import * as fs from 'fs';
|
| 4 | +import { validateIPaddress } from './util'; |
4 | 5 |
|
5 | 6 | /**
|
6 | 7 | * Monitoring satellite deployment bits
|
@@ -52,6 +53,7 @@ export async function installMonitoringSatellite(params: InstallMonitoringSatell
|
52 | 53 | exec(jsonnetRenderCmd, {silent: true})
|
53 | 54 | // The correct kubectl context should already be configured prior to this step
|
54 | 55 | ensureCorrectInstallationOrder()
|
| 56 | + ensureIngressesReadiness(params) |
55 | 57 | }
|
56 | 58 |
|
57 | 59 | async function ensureCorrectInstallationOrder(){
|
@@ -152,3 +154,34 @@ function jsonnetUnitTests(): boolean {
|
152 | 154 | }
|
153 | 155 | return success
|
154 | 156 | }
|
| 157 | + |
| 158 | +function ensureIngressesReadiness(params: InstallMonitoringSatelliteParams) { |
| 159 | + // Read more about validating ingresses readiness |
| 160 | + // https://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balance-ingress?hl=it#validate |
| 161 | + |
| 162 | + let grafanaIngressReady = false |
| 163 | + let prometheusIngressReady = false |
| 164 | + werft.log(sliceName, "Checking ingresses readiness") |
| 165 | + for(let i = 0; i < 15; i++) { |
| 166 | + grafanaIngressReady = ingressReady(params.satelliteNamespace, 'grafana') |
| 167 | + prometheusIngressReady = ingressReady(params.satelliteNamespace, 'prometheus') |
| 168 | + |
| 169 | + if(grafanaIngressReady && prometheusIngressReady) { break } |
| 170 | + werft.log(sliceName, "Trying again in 1 minute") |
| 171 | + exec(`sleep 60`, {slice: sliceName}) // 1 min |
| 172 | + i++ |
| 173 | + } |
| 174 | + |
| 175 | + if (!prometheusIngressReady || !grafanaIngressReady) { |
| 176 | + throw new Error('Timeout while waiting for ingresses readiness') |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +function ingressReady(namespace: string, name: string): boolean { |
| 181 | + let ingressAddress = exec(`kubectl get ingress -n ${namespace} --no-headers ${name} | awk {'print $4'}`, {silent: true}).stdout.trim() |
| 182 | + if (validateIPaddress(ingressAddress)) { |
| 183 | + return true |
| 184 | + } |
| 185 | + werft.log(sliceName, `${name} ingress not ready.`) |
| 186 | + return false |
| 187 | +} |
0 commit comments