6
6
'use strict' ;
7
7
8
8
const path = require ( 'path' ) ;
9
+ const readline = require ( 'readline' ) ;
9
10
10
11
const i18n = require ( './i18next.config' ) ;
11
12
const fsUtils = require ( './fsUtils' ) ;
12
- const { executeFileCommand } = require ( './childProcessExecutor' ) ;
13
+ const { executeFileCommand, spawnDaemonChildProcess } = require ( './childProcessExecutor' ) ;
13
14
const { getLogger } = require ( './wktLogging' ) ;
14
15
const { getHttpsProxyUrl, getBypassProxyHosts } = require ( './userSettings' ) ;
15
16
const { getErrorMessage } = require ( './errorUtils' ) ;
@@ -210,7 +211,7 @@ async function getOperatorStatus(kubectlExe, operatorNamespace, options) {
210
211
} ) ;
211
212
}
212
213
213
- async function getOperatorLogs ( kubectlExe , operatorNamespace , options ) {
214
+ async function getOperatorVersion ( kubectlExe , operatorNamespace , options ) {
214
215
const args = [ 'logs' , '-n' , operatorNamespace , '-c' , 'weblogic-operator' , 'deployments/weblogic-operator' ] ;
215
216
const httpsProxyUrl = getHttpsProxyUrl ( ) ;
216
217
const bypassProxyHosts = getBypassProxyHosts ( ) ;
@@ -219,38 +220,42 @@ async function getOperatorLogs(kubectlExe, operatorNamespace, options) {
219
220
isSuccess : true
220
221
} ;
221
222
222
- return new Promise ( resolve => {
223
- executeFileCommand ( kubectlExe , args , env ) . then ( operatorLogs => {
224
- const logs = operatorLogs . split ( '\n' ) ;
225
- results [ 'operatorLogs' ] = logs ;
226
- resolve ( results ) ;
227
- } ) . catch ( err => {
223
+ return new Promise ( ( resolve ) => {
224
+ const _kubectlChildProcess = spawnDaemonChildProcess ( kubectlExe , args , env ) ;
225
+ _kubectlChildProcess . on ( 'error' , ( err ) => {
228
226
results . isSuccess = false ;
229
- results . reason =
230
- i18n . t ( 'kubectl-get-operator-logs-error-message' , { error : getErrorMessage ( err ) } ) ;
227
+ results . reason = i18n . t ( 'kubectl-get-operator-version-error-message' , { error : getErrorMessage ( err ) } ) ;
231
228
resolve ( results ) ;
232
229
} ) ;
233
- } ) ;
234
- }
235
-
236
- async function getOperatorVersion ( kubectlExe , operatorNamespace , options ) {
237
- const results = {
238
- isSuccess : true
239
- } ;
230
+ _kubectlChildProcess . on ( 'exit' , ( code ) => {
231
+ getLogger ( ) . debug ( 'kubectl command to get the operator version from the pod log exited with code %s' , code ) ;
232
+ results . isSuccess = false ;
233
+ results . reason = i18n . t ( 'kubectl-get-operator-version-no-version-message' , { code } ) ;
234
+ } ) ;
240
235
241
- return new Promise ( resolve => {
242
- getOperatorLogs ( kubectlExe , operatorNamespace , options ) . then ( logResult => {
243
- if ( logResult . isSuccess === false ) {
244
- results . isSuccess = false ;
245
- results . reason = i18n . t ( 'kubectl-get-operator-version-error-message' , { error : logResult . reason } ) ;
246
- return resolve ( results ) ;
236
+ const stdoutLines = readline . createInterface ( { input : _kubectlChildProcess . stdout } ) ;
237
+ const stderrLines = readline . createInterface ( { input : _kubectlChildProcess . stderr } ) ;
238
+
239
+ let foundVersion = false ;
240
+ const versionRegex = / ^ O r a c l e W e b L o g i c K u b e r n e t e s O p e r a t o r , v e r s i o n : \s * ( \d + \. \d + \. \d + ) .* $ / ;
241
+ stdoutLines . on ( 'line' , ( line ) => {
242
+ if ( ! foundVersion ) {
243
+ const parseEntry = _parseLogEntryAsJson ( line ) ;
244
+ if ( typeof parseEntry !== 'undefined' ) {
245
+ const message = parseEntry . message || '' ;
246
+ const matcher = message . match ( versionRegex ) ;
247
+
248
+ if ( Array . isArray ( matcher ) && matcher . length > 1 ) {
249
+ foundVersion = true ;
250
+ results . version = matcher [ 1 ] ;
251
+ getLogger ( ) . debug ( 'Found installed operator version %s' , results . version ) ;
252
+ resolve ( results ) ;
253
+ }
254
+ }
247
255
}
248
- _getOperatorVersionFromLogs ( logResult . operatorLogs , results ) ;
249
- resolve ( results ) ;
250
- } ) . catch ( err => {
251
- results . isSuccess = false ;
252
- results . reason = i18n . t ( 'kubectl-get-operator-version-error-message' , { error : getErrorMessage ( err ) } ) ;
253
- resolve ( results ) ;
256
+ } ) ;
257
+ stderrLines . on ( 'line' , ( line ) => {
258
+ getLogger ( ) . debug ( 'kubectl logs for operator pod stderr: %s' , line . trim ( ) ) ;
254
259
} ) ;
255
260
} ) ;
256
261
}
@@ -1139,32 +1144,6 @@ function isNotFoundError(err) {
1139
1144
return / \( N o t F o u n d \) / . test ( errString ) ;
1140
1145
}
1141
1146
1142
- function _getOperatorVersionFromLogs ( operatorLogs , results ) {
1143
- const versionRegex = / ^ O r a c l e W e b L o g i c K u b e r n e t e s O p e r a t o r , v e r s i o n : \s * ( \d + \. \d + \. \d + ) .* $ / ;
1144
- if ( Array . isArray ( operatorLogs ) && operatorLogs . length > 0 ) {
1145
- for ( const logEntry of operatorLogs ) {
1146
- const parsedEntry = _parseLogEntryAsJson ( logEntry ) ;
1147
- if ( typeof parsedEntry === 'undefined' ) {
1148
- continue ;
1149
- }
1150
-
1151
- const message = parsedEntry . message || '' ;
1152
- const match = message . match ( versionRegex ) ;
1153
- if ( Array . isArray ( match ) && match . length > 1 ) {
1154
- results . isSuccess = true ;
1155
- results . version = match [ 1 ] ;
1156
- getLogger ( ) . debug ( 'Found installed operator version %s' , results . version ) ;
1157
- return ;
1158
- }
1159
- }
1160
- results . isSuccess = false ;
1161
- results . reason = i18n . t ( 'kubectl-get-operator-version-not-found-error-message' ) ;
1162
- } else {
1163
- results . isSuccess = false ;
1164
- results . reason = i18n . t ( 'kubectl-get-operator-version-logs-empty-error-message' ) ;
1165
- }
1166
- }
1167
-
1168
1147
function _parseLogEntryAsJson ( logEntry ) {
1169
1148
let result ;
1170
1149
@@ -1199,12 +1178,10 @@ module.exports = {
1199
1178
getK8sConfigView,
1200
1179
getK8sClusterInfo,
1201
1180
getVerrazzanoApplicationHostnames,
1202
- getVerrazzanoIngressExternalAddress,
1203
1181
getWkoDomainStatus,
1204
1182
getApplicationStatus,
1205
1183
getOperatorStatus,
1206
1184
getOperatorVersionFromDomainConfigMap,
1207
- getOperatorLogs,
1208
1185
getVerrazzanoInstallationObject,
1209
1186
getKubernetesObjectsByNamespace,
1210
1187
getKubernetesObjectsFromAllNamespaces,
0 commit comments