66'use strict' ;
77
88const path = require ( 'path' ) ;
9+ const readline = require ( 'readline' ) ;
910
1011const i18n = require ( './i18next.config' ) ;
1112const fsUtils = require ( './fsUtils' ) ;
12- const { executeFileCommand } = require ( './childProcessExecutor' ) ;
13+ const { executeFileCommand, spawnDaemonChildProcess } = require ( './childProcessExecutor' ) ;
1314const { getLogger } = require ( './wktLogging' ) ;
1415const { getHttpsProxyUrl, getBypassProxyHosts } = require ( './userSettings' ) ;
1516const { getErrorMessage } = require ( './errorUtils' ) ;
@@ -210,7 +211,7 @@ async function getOperatorStatus(kubectlExe, operatorNamespace, options) {
210211 } ) ;
211212}
212213
213- async function getOperatorLogs ( kubectlExe , operatorNamespace , options ) {
214+ async function getOperatorVersion ( kubectlExe , operatorNamespace , options ) {
214215 const args = [ 'logs' , '-n' , operatorNamespace , '-c' , 'weblogic-operator' , 'deployments/weblogic-operator' ] ;
215216 const httpsProxyUrl = getHttpsProxyUrl ( ) ;
216217 const bypassProxyHosts = getBypassProxyHosts ( ) ;
@@ -219,38 +220,42 @@ async function getOperatorLogs(kubectlExe, operatorNamespace, options) {
219220 isSuccess : true
220221 } ;
221222
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 ) => {
228226 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 ) } ) ;
231228 resolve ( results ) ;
232229 } ) ;
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+ } ) ;
240235
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+ }
247255 }
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 ( ) ) ;
254259 } ) ;
255260 } ) ;
256261}
@@ -1139,32 +1144,6 @@ function isNotFoundError(err) {
11391144 return / \( N o t F o u n d \) / . test ( errString ) ;
11401145}
11411146
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-
11681147function _parseLogEntryAsJson ( logEntry ) {
11691148 let result ;
11701149
@@ -1199,12 +1178,10 @@ module.exports = {
11991178 getK8sConfigView,
12001179 getK8sClusterInfo,
12011180 getVerrazzanoApplicationHostnames,
1202- getVerrazzanoIngressExternalAddress,
12031181 getWkoDomainStatus,
12041182 getApplicationStatus,
12051183 getOperatorStatus,
12061184 getOperatorVersionFromDomainConfigMap,
1207- getOperatorLogs,
12081185 getVerrazzanoInstallationObject,
12091186 getKubernetesObjectsByNamespace,
12101187 getKubernetesObjectsFromAllNamespaces,
0 commit comments