@@ -34,9 +34,15 @@ export async function deploy(kubectl: Kubectl, manifestFilePaths: string[], depl
3434 const deployedManifestFiles = deployManifests ( inputManifestFiles , kubectl , isCanaryDeploymentStrategy ( deploymentStrategy ) ) ;
3535
3636 // check manifest stability
37- const resourceTypes : Resource [ ] = KubernetesObjectUtility . getResources ( deployedManifestFiles , models . deploymentTypes ) ;
37+ const resourceTypes : Resource [ ] = KubernetesObjectUtility . getResources ( deployedManifestFiles , models . deploymentTypes . concat ( [ constants . DiscoveryAndLoadBalancerResource . service ] ) ) ;
3838 await checkManifestStability ( kubectl , resourceTypes ) ;
3939
40+ // print ingress resources
41+ const ingressResources : Resource [ ] = KubernetesObjectUtility . getResources ( deployedManifestFiles , [ constants . DiscoveryAndLoadBalancerResource . ingress ] ) ;
42+ ingressResources . forEach ( ingressResource => {
43+ kubectl . getResource ( constants . DiscoveryAndLoadBalancerResource . ingress , ingressResource . name ) ;
44+ } ) ;
45+
4046 // annotate resources
4147 const allPods = JSON . parse ( ( kubectl . getAllPods ( ) ) . stdout ) ;
4248 annotateResources ( deployedManifestFiles , kubectl , resourceTypes , allPods ) ;
@@ -92,6 +98,21 @@ async function checkManifestStability(kubectl: Kubectl, resources: Resource[]):
9298 tl . warning ( tl . loc ( 'CouldNotDeterminePodStatus' , JSON . stringify ( ex ) ) ) ;
9399 }
94100 }
101+ if ( isEqual ( resource . type , constants . DiscoveryAndLoadBalancerResource . service , StringComparer . OrdinalIgnoreCase ) ) {
102+ try {
103+ const service = getService ( kubectl , resource . name ) ;
104+ const spec = service . spec ;
105+ const status = service . status ;
106+ if ( isEqual ( spec . type , constants . ServiceTypes . loadBalancer , StringComparer . OrdinalIgnoreCase ) ) {
107+ if ( ! isLoadBalancerIPAssigned ( status ) ) {
108+ await waitForServiceExternalIPAssignment ( kubectl , resource . name ) ;
109+ }
110+ console . log ( tl . loc ( 'ServiceExternalIP' , resource . name , status . loadBalancer . ingress [ 0 ] . ip ) ) ;
111+ }
112+ } catch ( ex ) {
113+ tl . warning ( tl . loc ( 'CouldNotDetermineServiceStatus' , resource . name , JSON . stringify ( ex ) ) ) ;
114+ }
115+ }
95116 }
96117 utils . checkForErrors ( rolloutStatusResults ) ;
97118}
@@ -263,6 +284,34 @@ function isPodReady(podStatus: any): boolean {
263284 return allContainersAreReady ;
264285}
265286
287+ function getService ( kubectl : Kubectl , serviceName ) {
288+ const serviceResult = kubectl . getResource ( constants . DiscoveryAndLoadBalancerResource . service , serviceName ) ;
289+ utils . checkForErrors ( [ serviceResult ] ) ;
290+ return JSON . parse ( serviceResult . stdout ) ;
291+ }
292+
293+ async function waitForServiceExternalIPAssignment ( kubectl : Kubectl , serviceName : string ) : Promise < void > {
294+ const sleepTimeout = 10 * 1000 ; // 10 seconds
295+ const iterations = 18 ; // 18 * 10 seconds timeout = 3 minutes max timeout
296+
297+ for ( let i = 0 ; i < iterations ; i ++ ) {
298+ console . log ( tl . loc ( 'waitForServiceIpAssignment' , serviceName ) ) ;
299+ await sleep ( sleepTimeout ) ;
300+ let status = getService ( kubectl , serviceName ) . status ;
301+ if ( isLoadBalancerIPAssigned ( status ) ) {
302+ return ;
303+ }
304+ }
305+ tl . warning ( tl . loc ( 'waitForServiceIpAssignmentTimedOut' , serviceName ) ) ;
306+ }
307+
308+ function isLoadBalancerIPAssigned ( status : any ) {
309+ if ( status && status . loadBalancer && status . loadBalancer . ingress && status . loadBalancer . ingress . length > 0 ) {
310+ return true ;
311+ }
312+ return false ;
313+ }
314+
266315function sleep ( timeout : number ) {
267316 return new Promise ( resolve => setTimeout ( resolve , timeout ) ) ;
268317}
0 commit comments