@@ -23,35 +23,37 @@ export function deploySMICanary(kubectl: Kubectl, filePaths: string[]) {
2323 filePaths . forEach ( ( filePath : string ) => {
2424 const fileContents = fs . readFileSync ( filePath ) ;
2525 yaml . safeLoadAll ( fileContents , function ( inputObject ) {
26- const name = inputObject . metadata . name ;
27- const kind = inputObject . kind ;
28- if ( helper . isDeploymentEntity ( kind ) ) {
29- // Get stable object
30- tl . debug ( 'Querying stable object' ) ;
31- const stableObject = canaryDeploymentHelper . fetchResource ( kubectl , kind , name ) ;
32- if ( ! stableObject ) {
33- tl . debug ( 'Stable object not found. Creating only canary object' ) ;
34- // If stable object not found, create canary deployment.
35- const newCanaryObject = canaryDeploymentHelper . getNewCanaryResource ( inputObject , canaryReplicaCount ) ;
36- tl . debug ( 'New canary object is: ' + JSON . stringify ( newCanaryObject ) ) ;
37- newObjectsList . push ( newCanaryObject ) ;
38- } else {
39- if ( ! canaryDeploymentHelper . isResourceMarkedAsStable ( stableObject ) ) {
40- throw ( tl . loc ( 'StableSpecSelectorNotExist' , name ) ) ;
41- }
26+ if ( inputObject ) {
27+ const name = inputObject . metadata . name ;
28+ const kind = inputObject . kind ;
29+ if ( helper . isDeploymentEntity ( kind ) ) {
30+ // Get stable object
31+ tl . debug ( 'Querying stable object' ) ;
32+ const stableObject = canaryDeploymentHelper . fetchResource ( kubectl , kind , name ) ;
33+ if ( ! stableObject ) {
34+ tl . debug ( 'Stable object not found. Creating only canary object' ) ;
35+ // If stable object not found, create canary deployment.
36+ const newCanaryObject = canaryDeploymentHelper . getNewCanaryResource ( inputObject , canaryReplicaCount ) ;
37+ tl . debug ( 'New canary object is: ' + JSON . stringify ( newCanaryObject ) ) ;
38+ newObjectsList . push ( newCanaryObject ) ;
39+ } else {
40+ if ( ! canaryDeploymentHelper . isResourceMarkedAsStable ( stableObject ) ) {
41+ throw ( tl . loc ( 'StableSpecSelectorNotExist' , name ) ) ;
42+ }
4243
43- tl . debug ( 'Stable object found. Creating canary and baseline objects' ) ;
44- // If canary object not found, create canary and baseline object.
45- const newCanaryObject = canaryDeploymentHelper . getNewCanaryResource ( inputObject , canaryReplicaCount ) ;
46- const newBaselineObject = canaryDeploymentHelper . getNewBaselineResource ( stableObject , canaryReplicaCount ) ;
47- tl . debug ( 'New canary object is: ' + JSON . stringify ( newCanaryObject ) ) ;
48- tl . debug ( 'New baseline object is: ' + JSON . stringify ( newBaselineObject ) ) ;
49- newObjectsList . push ( newCanaryObject ) ;
50- newObjectsList . push ( newBaselineObject ) ;
44+ tl . debug ( 'Stable object found. Creating canary and baseline objects' ) ;
45+ // If canary object not found, create canary and baseline object.
46+ const newCanaryObject = canaryDeploymentHelper . getNewCanaryResource ( inputObject , canaryReplicaCount ) ;
47+ const newBaselineObject = canaryDeploymentHelper . getNewBaselineResource ( stableObject , canaryReplicaCount ) ;
48+ tl . debug ( 'New canary object is: ' + JSON . stringify ( newCanaryObject ) ) ;
49+ tl . debug ( 'New baseline object is: ' + JSON . stringify ( newBaselineObject ) ) ;
50+ newObjectsList . push ( newCanaryObject ) ;
51+ newObjectsList . push ( newBaselineObject ) ;
52+ }
53+ } else {
54+ // Updating non deployment entity as it is.
55+ newObjectsList . push ( inputObject ) ;
5156 }
52- } else {
53- // Updating non deployment entity as it is.
54- newObjectsList . push ( inputObject ) ;
5557 }
5658 } ) ;
5759 } ) ;
@@ -69,48 +71,49 @@ function createCanaryService(kubectl: Kubectl, filePaths: string[]) {
6971 filePaths . forEach ( ( filePath : string ) => {
7072 const fileContents = fs . readFileSync ( filePath ) ;
7173 yaml . safeLoadAll ( fileContents , function ( inputObject ) {
74+ if ( inputObject ) {
75+ const name = inputObject . metadata . name ;
76+ const kind = inputObject . kind ;
77+ if ( helper . isServiceEntity ( kind ) ) {
78+ const newCanaryServiceObject = canaryDeploymentHelper . getNewCanaryResource ( inputObject ) ;
79+ tl . debug ( 'New canary service object is: ' + JSON . stringify ( newCanaryServiceObject ) ) ;
80+ newObjectsList . push ( newCanaryServiceObject ) ;
81+
82+ const newBaselineServiceObject = canaryDeploymentHelper . getNewBaselineResource ( inputObject ) ;
83+ tl . debug ( 'New baseline object is: ' + JSON . stringify ( newBaselineServiceObject ) ) ;
84+ newObjectsList . push ( newBaselineServiceObject ) ;
85+
86+ tl . debug ( 'Querying for stable service object' ) ;
87+ const stableObject = canaryDeploymentHelper . fetchResource ( kubectl , kind , canaryDeploymentHelper . getStableResourceName ( name ) ) ;
88+ if ( ! stableObject ) {
89+ const newStableServiceObject = canaryDeploymentHelper . getStableResource ( inputObject ) ;
90+ tl . debug ( 'New stable service object is: ' + JSON . stringify ( newStableServiceObject ) ) ;
91+ newObjectsList . push ( newStableServiceObject ) ;
92+
93+ tl . debug ( 'Creating the traffic object for service: ' + name ) ;
94+ const trafficObject = createTrafficSplitManifestFile ( name , 0 , 0 , 1000 ) ;
95+ tl . debug ( 'Creating the traffic object for service: ' + trafficObject ) ;
96+ trafficObjectsList . push ( trafficObject ) ;
97+ } else {
98+ let updateTrafficObject = true ;
99+ const trafficObject = canaryDeploymentHelper . fetchResource ( kubectl , TRAFFIC_SPLIT_OBJECT , getTrafficSplitResourceName ( name ) ) ;
100+ if ( trafficObject ) {
101+ const trafficJObject = JSON . parse ( JSON . stringify ( trafficObject ) ) ;
102+ if ( trafficJObject && trafficJObject . spec && trafficJObject . spec . backends ) {
103+ trafficJObject . spec . backends . forEach ( ( s ) => {
104+ if ( s . service === canaryDeploymentHelper . getCanaryResourceName ( name ) && s . weight === "1000m" ) {
105+ tl . debug ( 'Update traffic objcet not required' ) ;
106+ updateTrafficObject = false ;
107+ }
108+ } )
109+ }
110+ }
72111
73- const name = inputObject . metadata . name ;
74- const kind = inputObject . kind ;
75- if ( helper . isServiceEntity ( kind ) ) {
76- const newCanaryServiceObject = canaryDeploymentHelper . getNewCanaryResource ( inputObject ) ;
77- tl . debug ( 'New canary service object is: ' + JSON . stringify ( newCanaryServiceObject ) ) ;
78- newObjectsList . push ( newCanaryServiceObject ) ;
79-
80- const newBaselineServiceObject = canaryDeploymentHelper . getNewBaselineResource ( inputObject ) ;
81- tl . debug ( 'New baseline object is: ' + JSON . stringify ( newBaselineServiceObject ) ) ;
82- newObjectsList . push ( newBaselineServiceObject ) ;
83-
84- tl . debug ( 'Querying for stable service object' ) ;
85- const stableObject = canaryDeploymentHelper . fetchResource ( kubectl , kind , canaryDeploymentHelper . getStableResourceName ( name ) ) ;
86- if ( ! stableObject ) {
87- const newStableServiceObject = canaryDeploymentHelper . getStableResource ( inputObject ) ;
88- tl . debug ( 'New stable service object is: ' + JSON . stringify ( newStableServiceObject ) ) ;
89- newObjectsList . push ( newStableServiceObject ) ;
90-
91- tl . debug ( 'Creating the traffic object for service: ' + name ) ;
92- const trafficObject = createTrafficSplitManifestFile ( name , 0 , 0 , 1000 ) ;
93- tl . debug ( 'Creating the traffic object for service: ' + trafficObject ) ;
94- trafficObjectsList . push ( trafficObject ) ;
95- } else {
96- let updateTrafficObject = true ;
97- const trafficObject = canaryDeploymentHelper . fetchResource ( kubectl , TRAFFIC_SPLIT_OBJECT , getTrafficSplitResourceName ( name ) ) ;
98- if ( trafficObject ) {
99- const trafficJObject = JSON . parse ( JSON . stringify ( trafficObject ) ) ;
100- if ( trafficJObject && trafficJObject . spec && trafficJObject . spec . backends ) {
101- trafficJObject . spec . backends . forEach ( ( s ) => {
102- if ( s . service === canaryDeploymentHelper . getCanaryResourceName ( name ) && s . weight === "1000m" ) {
103- tl . debug ( 'Update traffic objcet not required' ) ;
104- updateTrafficObject = false ;
105- }
106- } )
112+ if ( updateTrafficObject ) {
113+ tl . debug ( 'Stable service object present so updating the traffic object for service: ' + name ) ;
114+ trafficObjectsList . push ( updateTrafficSplitObject ( name ) ) ;
107115 }
108116 }
109-
110- if ( updateTrafficObject ) {
111- tl . debug ( 'Stable service object present so updating the traffic object for service: ' + name ) ;
112- trafficObjectsList . push ( updateTrafficSplitObject ( name ) ) ;
113- }
114117 }
115118 }
116119 } ) ;
@@ -152,7 +155,7 @@ function adjustTraffic(kubectl: Kubectl, manifestFilePaths: string[], stableWeig
152155 const inputManifestFiles : string [ ] = utils . getManifestFiles ( manifestFilePaths ) ;
153156
154157 if ( inputManifestFiles == null || inputManifestFiles . length == 0 ) {
155- return ;
158+ return ;
156159 }
157160
158161 const trafficSplitManifests = [ ] ;
0 commit comments