@@ -9,7 +9,7 @@ import { PromiseMiddlewareWrapper } from '@kubernetes/client-node/dist/gen/middl
9
9
/**
10
10
* Constants for interacting with Kubernetes/OpenShift clusters.
11
11
*/
12
- const RHTAPGitopsNamespace = process . env . RHTAP_GITOPS_NAMESPACE ?? 'rhtap-gitops' ;
12
+ const RHTAPGitopsNamespace = process . env . RHTAP_GITOPS_NAMESPACE ?? 'rhtap-gitops' ;
13
13
14
14
/**
15
15
* Kubernetes class for interacting with Kubernetes/OpenShift clusters.
@@ -36,7 +36,7 @@ export class Kubernetes extends Utils {
36
36
public async namespaceExists ( name : string ) : Promise < boolean > {
37
37
const k8sCoreApi = this . kubeConfig . makeApiClient ( CoreV1Api ) ;
38
38
try {
39
- const response = await k8sCoreApi . readNamespace ( { name : name } ) ;
39
+ const response = await k8sCoreApi . readNamespace ( { name : name } ) ;
40
40
if ( response ?. metadata ?. name === name ) {
41
41
return true ;
42
42
}
@@ -57,7 +57,7 @@ export class Kubernetes extends Utils {
57
57
public async getTaskRunsFromPipelineRun ( pipelineRunName : string ) : Promise < TaskRunKind [ ] > {
58
58
const customObjectsApi = this . kubeConfig . makeApiClient ( CustomObjectsApi ) ;
59
59
try {
60
- const taskRunList = await customObjectsApi . listClusterCustomObject ( { group : 'tekton.dev' , version : 'v1' , plural : 'taskruns' } ) ;
60
+ const taskRunList = await customObjectsApi . listClusterCustomObject ( { group : 'tekton.dev' , version : 'v1' , plural : 'taskruns' } ) ;
61
61
const taskRunInterface = taskRunList as TaskRunList ;
62
62
return taskRunInterface . items . filter ( taskRun => taskRun ?. metadata ?. ownerReferences ?. [ 0 ] . name === pipelineRunName ) ;
63
63
@@ -76,7 +76,7 @@ export class Kubernetes extends Utils {
76
76
public async getOpenshiftRoute ( name : string , namespace : string ) : Promise < string > {
77
77
const customObjectsApi = this . kubeConfig . makeApiClient ( CustomObjectsApi ) ;
78
78
try {
79
- const route = await customObjectsApi . getNamespacedCustomObject ( { group : 'route.openshift.io' , version : 'v1' , plural : 'routes' , name : name , namespace : namespace } ) ;
79
+ const route = await customObjectsApi . getNamespacedCustomObject ( { group : 'route.openshift.io' , version : 'v1' , plural : 'routes' , name : name , namespace : namespace } ) ;
80
80
return route . spec . host ;
81
81
} catch ( error ) {
82
82
console . error ( error ) ;
@@ -95,19 +95,19 @@ export class Kubernetes extends Utils {
95
95
const k8sApi = this . kubeConfig . makeApiClient ( CoreV1Api ) ;
96
96
try {
97
97
// Get the pod object
98
- const pod = await k8sApi . readNamespacedPod ( { name : podName , namespace : namespace } ) ;
98
+ const pod = await k8sApi . readNamespacedPod ( { name : podName , namespace : namespace } ) ;
99
99
100
100
// Check if pod.spec is defined
101
101
if ( pod . spec ?. containers ) {
102
102
// Iterate over each container in the pod
103
103
for ( const container of pod . spec . containers ) {
104
104
// Get logs from each container
105
- const response = await k8sApi . readNamespacedPodLog ( { name : podName , namespace : namespace , container : container . name } ) ;
105
+ const response = await k8sApi . readNamespacedPodLog ( { name : podName , namespace : namespace , container : container . name } ) ;
106
106
107
107
// Append container name before the logs
108
108
const logsWithContainerInfo = `Container: ${ container . name } \n${ response } \n\n` ;
109
109
const logFilePath = path . join ( 'taskruns-logs' , podName ) ;
110
- await this . writeLogsToArtifactDir ( logFilePath , `${ container . name } .log` , logsWithContainerInfo ) ;
110
+ this . writeLogsToArtifactDir ( logFilePath , `${ container . name } .log` , logsWithContainerInfo ) ;
111
111
}
112
112
113
113
} else {
@@ -130,7 +130,7 @@ export class Kubernetes extends Utils {
130
130
const k8sApi = this . kubeConfig . makeApiClient ( CoreV1Api ) ;
131
131
try {
132
132
// Get logs from the given container
133
- const response = await k8sApi . readNamespacedPodLog ( { name : podName , namespace : namespace , container : containerName } ) ;
133
+ const response = await k8sApi . readNamespacedPodLog ( { name : podName , namespace : namespace , container : containerName } ) ;
134
134
return ( response ) ;
135
135
} catch ( err ) {
136
136
console . error ( 'Error:' , err ) ;
@@ -151,8 +151,10 @@ export class Kubernetes extends Utils {
151
151
152
152
for ( let attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
153
153
try {
154
- const body = await customObjectsApi . listClusterCustomObject ( { group : 'tekton.dev' , version :'v1' , plural : 'pipelineruns' ,
155
- labelSelector : `pipelinesascode.tekton.dev/url-repository=${ gitRepository } ` } ) ;
154
+ const body = await customObjectsApi . listClusterCustomObject ( {
155
+ group : 'tekton.dev' , version : 'v1' , plural : 'pipelineruns' ,
156
+ labelSelector : `pipelinesascode.tekton.dev/url-repository=${ gitRepository } `
157
+ } ) ;
156
158
const pr = body as PipelineRunList ;
157
159
158
160
const filteredPipelineRuns = pr . items . filter ( ( pipelineRun : PipelineRunKind ) => {
@@ -203,7 +205,7 @@ export class Kubernetes extends Utils {
203
205
204
206
while ( timeoutMs === 0 || totalTimeMs < timeoutMs ) {
205
207
try {
206
- const body = await customObjectsApi . getNamespacedCustomObject ( { group : 'tekton.dev' , version : 'v1' , namespace : namespace , plural : 'pipelineruns' , name : name } ) ;
208
+ const body = await customObjectsApi . getNamespacedCustomObject ( { group : 'tekton.dev' , version : 'v1' , namespace : namespace , plural : 'pipelineruns' , name : name } ) ;
207
209
const pr = body as PipelineRunKind ;
208
210
209
211
if ( pr . status ?. conditions ) {
@@ -272,7 +274,7 @@ export class Kubernetes extends Utils {
272
274
273
275
while ( timeoutMs === 0 || totalTimeMs < timeoutMs ) {
274
276
try {
275
- const body = await customObjectsApi . getNamespacedCustomObject ( { group : 'argoproj.io' , version : 'v1alpha1' , namespace : RHTAPGitopsNamespace , plural : 'applications' , name : name } ) ;
277
+ const body = await customObjectsApi . getNamespacedCustomObject ( { group : 'argoproj.io' , version : 'v1alpha1' , namespace : RHTAPGitopsNamespace , plural : 'applications' , name : name } ) ;
276
278
const application = body as ApplicationSpec ;
277
279
278
280
if ( application . status ?. sync ?. status &&
@@ -320,9 +322,9 @@ export class Kubernetes extends Utils {
320
322
const headerPatchMiddleware = new PromiseMiddlewareWrapper ( {
321
323
pre : async ( requestContext : RequestContext ) => {
322
324
requestContext . setHeaderParam ( 'Content-Type' , 'application/merge-patch+json' ) ;
323
- return requestContext ;
325
+ return await Promise . resolve ( requestContext ) ;
324
326
} ,
325
- post : async ( responseContext : ResponseContext ) => responseContext ,
327
+ post : async ( responseContext : ResponseContext ) => await Promise . resolve ( responseContext ) ,
326
328
} ) ;
327
329
const currentContext = this . kubeConfig . getCurrentContext ( ) ;
328
330
const currentCluster = this . kubeConfig . getCluster ( currentContext ) ;
@@ -344,11 +346,11 @@ export class Kubernetes extends Utils {
344
346
} ) ;
345
347
346
348
// Patch the app
347
- await k8sCoreApi . patchNamespacedCustomObject ( { group : 'argoproj.io' , version : 'v1alpha1' , namespace : namespace , plural : 'applications' , name : applicationName , body : patchObject } , configuration ) ;
349
+ await k8sCoreApi . patchNamespacedCustomObject ( { group : 'argoproj.io' , version : 'v1alpha1' , namespace : namespace , plural : 'applications' , name : applicationName , body : patchObject } , configuration ) ;
348
350
349
351
350
352
// Delete the app
351
- await k8sCoreApi . deleteNamespacedCustomObject ( { group : 'argoproj.io' , version : 'v1alpha1' , namespace : namespace , plural : 'applications' , name : applicationName } ) ;
353
+ await k8sCoreApi . deleteNamespacedCustomObject ( { group : 'argoproj.io' , version : 'v1alpha1' , namespace : namespace , plural : 'applications' , name : applicationName } ) ;
352
354
353
355
console . log ( `App ${ applicationName } patched and deleted successfully.` ) ;
354
356
} catch ( error ) {
@@ -369,7 +371,7 @@ export class Kubernetes extends Utils {
369
371
const k8sApi = this . kubeConfig . makeApiClient ( CoreV1Api ) ;
370
372
try {
371
373
// Fetch the secret from the specified namespace
372
- const secret = await k8sApi . readNamespacedSecret ( { name : secretName , namespace : namespace } ) ;
374
+ const secret = await k8sApi . readNamespacedSecret ( { name : secretName , namespace : namespace } ) ;
373
375
374
376
// Check if the key exists in the secret data
375
377
if ( secret . data && secret . data [ keyName ] ) {
@@ -392,7 +394,7 @@ export class Kubernetes extends Utils {
392
394
const k8sApi = this . kubeConfig . makeApiClient ( CoreV1Api ) ;
393
395
394
396
// List all secrets
395
- const secretList = await k8sApi . listNamespacedSecret ( { namespace : namespace } ) ;
397
+ const secretList = await k8sApi . listNamespacedSecret ( { namespace : namespace } ) ;
396
398
397
399
// Filter secrets
398
400
const matchingSecrets = secretList . items . filter ( secret => secret . metadata ?. name ?. startsWith ( partialSecretName ) ) ;
@@ -461,21 +463,21 @@ export class Kubernetes extends Utils {
461
463
* Gets cosign public key.
462
464
*/
463
465
public async getCosignPublicKey ( ) : Promise < string > {
464
- return this . getSecretPartialName ( "openshift-pipelines" , "signing-secrets" , "cosign.pub" , false ) ;
466
+ return await this . getSecretPartialName ( "openshift-pipelines" , "signing-secrets" , "cosign.pub" , false ) ;
465
467
}
466
468
467
469
/**
468
470
* Gets cosign private key.
469
471
*/
470
472
public async getCosignPrivateKey ( ) : Promise < string > {
471
- return this . getSecretPartialName ( "openshift-pipelines" , "signing-secrets" , "cosign.key" , false ) ;
473
+ return await this . getSecretPartialName ( "openshift-pipelines" , "signing-secrets" , "cosign.key" , false ) ;
472
474
}
473
475
474
476
/**
475
477
* Gets cosign password.
476
478
*/
477
479
public async getCosignPassword ( ) : Promise < string > {
478
- return this . getSecretPartialName ( "openshift-pipelines" , "signing-secrets" , "cosign.password" , false ) ;
480
+ return await this . getSecretPartialName ( "openshift-pipelines" , "signing-secrets" , "cosign.password" , false ) ;
479
481
}
480
482
481
483
/**
@@ -485,7 +487,7 @@ export class Kubernetes extends Utils {
485
487
* @returns {Promise<string> } - returns route URL.
486
488
*/
487
489
public async getACSEndpoint ( namespace : string ) : Promise < string > {
488
- return this . getDeveloperHubSecret ( namespace , "rhtap-acs-integration" , "endpoint" ) ;
490
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-acs-integration" , "endpoint" ) ;
489
491
}
490
492
491
493
/**
@@ -495,7 +497,7 @@ export class Kubernetes extends Utils {
495
497
* @returns {Promise<string> } - returns token.
496
498
*/
497
499
public async getACSToken ( namespace : string ) : Promise < string > {
498
- return this . getDeveloperHubSecret ( namespace , "rhtap-acs-integration" , "token" ) ;
500
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-acs-integration" , "token" ) ;
499
501
}
500
502
501
503
/**
@@ -505,7 +507,7 @@ export class Kubernetes extends Utils {
505
507
* @returns {Promise<string> } - returns route URL.
506
508
*/
507
509
public async getRekorServerUrl ( namespace : string ) : Promise < string > {
508
- return this . getDeveloperHubSecret ( namespace , "rhtap-tas-integration" , "rekor_url" ) ;
510
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-tas-integration" , "rekor_url" ) ;
509
511
}
510
512
511
513
/**
@@ -515,7 +517,7 @@ export class Kubernetes extends Utils {
515
517
* @returns {Promise<string> } - returns route URL.
516
518
*/
517
519
public async getTUFUrl ( namespace : string ) : Promise < string > {
518
- return this . getDeveloperHubSecret ( namespace , "rhtap-tas-integration" , "tuf_url" ) ;
520
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-tas-integration" , "tuf_url" ) ;
519
521
}
520
522
521
523
/**
@@ -527,7 +529,7 @@ export class Kubernetes extends Utils {
527
529
public async getPodYaml ( PodName : string , nameSpace : string ) : Promise < string | null > {
528
530
const k8sCoreApi = this . kubeConfig . makeApiClient ( CoreV1Api ) ;
529
531
try {
530
- const response = await k8sCoreApi . readNamespacedPod ( { name : PodName , namespace : nameSpace } ) ;
532
+ const response = await k8sCoreApi . readNamespacedPod ( { name : PodName , namespace : nameSpace } ) ;
531
533
const podYaml = dumpYaml ( response ) ;
532
534
return podYaml ;
533
535
}
@@ -544,7 +546,7 @@ export class Kubernetes extends Utils {
544
546
* @returns {Promise<string> } - returns route URL.
545
547
*/
546
548
public async getTTrustificationBombasticApiUrl ( namespace : string ) : Promise < string > {
547
- return this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "bombastic_api_url" ) ;
549
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "bombastic_api_url" ) ;
548
550
}
549
551
550
552
/**
@@ -554,7 +556,7 @@ export class Kubernetes extends Utils {
554
556
* @returns {Promise<string> } - returns route URL.
555
557
*/
556
558
public async getTTrustificationOidcIssuerUrl ( namespace : string ) : Promise < string > {
557
- return this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "oidc_issuer_url" ) ;
559
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "oidc_issuer_url" ) ;
558
560
}
559
561
560
562
/**
@@ -564,7 +566,7 @@ export class Kubernetes extends Utils {
564
566
* @returns {Promise<string> } - returns route URL.
565
567
*/
566
568
public async getTTrustificationClientId ( namespace : string ) : Promise < string > {
567
- return this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "oidc_client_id" ) ;
569
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "oidc_client_id" ) ;
568
570
}
569
571
570
572
/**
@@ -574,7 +576,7 @@ export class Kubernetes extends Utils {
574
576
* @returns {Promise<string> } - returns route URL.
575
577
*/
576
578
public async getTTrustificationClientSecret ( namespace : string ) : Promise < string > {
577
- return this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "oidc_client_secret" ) ;
579
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "oidc_client_secret" ) ;
578
580
}
579
581
580
582
/**
@@ -584,6 +586,6 @@ export class Kubernetes extends Utils {
584
586
* @returns {Promise<string> } - returns route URL.
585
587
*/
586
588
public async getTTrustificationSupportedCycloneDXVersion ( namespace : string ) : Promise < string > {
587
- return this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "supported_cyclonedx_version" ) ;
589
+ return await this . getDeveloperHubSecret ( namespace , "rhtap-trustification-integration" , "supported_cyclonedx_version" ) ;
588
590
}
589
591
}
0 commit comments