Skip to content

Commit 1f9b6cc

Browse files
author
Luke Goodfellow
authored
Updated Outputs (#7)
Added the following outputs. Describe Nodes Describe Pods List of Pods Events
1 parent 535eadd commit 1f9b6cc

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

CONTRIBUTIONS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Pull requests are the best way to propose changes to the codebase. We actively w
2020

2121
## Any contributions you make will be under the MIT Software License
2222

23-
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
23+
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers
24+
the project. Feel free to contact the maintainers if that's a concern.
2425

2526
## Development
2627

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Codefresh Support Package
22

3-
This project is designed to gather data from Hybrid Runtimes for Codefresh SaaS platform, and Hybrid Runtimes and OnPrem isntallation on the OnPrem Platform. It collects information about various Kubernetes resources such as Pods, Nodes, Configmaps, Services, and Events. For Classic and OnPrem we gather some informtion from the platform itself.
3+
This project is designed to gather data from Hybrid Runtimes for Codefresh SaaS platform, and Hybrid Runtimes and OnPrem isntallation on the OnPrem Platform. It
4+
collects information about various Kubernetes resources such as Pods, Nodes, Configmaps, Services, and Events. For Classic and OnPrem we gather some informtion
5+
from the platform itself.
46

57
## Prereqs
68

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.0
1+
2.3.0

src/main.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,48 @@ function selectRuntimeType() {
3838
async function saveItems(resources, dir) {
3939
try {
4040
await Deno.mkdir(`${dirPath}/${dir}/`, { recursive: true });
41-
4241
const writePromises = resources.map(async (item) => {
43-
const filePath = `${dirPath}/${dir}/${item.metadata.name}.yaml`;
42+
const filePath = `${dirPath}/${dir}/${item.metadata.name}_get.yaml`;
4443
const fileContent = toYaml(item, { skipInvalid: true });
4544
await Deno.writeTextFile(filePath, fileContent);
4645
});
47-
4846
await Promise.all(writePromises);
4947
} catch (error) {
5048
console.error(`Error saving items to ${dir}:`, error);
5149
}
5250
}
5351

52+
async function describeItems(dir, namespace, name) {
53+
try {
54+
const describe = new Deno.Command('kubectl', { args: ['describe', dir.toLowerCase(), '-n', namespace, name] });
55+
const output = await describe.output();
56+
await Deno.writeTextFile(`${dirPath}/${dir}/${name}_describe.yaml`, new TextDecoder().decode(output.stdout));
57+
} catch (error) {
58+
console.error(`Failed to describe ${name}:`, error);
59+
}
60+
}
61+
62+
async function saveEvents(namespace) {
63+
try {
64+
const events = new Deno.Command('kubectl', { args: ['get', 'events', '-n', namespace, '--sort-by=.metadata.creationTimestamp'] });
65+
const output = await events.output();
66+
await Deno.writeTextFile(`${dirPath}/Events.txt`, new TextDecoder().decode(output.stdout));
67+
} catch (error) {
68+
console.error(`Error saving events:`, error);
69+
}
70+
}
71+
5472
async function saveHelmReleases(type, namespace) {
5573
try {
5674
const helmList = new Deno.Command('helm', { args: ['list', '-n', namespace, '-o', 'json'] });
5775
const output = await helmList.output();
5876
const helmReleases = JSON.parse(new TextDecoder().decode(output.stdout));
59-
await Deno.writeTextFile(`${dirPath}/${type}-helmReleases.yaml`, toYaml(helmReleases, { skipInvalid: true }));
77+
await Deno.writeTextFile(`${dirPath}/${type}_helmReleases.yaml`, toYaml(helmReleases, { skipInvalid: true }));
6078
} catch (error) {
6179
console.error(`Error saving Helm releases for ${type}:`, error);
6280
}
6381
}
6482

65-
6683
function dataFetchers(type, namespace) {
6784
switch (type) {
6885
case 'classic':
@@ -75,7 +92,6 @@ function dataFetchers(type, namespace) {
7592
'Configmaps': () => coreApi.namespace(namespace).getConfigMapList({ labelSelector: 'app.kubernetes.io/name=cf-runtime' }),
7693
'Services': () => coreApi.namespace(namespace).getServiceList(),
7794
'Pods': () => coreApi.namespace(namespace).getPodList(),
78-
'Events': () => coreApi.namespace(namespace).getEventList(),
7995
'Storageclass': () => storageApi.getStorageClassList(),
8096
};
8197
case 'gitops':
@@ -85,7 +101,6 @@ function dataFetchers(type, namespace) {
85101
'Configmaps': () => coreApi.namespace(namespace).getConfigMapList(),
86102
'Services': () => coreApi.namespace(namespace).getServiceList(),
87103
'Pods': () => coreApi.namespace(namespace).getPodList(),
88-
'Events': () => coreApi.namespace(namespace).getEventList(),
89104
};
90105
case 'onprem':
91106
return {
@@ -96,7 +111,6 @@ function dataFetchers(type, namespace) {
96111
'Volumeclaims': () => coreApi.namespace(namespace).getPersistentVolumeClaimList({ labelSelector: 'io.codefresh.accountName' }),
97112
'Services': () => coreApi.namespace(namespace).getServiceList(),
98113
'Pods': () => coreApi.namespace(namespace).getPodList(),
99-
'Events': () => coreApi.namespace(namespace).getEventList(),
100114
'Storageclass': () => storageApi.getStorageClassList(),
101115
};
102116
default:
@@ -108,6 +122,7 @@ function dataFetchers(type, namespace) {
108122
async function fetchAndSaveData(type, namespace) {
109123
for (const [dir, fetcher] of Object.entries(dataFetchers(type, namespace))) {
110124
const resources = await fetcher();
125+
111126
await saveItems(resources.items, dir);
112127

113128
if (dir === 'Pods') {
@@ -116,14 +131,25 @@ async function fetchAndSaveData(type, namespace) {
116131
try {
117132
log = await coreApi.namespace(namespace).getPodLog(item.metadata.name, { container: item.spec.containers[0].name });
118133
} catch (error) {
119-
console.error(`Failed to get logs for ${item.metadata.name}:`, error);
134+
console.error(`Failed to get items for ${item.metadata.name}:`, error);
120135
log = error;
121136
}
122-
await Deno.writeTextFile(`${dirPath}/${dir}/${item.metadata.name}.log`, log);
137+
await Deno.writeTextFile(`${dirPath}/${dir}/${item.metadata.name}_log.log`, log);
138+
await describeItems(dir, namespace, item.metadata.name);
139+
}));
140+
}
141+
142+
if (dir === 'Nodes') {
143+
await Promise.all(resources.items.map(async (item) => {
144+
await describeItems(dir, namespace, item.metadata.name);
123145
}));
124146
}
125147
}
126148
await saveHelmReleases(type, namespace);
149+
await saveEvents(namespace);
150+
const listPods = new Deno.Command('kubectl', { args: ['get', 'pods', '-n', namespace] });
151+
const output = await listPods.output();
152+
await Deno.writeTextFile(`${dirPath}/ListPods.txt`, new TextDecoder().decode(output.stdout));
127153
}
128154

129155
async function gatherClassic() {

0 commit comments

Comments
 (0)