Skip to content

Commit c7c823f

Browse files
authored
Support Package Version 7.0.0 (#42)
- fixes #43 - fixes #44 - Added logging - Convert to Typescript - Prefer kube config for authentication - added version to output
1 parent 0a68ad4 commit c7c823f

File tree

23 files changed

+706
-463
lines changed

23 files changed

+706
-463
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- name: Compile and package binaries
2222
run: |
23-
sed -i "s/__APP_VERSION__/$TAG_NAME/g" main.js
23+
sed -i "s/__APP_VERSION__/$TAG_NAME/g" ./src/main.ts
2424
deno task compile
2525
deno task package
2626
env:

deno.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
},
1313
"tasks": {
1414
"pre-compile": "rm -rf ./bin && mkdir ./bin",
15-
"compile:linux_amd64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_linux_amd64 --target=x86_64-unknown-linux-gnu ./main.js",
16-
"compile:linux_arm64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_linux_arm64 --target=aarch64-unknown-linux-gnu ./main.js",
17-
"compile:apple_amd64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_amd64 --target=x86_64-apple-darwin ./main.js",
18-
"compile:apple_arm64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_arm64 --target=aarch64-apple-darwin ./main.js",
19-
"compile:windows": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_windows_amd64 --target=x86_64-pc-windows-msvc ./main.js",
15+
"compile:linux_amd64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_linux_amd64 --target=x86_64-unknown-linux-gnu ./src/main.ts",
16+
"compile:linux_arm64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_linux_arm64 --target=aarch64-unknown-linux-gnu ./src/main.ts",
17+
"compile:apple_amd64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_amd64 --target=x86_64-apple-darwin ./src/main.ts",
18+
"compile:apple_arm64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_arm64 --target=aarch64-apple-darwin ./src/main.ts",
19+
"compile:windows": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_windows_amd64 --target=x86_64-pc-windows-msvc ./src/main.ts",
2020
"compile": "deno task pre-compile && deno task compile:linux_amd64 && deno task compile:linux_arm64 && deno task compile:windows && deno task compile:apple_amd64 && deno task compile:apple_arm64",
2121
"package": "cd bin && tar -czvf ./cf-support_linux_amd64.tar.gz cf-support_linux_amd64 && tar -czvf ./cf-support_linux_arm64.tar.gz ./cf-support_linux_arm64 && tar -czvf ./cf-support_darwin_amd64.tar.gz ./cf-support_darwin_amd64 && tar -czvf ./cf-support_darwin_arm64.tar.gz ./cf-support_darwin_arm64 && zip ./cf-support_windows_amd64.zip ./cf-support_windows_amd64.exe"
2222
},
2323
"imports": {
2424
"@cliffy/command": "jsr:@cliffy/[email protected]",
2525
"@cloudydeno/kubernetes-apis": "jsr:@cloudydeno/[email protected]",
2626
"@cloudydeno/kubernetes-client": "jsr:@cloudydeno/[email protected]",
27+
"@deno-lib/logger": "jsr:@deno-lib/logger@^1.1.9",
28+
"@deno-library/logger": "jsr:@deno-library/logger@^1.2.0",
2729
"@henrygd/semaphore": "jsr:@henrygd/semaphore@^0.0.2",
2830
"@std/yaml": "jsr:@std/[email protected]"
2931
}

deno.lock

Lines changed: 51 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/gitops.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DIR_PATH, logger, Utils } from '../utils/mod.ts';
2+
import { K8s } from '../logic/mod.ts';
3+
4+
export async function gitopsCMD(namespace?: string) {
5+
logger.info(`Starting GitOps data collection...`);
6+
const k8s = new K8s();
7+
const utils = new Utils();
8+
if (!namespace) {
9+
logger.info('No namespace provided, prompting user to select one.');
10+
const selected = await k8s.selectNamespace();
11+
namespace = selected;
12+
}
13+
14+
console.log(`Gathering data in the '${namespace}' namespace for the GitOps Runtime`);
15+
logger.info(`Gathering data in the '${namespace}' namespace for the GitOps Runtime`);
16+
const k8sResources = k8s.getResources(namespace);
17+
await utils.processData(DIR_PATH, k8sResources);
18+
await utils.preparePackage(DIR_PATH, 'gitops');
19+
}

src/commands/mod.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { gitopsCMD } from './gitops.ts';
2+
import { pipelinesCMD } from './pipelines.ts';
3+
import { onpremCMD } from './onprem.ts';
4+
import { ossCMD } from './oss.ts';
5+
6+
export { gitopsCMD, onpremCMD, ossCMD, pipelinesCMD };

src/commands/onprem.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { DIR_PATH, logger, Utils } from '../utils/mod.ts';
2+
import { Codefresh, K8s } from '../logic/mod.ts';
3+
4+
export async function onpremCMD(namespace?: string) {
5+
logger.info('Starting OnPrem data collection...');
6+
const cf = new Codefresh();
7+
const k8s = new K8s();
8+
const utils = new Utils();
9+
10+
const cfCreds = cf.getCredentials();
11+
12+
if (cfCreds && cfCreds.baseUrl === 'https://g.codefresh.io/api') {
13+
console.error(
14+
'Cannot gather On-Prem data for Codefresh SaaS. If you need to gather data for Codefresh On-Prem, please update your ./cfconfig context (or Envs) to point to an On-Prem instance.',
15+
);
16+
logger.error(
17+
'Cannot gather On-Prem data for Codefresh SaaS. If you need to gather data for Codefresh On-Prem, please update your ./cfconfig context (or Envs) to point to an On-Prem instance.',
18+
);
19+
console.error('For Codefresh SaaS, use "pipelines" or "gitops" commands.');
20+
logger.error('For Codefresh SaaS, use "pipelines" or "gitops" commands.');
21+
return;
22+
}
23+
24+
if (!namespace) {
25+
logger.info('No namespace provided, prompting user to select one.');
26+
const selected = await k8s.selectNamespace();
27+
namespace = selected;
28+
}
29+
30+
if (cfCreds) {
31+
logger.info('Gathering OnPrem system data...');
32+
const dataFetchers = [
33+
{ name: 'OnPrem_Accounts', fetcher: cf.getSystemAccounts },
34+
{ name: 'OnPrem_Runtimes', fetcher: cf.getSystemRuntimes },
35+
{ name: 'OnPrem_Feature_Flags', fetcher: cf.getSystemFeatureFlags },
36+
{ name: 'OnPrem_Total_Users', fetcher: cf.getSystemTotalUsers },
37+
];
38+
39+
for (const { name, fetcher } of dataFetchers) {
40+
try {
41+
logger.info(`Fetching and writing ${name}...`);
42+
const data = await fetcher(cfCreds);
43+
await utils.writeYaml(data, name, DIR_PATH);
44+
} catch (error) {
45+
console.error(`Failed to fetch or write ${name}:\n${error}`);
46+
logger.error(`Failed to fetch or write ${name}:\n${error}`);
47+
}
48+
}
49+
}
50+
51+
console.log(`Gathering data in the '${namespace}' namespace for Codefresh OnPrem`);
52+
logger.info(`Gathering data in the '${namespace}' namespace for Codefresh OnPrem`);
53+
const k8sResources = k8s.getResources(namespace);
54+
await utils.processData(DIR_PATH, k8sResources);
55+
await utils.preparePackage(DIR_PATH, 'onprem');
56+
}

src/commands/oss.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { DIR_PATH, logger, Utils } from '../utils/mod.ts';
2+
import { K8s } from '../logic/mod.ts';
3+
4+
export async function ossCMD(namespace?: string) {
5+
logger.info(`Starting OSS data collection...`);
6+
const k8s = new K8s();
7+
const utils = new Utils();
8+
9+
if (!namespace) {
10+
logger.info('No namespace provided, prompting user to select one.');
11+
const selected = await k8s.selectNamespace();
12+
namespace = selected;
13+
}
14+
15+
console.log(`Gathering data in the '${namespace}' namespace for OSS Argo`);
16+
logger.info(`Gathering data in the '${namespace}' namespace for OSS Argo`);
17+
const k8sResources = k8s.getResources(namespace);
18+
await utils.processData(DIR_PATH, k8sResources);
19+
await utils.preparePackage(DIR_PATH, 'oss');
20+
}

src/commands/pipelines.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { DIR_PATH, logger, Utils } from '../utils/mod.ts';
2+
import { Codefresh, K8s } from '../logic/mod.ts';
3+
4+
export async function pipelinesCMD(namespace?: string, runtime?: string) {
5+
logger.info(`Starting Pipelines data collection...`);
6+
const cf = new Codefresh();
7+
const k8s = new K8s();
8+
const utils = new Utils();
9+
const cfCreds = cf.getCredentials();
10+
11+
if (!namespace) {
12+
logger.info('No namespace provided, prompting user to select one.');
13+
const selected = await k8s.selectNamespace();
14+
namespace = selected;
15+
}
16+
17+
if (cfCreds) {
18+
if (!runtime) {
19+
logger.info('No runtime provided, prompting user to select one.');
20+
const runtimes = await cf.getAccountRuntimes(cfCreds);
21+
22+
if (runtimes.length !== 0) {
23+
runtimes.forEach((re: any, index: number) => {
24+
console.log(`${index + 1}. ${re.metadata.name}`);
25+
logger.info(`${index + 1}. ${re.metadata.name}`);
26+
});
27+
let selection;
28+
do {
29+
selection = Number(prompt('\nWhich Pipelines Runtime Are We Working With? (Number): '));
30+
logger.info(`User selected runtime option: ${selection}`);
31+
if (isNaN(selection) || selection < 1 || selection > runtimes.length) {
32+
console.warn(
33+
'Invalid selection. Please enter a number corresponding to one of the listed runtimes.',
34+
);
35+
logger.warn(
36+
'Invalid selection. Please enter a number corresponding to one of the listed runtimes.',
37+
);
38+
}
39+
} while (isNaN(selection) || selection < 1 || selection > runtimes.length);
40+
41+
const reSpec = runtimes[selection - 1];
42+
logger.info(`User selected runtime: ${reSpec.metadata.name}`);
43+
await utils.writeYaml(reSpec, 'Runtime_Spec', DIR_PATH);
44+
logger.info(`Runtime Spec written for ${reSpec.metadata.name}`);
45+
}
46+
} else {
47+
logger.info(`Runtime provided (${runtime}), fetching spec...`);
48+
const reSpec = await cf.getAccountRuntimeSpec(cfCreds, runtime);
49+
await utils.writeYaml(reSpec, 'Runtime_Spec', DIR_PATH);
50+
logger.info(`Runtime Spec written for ${runtime}`);
51+
}
52+
}
53+
54+
console.log(`Gathering data in the '${namespace}' namespace for Pipelines Runtime`);
55+
logger.info(`Gathering data in the '${namespace}' namespace for Pipelines Runtime`);
56+
const k8sResources = k8s.getResources(namespace);
57+
await utils.processData(DIR_PATH, k8sResources);
58+
await utils.preparePackage(DIR_PATH, 'pipelines');
59+
}

src/gitops.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)