1
1
'use strict' ;
2
2
3
3
import { Codefresh } from './codefresh.js' ;
4
- import { autoDetectClient } from 'https://deno.land/x/[email protected] /mod.ts' ;
5
- import { AppsV1Api } from 'https://deno.land/x/[email protected] /builtin/apps@v1/mod.ts' ;
6
- import { BatchV1Api } from 'https://deno.land/x/[email protected] /builtin/batch@v1/mod.ts' ;
7
- import { CoreV1Api } from 'https://deno.land/x/[email protected] /builtin/core@v1/mod.ts' ;
8
- import { StorageV1Api } from 'https://deno.land/x/[email protected] /builtin/storage.k8s.io@v1/mod.ts' ;
9
- import { ArgoprojIoV1alpha1Api } from 'https://deno.land/x/[email protected] /argo-cd/argoproj.io@v1alpha1/mod.ts' ;
10
- import { compress } from 'https://deno.land/x/[email protected] /mod.ts' ;
11
- import { stringify as toYaml } from 'https://deno.land/[email protected] /yaml/mod.ts' ;
4
+ import { autoDetectClient } from '@cloudydeno/kubernetes-client' ;
5
+ import { AppsV1Api } from '@cloudydeno/kubernetes-apis/apps/v1' ;
6
+ import { BatchV1Api } from '@cloudydeno/kubernetes-apis/batch/v1' ;
7
+ import { CoreV1Api } from '@cloudydeno/kubernetes-apis/core/v1' ;
8
+ import { StorageV1Api } from '@cloudydeno/kubernetes-apis/storage.k8s.io/v1' ;
9
+ import { ArgoprojIoV1alpha1Api } from '@cloudydeno/kubernetes-apis/argoproj.io/v1alpha1' ;
10
+
11
+ import { compress } from '@fakoua/zip-ts' ;
12
+ import { stringify as toYaml } from '@std/yaml' ;
12
13
13
14
console . log ( 'Initializing \n' ) ;
14
15
const kubeConfig = await autoDetectClient ( ) ;
@@ -21,7 +22,7 @@ const timestamp = new Date().getTime();
21
22
const dirPath = `./codefresh-support-${ timestamp } ` ;
22
23
23
24
function selectRuntimeType ( ) {
24
- const reTypes = [ 'classic ' , 'gitops ' , 'onprem ' ] ;
25
+ const reTypes = [ 'Pipelines Runtime ' , 'GitOps Runtime ' , 'On-Prem ' ] ;
25
26
reTypes . forEach ( ( reType , index ) => {
26
27
console . log ( `${ index + 1 } . ${ reType } ` ) ;
27
28
} ) ;
@@ -82,10 +83,12 @@ async function saveHelmReleases(type, namespace) {
82
83
83
84
function dataFetchers ( type , namespace ) {
84
85
switch ( type ) {
85
- case 'classic ' :
86
+ case 'Pipelines Runtime ' :
86
87
return {
87
88
'Cron' : ( ) => batchApi . namespace ( namespace ) . getCronJobList ( ) ,
88
89
'Jobs' : ( ) => batchApi . namespace ( namespace ) . getJobList ( ) ,
90
+ 'Deployments' : ( ) => appsApi . namespace ( namespace ) . getDeploymentList ( ) ,
91
+ 'Daemonsets' : ( ) => appsApi . namespace ( namespace ) . getDaemonSetList ( ) ,
89
92
'Nodes' : ( ) => coreApi . getNodeList ( ) ,
90
93
'Volumes' : ( ) => coreApi . getPersistentVolumeList ( { labelSelector : 'io.codefresh.accountName' } ) ,
91
94
'Volumeclaims' : ( ) => coreApi . namespace ( namespace ) . getPersistentVolumeClaimList ( { labelSelector : 'io.codefresh.accountName' } ) ,
@@ -94,22 +97,30 @@ function dataFetchers(type, namespace) {
94
97
'Pods' : ( ) => coreApi . namespace ( namespace ) . getPodList ( ) ,
95
98
'Storageclass' : ( ) => storageApi . getStorageClassList ( ) ,
96
99
} ;
97
- case 'gitops ' :
100
+ case 'GitOps Runtime ' :
98
101
return {
99
- 'Apps' : ( ) => argoProj . namespace ( namespace ) . getApplicationList ( ) ,
100
- 'AppSets' : ( ) => argoProj . namespace ( namespace ) . getApplicationSetList ( ) ,
102
+ 'Argo-Apps' : ( ) => argoProj . namespace ( namespace ) . getApplicationList ( ) ,
103
+ 'Argo-AppSets' : ( ) => argoProj . namespace ( namespace ) . getApplicationSetList ( ) ,
104
+ 'Cron' : ( ) => batchApi . namespace ( namespace ) . getCronJobList ( ) ,
105
+ 'Jobs' : ( ) => batchApi . namespace ( namespace ) . getJobList ( ) ,
106
+ 'Deployments' : ( ) => appsApi . namespace ( namespace ) . getDeploymentList ( ) ,
107
+ 'Daemonsets' : ( ) => appsApi . namespace ( namespace ) . getDaemonSetList ( ) ,
108
+ 'Statefulsets' : ( ) => appsApi . namespace ( namespace ) . getStatefulSetList ( ) ,
101
109
'Nodes' : ( ) => coreApi . getNodeList ( ) ,
102
110
'Configmaps' : ( ) => coreApi . namespace ( namespace ) . getConfigMapList ( ) ,
103
111
'Services' : ( ) => coreApi . namespace ( namespace ) . getServiceList ( ) ,
104
112
'Pods' : ( ) => coreApi . namespace ( namespace ) . getPodList ( ) ,
105
113
} ;
106
- case 'onprem ' :
114
+ case 'On-Prem ' :
107
115
return {
116
+ 'Cron' : ( ) => batchApi . namespace ( namespace ) . getCronJobList ( ) ,
117
+ 'Jobs' : ( ) => batchApi . namespace ( namespace ) . getJobList ( ) ,
108
118
'Deployments' : ( ) => appsApi . namespace ( namespace ) . getDeploymentList ( ) ,
109
119
'Daemonsets' : ( ) => appsApi . namespace ( namespace ) . getDaemonSetList ( ) ,
110
120
'Nodes' : ( ) => coreApi . getNodeList ( ) ,
111
121
'Volumes' : ( ) => coreApi . getPersistentVolumeList ( { labelSelector : 'io.codefresh.accountName' } ) ,
112
122
'Volumeclaims' : ( ) => coreApi . namespace ( namespace ) . getPersistentVolumeClaimList ( { labelSelector : 'io.codefresh.accountName' } ) ,
123
+ 'Configmaps' : ( ) => coreApi . namespace ( namespace ) . getConfigMapList ( ) ,
113
124
'Services' : ( ) => coreApi . namespace ( namespace ) . getServiceList ( ) ,
114
125
'Pods' : ( ) => coreApi . namespace ( namespace ) . getPodList ( ) ,
115
126
'Storageclass' : ( ) => storageApi . getStorageClassList ( ) ,
@@ -128,18 +139,25 @@ async function fetchAndSaveData(type, namespace) {
128
139
129
140
if ( dir === 'Pods' ) {
130
141
await Promise . all ( resources . items . map ( async ( item ) => {
131
- let log ;
132
- try {
133
- log = await coreApi . namespace ( namespace ) . getPodLog ( item . metadata . name , {
134
- container : item . spec . containers [ 0 ] . name ,
135
- timestamps : true ,
136
- } ) ;
137
- } catch ( error ) {
138
- console . error ( `Failed to get items for ${ item . metadata . name } :` , error ) ;
139
- log = error ;
140
- }
141
- await Deno . writeTextFile ( `${ dirPath } /${ dir } /${ item . metadata . name } _log.log` , log ) ;
142
- await describeItems ( dir , namespace , item . metadata . name ) ;
142
+ const podName = item . metadata . name ;
143
+ const containers = item . spec . containers ;
144
+
145
+ await Promise . all ( containers . map ( async ( container ) => {
146
+ let log ;
147
+ try {
148
+ log = await coreApi . namespace ( namespace ) . getPodLog ( podName , {
149
+ container : container . name ,
150
+ timestamps : true ,
151
+ } ) ;
152
+ } catch ( error ) {
153
+ console . error ( `Failed to get logs for container ${ container . name } in pod ${ podName } :` , error ) ;
154
+ log = error . toString ( ) ;
155
+ }
156
+ const logFileName = `${ dirPath } /${ dir } /${ podName } _${ container . name } _log.log` ;
157
+ await Deno . writeTextFile ( logFileName , log ) ;
158
+ } ) ) ;
159
+
160
+ await describeItems ( dir , namespace , podName ) ;
143
161
} ) ) ;
144
162
}
145
163
@@ -156,7 +174,7 @@ async function fetchAndSaveData(type, namespace) {
156
174
await Deno . writeTextFile ( `${ dirPath } /ListPods.txt` , new TextDecoder ( ) . decode ( output . stdout ) ) ;
157
175
}
158
176
159
- async function gatherClassic ( ) {
177
+ async function gatherPipelines ( ) {
160
178
try {
161
179
const cf = new Codefresh ( ) ;
162
180
await cf . init ( ) ;
@@ -166,22 +184,22 @@ async function gatherClassic() {
166
184
console . log ( `${ index + 1 } . ${ re } ` ) ;
167
185
} ) ;
168
186
169
- let selection = Number ( prompt ( '\nWhich Classic Runtime Are We Working With? (Number): ' ) ) ;
187
+ let selection = Number ( prompt ( '\nWhich Pipelines Runtime Are We Working With? (Number): ' ) ) ;
170
188
while ( isNaN ( selection ) || selection < 1 || selection > reNames . length ) {
171
189
console . log ( 'Invalid selection. Please enter a number corresponding to one of the listed runtimes.' ) ;
172
- selection = Number ( prompt ( '\nWhich Classic Runtime Are We Working With? (Number): ' ) ) ;
190
+ selection = Number ( prompt ( '\nWhich Pipelines Runtime Are We Working With? (Number): ' ) ) ;
173
191
}
174
192
175
193
const reSpec = cf . runtimes [ selection - 1 ] ;
176
194
const namespace = reSpec . runtimeScheduler . cluster . namespace ;
177
195
178
196
console . log ( `\nGathering Data For ${ reSpec . metadata . name } .` ) ;
179
197
180
- await fetchAndSaveData ( 'classic ' , namespace ) ;
198
+ await fetchAndSaveData ( 'Pipelines Runtime ' , namespace ) ;
181
199
182
200
await Deno . writeTextFile ( `${ dirPath } /runtimeSpec.yaml` , toYaml ( reSpec , { skipInvalid : true } ) ) ;
183
201
} catch ( error ) {
184
- console . error ( `Error gathering classic runtime data:` , error ) ;
202
+ console . error ( `Error gathering Pipelines Runtime data:` , error ) ;
185
203
}
186
204
}
187
205
@@ -203,7 +221,7 @@ async function gatherGitOps() {
203
221
204
222
console . log ( `\nGathering Data In ${ namespace } For The GitOps Runtime.` ) ;
205
223
206
- await fetchAndSaveData ( 'gitops ' , namespace ) ;
224
+ await fetchAndSaveData ( 'GitOps Runtime ' , namespace ) ;
207
225
} catch ( error ) {
208
226
console . error ( `Error gathering GitOps runtime data:` , error ) ;
209
227
}
@@ -213,8 +231,14 @@ async function gatherOnPrem() {
213
231
try {
214
232
const cf = new Codefresh ( ) ;
215
233
await cf . init ( ) ;
234
+ if ( cf . apiURL === 'https://g.codefresh.io' ) {
235
+ console . error ( `The API URL ( ${ cf . apiURL } ) is not an On Prem instance. Please use Pipelines Runtime or GitOps Runtime.` ) ;
236
+ Deno . exit ( 1 ) ;
237
+ }
216
238
const accounts = await cf . getOnPremAccounts ( ) ;
217
239
const runtimes = await cf . getOnPremRuntimes ( ) ;
240
+ const userTotal = await cf . getOnPremUserTotal ( ) ;
241
+ const systemFF = await cf . getOnPremSystemFF ( ) ;
218
242
219
243
const namespaceList = await coreApi . getNamespaceList ( ) ;
220
244
console . log ( '' ) ;
@@ -232,10 +256,12 @@ async function gatherOnPrem() {
232
256
233
257
console . log ( `\nGathering Data For On Prem.` ) ;
234
258
235
- await fetchAndSaveData ( 'onprem ' , namespace ) ;
259
+ await fetchAndSaveData ( 'On-Prem ' , namespace ) ;
236
260
237
261
await Deno . writeTextFile ( `${ dirPath } /onPremAccounts.yaml` , toYaml ( accounts , { skipInvalid : true } ) ) ;
238
262
await Deno . writeTextFile ( `${ dirPath } /onPremRuntimes.yaml` , toYaml ( runtimes , { skipInvalid : true } ) ) ;
263
+ await Deno . writeTextFile ( `${ dirPath } /onPremUserTotal.txt` , userTotal . toString ( ) ) ;
264
+ await Deno . writeTextFile ( `${ dirPath } /onPremSystemFF.yaml` , toYaml ( systemFF , { skipInvalid : true } ) ) ;
239
265
} catch ( error ) {
240
266
console . error ( `Error gathering On Prem data:` , error ) ;
241
267
}
@@ -246,13 +272,13 @@ async function main() {
246
272
const runtimeType = selectRuntimeType ( ) ;
247
273
248
274
switch ( runtimeType ) {
249
- case 'classic ' :
250
- await gatherClassic ( ) ;
275
+ case 'Pipelines Runtime ' :
276
+ await gatherPipelines ( ) ;
251
277
break ;
252
- case 'gitops ' :
278
+ case 'GitOps Runtime ' :
253
279
await gatherGitOps ( ) ;
254
280
break ;
255
- case 'onprem ' :
281
+ case 'On-Prem ' :
256
282
await gatherOnPrem ( ) ;
257
283
break ;
258
284
}
@@ -266,7 +292,7 @@ async function main() {
266
292
console . log ( `\nPlease attach ./codefresh-support-package-${ timestamp } .zip to your support ticket.` ) ;
267
293
console . log ( 'Before attaching, verify the contents and remove any sensitive information.' ) ;
268
294
} catch ( error ) {
269
- console . error ( `Error in main function :` , error ) ;
295
+ console . error ( `Error:` , error ) ;
270
296
}
271
297
}
272
298
0 commit comments