pulumi-extra-crds 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/generate.yml +66 -0
- package/generate-crds.js +114 -0
- package/package.json +17 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
name: Generate CRDs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch: # manual trigger
|
|
5
|
+
schedule:
|
|
6
|
+
- cron: "0 3 * * 1" # run weekly
|
|
7
|
+
push:
|
|
8
|
+
branches: [ main ]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
generate-crds:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout repo
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Setup Node.js
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: '20'
|
|
22
|
+
|
|
23
|
+
- name: Install TypeScript
|
|
24
|
+
run: npm install -g typescript
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: npm install
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
- name: Fetch latest Gateway API release
|
|
31
|
+
run: |
|
|
32
|
+
GW_VERSION=$(curl -s https://api.github.com/repos/kubernetes-sigs/gateway-api/releases/latest | jq -r .tag_name)
|
|
33
|
+
echo "GW_VERSION=$GW_VERSION" >> $GITHUB_ENV
|
|
34
|
+
|
|
35
|
+
- name: Fetch latest Cert-Manager release
|
|
36
|
+
run: |
|
|
37
|
+
CM_VERSION=$(curl -s https://api.github.com/repos/cert-manager/cert-manager/releases/latest | jq -r .tag_name)
|
|
38
|
+
echo "CM_VERSION=$CM_VERSION" >> $GITHUB_ENV
|
|
39
|
+
|
|
40
|
+
- name: Download crd2pulumi binary
|
|
41
|
+
run: |
|
|
42
|
+
CRD2PULUMI_VERSION=1.6.0
|
|
43
|
+
curl -L "https://github.com/pulumi/crd2pulumi/releases/download/v${CRD2PULUMI_VERSION}/crd2pulumi-v${CRD2PULUMI_VERSION}-linux-amd64.tar.gz" -o crd2pulumi.tar.gz
|
|
44
|
+
tar -xzf crd2pulumi.tar.gz
|
|
45
|
+
chmod +x crd2pulumi
|
|
46
|
+
sudo mv crd2pulumi /usr/local/bin/crd2pulumi
|
|
47
|
+
crd2pulumi version
|
|
48
|
+
|
|
49
|
+
- name: Run CRD generation script
|
|
50
|
+
run: node generate-crds.js
|
|
51
|
+
|
|
52
|
+
- name: Commit changes
|
|
53
|
+
run: |
|
|
54
|
+
git config --global user.name "github-actions[bot]"
|
|
55
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
56
|
+
git add generated/crds .crd2pulumi-checksum
|
|
57
|
+
git commit -m "Update CRDs" || echo "No changes to commit"
|
|
58
|
+
git push
|
|
59
|
+
env:
|
|
60
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
61
|
+
|
|
62
|
+
- name: Publish to npm
|
|
63
|
+
if: github.ref == 'refs/heads/main'
|
|
64
|
+
run: npm publish
|
|
65
|
+
env:
|
|
66
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/generate-crds.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const PROJECT_ROOT = process.cwd();
|
|
8
|
+
|
|
9
|
+
const OUTPUT_DIR = path.join(PROJECT_ROOT, 'generated/crds');
|
|
10
|
+
const TEMP_DIR = path.join(PROJECT_ROOT, 'temp_crds');
|
|
11
|
+
const CHECKSUM_FILE = path.join(PROJECT_ROOT, '.crd2pulumi-checksum');
|
|
12
|
+
|
|
13
|
+
const GW_VERSION = process.env.GW_VERSION || 'v1.1.0';
|
|
14
|
+
const GW_URL = `https://github.com/kubernetes-sigs/gateway-api/releases/download/${GW_VERSION}/experimental-install.yaml`;
|
|
15
|
+
const GW_FILE = 'gateway-api.yaml';
|
|
16
|
+
|
|
17
|
+
const CM_VERSION = process.env.CM_VERSION || 'v1.15.0';
|
|
18
|
+
const CM_URL = `https://github.com/cert-manager/cert-manager/releases/download/${CM_VERSION}/cert-manager.crds.yaml`;
|
|
19
|
+
const CM_FILE = 'cert-manager.yaml';
|
|
20
|
+
|
|
21
|
+
const downloadFile = (url, filename) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const destPath = path.join(TEMP_DIR, filename);
|
|
24
|
+
const file = fs.createWriteStream(destPath);
|
|
25
|
+
|
|
26
|
+
const request = (uri) => {
|
|
27
|
+
https.get(uri, (response) => {
|
|
28
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
29
|
+
return request(response.headers.location);
|
|
30
|
+
}
|
|
31
|
+
if (response.statusCode !== 200) {
|
|
32
|
+
reject(new Error(`Failed to download ${uri}: ${response.statusCode}`));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(`Downloading ${filename}...`);
|
|
36
|
+
response.pipe(file);
|
|
37
|
+
file.on('finish', () => {
|
|
38
|
+
file.close();
|
|
39
|
+
resolve(destPath);
|
|
40
|
+
});
|
|
41
|
+
}).on('error', (err) => {
|
|
42
|
+
fs.unlink(destPath, () => {});
|
|
43
|
+
reject(err);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
request(url);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const computeHash = (filePaths) => {
|
|
51
|
+
const hash = crypto.createHash('sha256');
|
|
52
|
+
filePaths.sort().forEach(fp => hash.update(fs.readFileSync(fp)));
|
|
53
|
+
return hash.digest('hex');
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
async function main() {
|
|
57
|
+
if (fs.existsSync(TEMP_DIR)) fs.rmSync(TEMP_DIR, { recursive: true, force: true });
|
|
58
|
+
fs.mkdirSync(TEMP_DIR);
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const gwPath = await downloadFile(GW_URL, GW_FILE);
|
|
62
|
+
const cmPath = await downloadFile(CM_URL, CM_FILE);
|
|
63
|
+
const allFiles = [gwPath, cmPath];
|
|
64
|
+
const newHash = computeHash(allFiles);
|
|
65
|
+
|
|
66
|
+
let oldHash = null;
|
|
67
|
+
if (fs.existsSync(CHECKSUM_FILE)) {
|
|
68
|
+
oldHash = fs.readFileSync(CHECKSUM_FILE, 'utf8').trim();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (oldHash === newHash && fs.existsSync(OUTPUT_DIR)) {
|
|
72
|
+
console.log('CRDs unchanged. Skipping.');
|
|
73
|
+
} else {
|
|
74
|
+
console.log('Regenerating CRDs...');
|
|
75
|
+
if (fs.existsSync(OUTPUT_DIR)) fs.rmSync(OUTPUT_DIR, { recursive: true, force: true });
|
|
76
|
+
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
|
77
|
+
execSync(`crd2pulumi --nodejsPath "${OUTPUT_DIR}" --force "${gwPath}" "${cmPath}"`, { stdio: 'inherit' });
|
|
78
|
+
|
|
79
|
+
const pkgPath = path.join(OUTPUT_DIR, 'package.json');
|
|
80
|
+
if (fs.existsSync(pkgPath)) {
|
|
81
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
82
|
+
if (pkg.scripts) delete pkg.scripts;
|
|
83
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const tsconfig = {
|
|
87
|
+
compilerOptions: {
|
|
88
|
+
target: "es2020",
|
|
89
|
+
module: "commonjs",
|
|
90
|
+
moduleResolution: "node",
|
|
91
|
+
declaration: true,
|
|
92
|
+
skipLibCheck: true,
|
|
93
|
+
},
|
|
94
|
+
include: ["**/*.ts"],
|
|
95
|
+
exclude: ["node_modules"]
|
|
96
|
+
};
|
|
97
|
+
fs.writeFileSync(path.join(OUTPUT_DIR, 'tsconfig.json'), JSON.stringify(tsconfig, null, 2));
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
execSync('npx tsc', { cwd: OUTPUT_DIR, stdio: 'inherit' });
|
|
101
|
+
} catch (e) { console.warn("TSC warnings ignored."); }
|
|
102
|
+
|
|
103
|
+
fs.writeFileSync(CHECKSUM_FILE, newHash);
|
|
104
|
+
console.log(`Success!`);
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(error);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
} finally {
|
|
110
|
+
if (fs.existsSync(TEMP_DIR)) fs.rmSync(TEMP_DIR, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pulumi-extra-crds",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"generate": "node scripts/generate-crds.js",
|
|
7
|
+
"build": "tsc -p tsconfig.json"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@pulumi/kubernetes": "^4.23.0",
|
|
11
|
+
"@pulumi/pulumi": "^3.113.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.0.0",
|
|
15
|
+
"@types/node": "^20.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["generated/**/*.ts", "**/*.ts"],
|
|
11
|
+
"exclude": ["node_modules"]
|
|
12
|
+
}
|