@@ -369,92 +369,98 @@ class KubelessDeploy {
369369 return new BbPromise ( ( resolve , reject ) => {
370370 _ . each ( this . serverless . service . functions , ( description , name ) => {
371371 const runtime = this . serverless . service . provider . runtime ;
372- const files = this . getRuntimeFilenames ( runtime , description . handler ) ;
373- const connectionOptions = helpers . getConnectionOptions (
374- helpers . loadKubeConfig ( ) , {
375- namespace : description . namespace ||
376- this . serverless . service . provider . namespace ,
377- }
378- ) ;
379- const thirdPartyResources = this . getThirdPartyResources ( connectionOptions ) ;
380- thirdPartyResources . addResource ( 'functions' ) ;
381- this . getFunctionContent ( files . handler )
382- . then ( functionContent => {
383- this . getFunctionContent ( files . deps )
384- . catch ( ( ) => {
385- // No requirements found
386- } )
387- . then ( ( requirementsContent ) => {
388- const events = ! _ . isEmpty ( description . events ) ?
389- description . events :
390- [ { http : { path : '/' } } ] ;
391- _ . each ( events , event => {
392- const eventType = _ . keys ( event ) [ 0 ] ;
393- const funcs = getFunctionDescription (
394- name ,
395- thirdPartyResources . namespaces . namespace ,
396- this . serverless . service . provider . runtime ,
397- requirementsContent ,
398- functionContent ,
399- description . handler ,
400- description . description ,
401- description . labels ,
402- description . environment ,
403- description . memorySize || this . serverless . service . provider . memorySize ,
404- eventType ,
405- event . trigger
406- ) ;
407- let deploymentPromise = null ;
408- thirdPartyResources . ns . functions . get ( ( err , functionsInfo ) => {
409- if ( err ) throw err ;
410- const existingFunction = _ . find ( functionsInfo . items , item => (
411- _ . isEqual ( item . spec , funcs . spec )
412- ) ) ;
413- if ( existingFunction ) {
414- // The same function is already deployed, skipping the deployment
415- this . serverless . cli . log (
416- `Function ${ name } has not changed. Skipping deployment`
417- ) ;
418- deploymentPromise = new BbPromise ( r => r ( false ) ) ;
419- } else {
420- deploymentPromise = this . deployFunctionAndWait ( funcs , thirdPartyResources ) ;
421- }
422- deploymentPromise . catch ( deploymentErr => {
423- errors . push ( deploymentErr ) ;
424- } )
425- . then ( ( deployed ) => {
426- if ( ! deployed ) {
427- // If there were an error with the deployment
428- // don't try to add an ingress rule
429- return new BbPromise ( ( r ) => r ( ) ) ;
430- }
431- return this . addIngressRuleIfNecessary (
432- name ,
433- eventType ,
434- event [ eventType ] . path ,
435- connectionOptions . namespace
372+ if ( description . handler ) {
373+ const files = this . getRuntimeFilenames ( runtime , description . handler ) ;
374+ const connectionOptions = helpers . getConnectionOptions (
375+ helpers . loadKubeConfig ( ) , {
376+ namespace : description . namespace ||
377+ this . serverless . service . provider . namespace ,
378+ }
379+ ) ;
380+ const thirdPartyResources = this . getThirdPartyResources ( connectionOptions ) ;
381+ thirdPartyResources . addResource ( 'functions' ) ;
382+ this . getFunctionContent ( files . handler )
383+ . then ( functionContent => {
384+ this . getFunctionContent ( files . deps )
385+ . catch ( ( ) => {
386+ // No requirements found
387+ } )
388+ . then ( ( requirementsContent ) => {
389+ const events = ! _ . isEmpty ( description . events ) ?
390+ description . events :
391+ [ { http : { path : '/' } } ] ;
392+ _ . each ( events , event => {
393+ const eventType = _ . keys ( event ) [ 0 ] ;
394+ const funcs = getFunctionDescription (
395+ name ,
396+ thirdPartyResources . namespaces . namespace ,
397+ this . serverless . service . provider . runtime ,
398+ requirementsContent ,
399+ functionContent ,
400+ description . handler ,
401+ description . description ,
402+ description . labels ,
403+ description . environment ,
404+ description . memorySize || this . serverless . service . provider . memorySize ,
405+ eventType ,
406+ event . trigger
407+ ) ;
408+ let deploymentPromise = null ;
409+ thirdPartyResources . ns . functions . get ( ( err , functionsInfo ) => {
410+ if ( err ) throw err ;
411+ const existingFunction = _ . find ( functionsInfo . items , item => (
412+ _ . isEqual ( item . spec , funcs . spec )
413+ ) ) ;
414+ if ( existingFunction ) {
415+ // The same function is already deployed, skipping the deployment
416+ this . serverless . cli . log (
417+ `Function ${ name } has not changed. Skipping deployment`
436418 ) ;
419+ deploymentPromise = new BbPromise ( r => r ( false ) ) ;
420+ } else {
421+ deploymentPromise = this . deployFunctionAndWait ( funcs , thirdPartyResources ) ;
422+ }
423+ deploymentPromise . catch ( deploymentErr => {
424+ errors . push ( deploymentErr ) ;
437425 } )
438- . catch ( ingressErr => {
439- errors . push ( ingressErr ) ;
440- } )
441- . then ( ( ) => {
442- counter ++ ;
443- if ( counter === _ . keys ( this . serverless . service . functions ) . length ) {
444- if ( _ . isEmpty ( errors ) ) {
445- resolve ( ) ;
446- } else {
447- reject (
448- 'Found errors while deploying the given functions:\n' +
449- `${ errors . join ( '\n' ) } `
450- ) ;
426+ . then ( ( deployed ) => {
427+ if ( ! deployed ) {
428+ // If there were an error with the deployment
429+ // don't try to add an ingress rule
430+ return new BbPromise ( ( r ) => r ( ) ) ;
451431 }
452- }
453- } ) ;
432+ return this . addIngressRuleIfNecessary (
433+ name ,
434+ eventType ,
435+ event [ eventType ] . path ,
436+ connectionOptions . namespace
437+ ) ;
438+ } )
439+ . catch ( ingressErr => {
440+ errors . push ( ingressErr ) ;
441+ } )
442+ . then ( ( ) => {
443+ counter ++ ;
444+ if ( counter === _ . keys ( this . serverless . service . functions ) . length ) {
445+ if ( _ . isEmpty ( errors ) ) {
446+ resolve ( ) ;
447+ } else {
448+ reject (
449+ 'Found errors while deploying the given functions:\n' +
450+ `${ errors . join ( '\n' ) } `
451+ ) ;
452+ }
453+ }
454+ } ) ;
455+ } ) ;
454456 } ) ;
455457 } ) ;
456- } ) ;
457- } ) ;
458+ } ) ;
459+ } else {
460+ this . serverless . cli . log (
461+ `Skipping deployment of ${ name } since it doesn't have a handler`
462+ ) ;
463+ }
458464 } ) ;
459465 } ) ;
460466 }
0 commit comments