diff --git a/.github/workflows/fetch-acceptance-tests.yml b/.github/workflows/fetch-acceptance-tests.yml index f259db41df..fed164fc56 100644 --- a/.github/workflows/fetch-acceptance-tests.yml +++ b/.github/workflows/fetch-acceptance-tests.yml @@ -34,10 +34,9 @@ jobs: node-version: '18' - name: Install dependencies run: | - cd ./redpanda-docs/scripts/fetch-from-github npm install - name: Run the script and save the output - run: node ./redpanda-docs/scripts/fetch-from-github/fetch.js redpanda-data redpanda-operator acceptance/features ../../modules/manage/examples/kubernetes + run: npx doc-tools fetch -o redpanda-data -r redpanda-operator -p acceptance/features -d ../../modules/manage/examples/kubernetes env: VBOT_GITHUB_API_TOKEN: ${{ env.ACTIONS_BOT_TOKEN }} - name: Create pull request diff --git a/.github/workflows/generate-crd.yml b/.github/workflows/generate-crd.yml index 640b04e799..649b23ea75 100644 --- a/.github/workflows/generate-crd.yml +++ b/.github/workflows/generate-crd.yml @@ -148,9 +148,9 @@ jobs: # Convert the generated Markdown Helm documentation to AsciiDoc format using pandoc. - name: Convert Markdown to AsciiDoc run: | - pandoc ./helm-charts/charts/redpanda/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc - pandoc ./helm-charts/charts/console/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc - pandoc ./helm-charts/charts/operator/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc + pandoc ./redpanda/charts/redpanda/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc + pandoc ./redpanda/charts/console/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc + pandoc ./redpanda/operator/chart/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc - name: Modify third-level headings format run: | sed -i 's/\(\[[0-9]*\)\]\./\1\\]\./g' ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc diff --git a/.github/workflows/get-cloud-api-spec.yml b/.github/workflows/get-cloud-api-spec.yml index cd33fe153b..2eb8658577 100644 --- a/.github/workflows/get-cloud-api-spec.yml +++ b/.github/workflows/get-cloud-api-spec.yml @@ -44,14 +44,12 @@ jobs: - name: Install dependencies run: | - cd ./redpanda-docs/scripts/fetch-from-github npm install - name: Run the script and save the output run: | - cd ./redpanda-docs/scripts/fetch-from-github - node fetch.js redpanda-data cloudv2 proto/gen/openapi/openapi.controlplane.prod.yaml ../../modules/ROOT/attachments cloud-controlplane-api.yaml - node fetch.js redpanda-data cloudv2 proto/gen/openapi/openapi.dataplane.prod.yaml ../../modules/ROOT/attachments cloud-dataplane-api.yaml + npx doc-tools fetch -o redpanda-data -r cloudv2 -p proto/gen/openapi/openapi.controlplane.prod.yaml -d ../../modules/ROOT/attachments cloud-controlplane-api.yaml + npx doc-tools fetch -o redpanda-data -r cloudv2 -p proto/gen/openapi/openapi.dataplane.prod.yaml -d ../../modules/ROOT/attachments cloud-dataplane-api.yaml env: VBOT_GITHUB_API_TOKEN: ${{ env.ACTIONS_BOT_TOKEN }} - name: Create pull request diff --git a/modules/console/images/degraded-cluster.png b/modules/console/images/degraded-cluster.png index e74d0d8c24..64f3203542 100644 Binary files a/modules/console/images/degraded-cluster.png and b/modules/console/images/degraded-cluster.png differ diff --git a/modules/console/images/overview.png b/modules/console/images/overview.png index 0ef2ebcda6..018503a397 100644 Binary files a/modules/console/images/overview.png and b/modules/console/images/overview.png differ diff --git a/package-lock.json b/package-lock.json index 6c572cb5d5..a043e96a08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,9 +16,6 @@ "@sntke/antora-mermaid-extension": "^0.0.6" }, "devDependencies": { - "@octokit/core": "^6.1.2", - "@octokit/plugin-retry": "^7.1.1", - "@octokit/rest": "^21.0.1", "@web/dev-server": "^0.2.1", "cross-env": "^7.0.3", "doc-detective": "^2.17.0", diff --git a/package.json b/package.json index 49dc7e3ac8..33140ea440 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,6 @@ "@sntke/antora-mermaid-extension": "^0.0.6" }, "devDependencies": { - "@octokit/core": "^6.1.2", - "@octokit/plugin-retry": "^7.1.1", - "@octokit/rest": "^21.0.1", "@web/dev-server": "^0.2.1", "cross-env": "^7.0.3", "doc-detective": "^2.17.0", diff --git a/scripts/fetch-from-github/fetch.js b/scripts/fetch-from-github/fetch.js deleted file mode 100644 index 15a83862c4..0000000000 --- a/scripts/fetch-from-github/fetch.js +++ /dev/null @@ -1,103 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -// Function to load Octokit once -let octokitInstance = null; - -async function loadOctokit() { - if (!octokitInstance) { - const { Octokit } = await import('@octokit/rest'); - octokitInstance = process.env.VBOT_GITHUB_API_TOKEN - ? new Octokit({ - auth: process.env.VBOT_GITHUB_API_TOKEN, - }) - : new Octokit(); - } - return octokitInstance; -} - -function logMessage(message, level = 'log') { - if (level === 'error') { - console.error(message); - } else { - console.log(message); - } -} - -const args = process.argv.slice(2); - -function printHelp() { - logMessage(` -Usage: node script.js [custom-filename] - -Arguments: - The GitHub repository owner or organization. - The GitHub repository name. - The file or directory path within the repository to fetch. - The local directory where files will be saved. - [custom-filename] Optional. If provided, the fetched file will be saved with this name. - -Options: - -h, --help Show this help message. - -Example: - node fetch.js redpanda-data cloudv2 proto/gen/openapi/openapi.prod.yaml ./modules/ROOT/attachments cloud-api.yaml - -Note: Ensure that you have set the 'VBOT_GITHUB_API_TOKEN' environment variable for authentication. - `); -} - -if (args.includes('--help') || args.includes('-h')) { - printHelp(); - process.exit(0); -} - -if (args.length < 4) { - logMessage('Error: Missing arguments.', 'error'); - printHelp(); - process.exit(1); -} - -const [owner, repo, filePath, saveDir, customFilename] = args; - -// Create the save directory if it doesn't exist -if (!fs.existsSync(saveDir)) { - fs.mkdirSync(saveDir, { recursive: true }); -} - -async function saveFile(content, filename) { - const filePath = path.join(saveDir, filename); - fs.writeFileSync(filePath, content); - logMessage(`Saved: ${filePath}`); -} - -async function fetchFile(owner, repo, filePath) { - const octokit = await loadOctokit(); - try { - const response = await octokit.repos.getContent({ - owner, - repo, - path: filePath, - }); - - if (Array.isArray(response.data)) { - // Path is a directory, fetch each file in the directory - for (const file of response.data) { - if (file.type === 'file') { - await fetchFile(owner, repo, file.path); - } - } - } else { - // Path is a file, save its content - const content = Buffer.from(response.data.content, 'base64').toString(); - // Use custom filename if provided, else use the default one from the repo - const filename = customFilename || path.basename(response.data.path); - await saveFile(content, filename); - } - } catch (error) { - logMessage('Error fetching file or directory: ' + error.message, 'error'); - process.exit(1); - } -} - -fetchFile(owner, repo, filePath); diff --git a/scripts/fetch-from-github/package-lock.json b/scripts/fetch-from-github/package-lock.json deleted file mode 100644 index 23e5c1a947..0000000000 --- a/scripts/fetch-from-github/package-lock.json +++ /dev/null @@ -1,238 +0,0 @@ -{ - "name": "get-api-specs", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "get-api-specs", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "@octokit/plugin-retry": "^6.0.1", - "@octokit/rest": "^20.0.2", - "chalk": "^5.3.0", - "js-yaml": "^4.1.0" - } - }, - "node_modules/@octokit/auth-token": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", - "integrity": "sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==", - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/core": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.0.2.tgz", - "integrity": "sha512-cZUy1gUvd4vttMic7C0lwPed8IYXWYp8kHIMatyhY8t8n3Cpw2ILczkV5pGMPqef7v0bLo0pOHrEHarsau2Ydg==", - "dependencies": { - "@octokit/auth-token": "^4.0.0", - "@octokit/graphql": "^7.0.0", - "@octokit/request": "^8.0.2", - "@octokit/request-error": "^5.0.0", - "@octokit/types": "^12.0.0", - "before-after-hook": "^2.2.0", - "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/endpoint": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.4.tgz", - "integrity": "sha512-DWPLtr1Kz3tv8L0UvXTDP1fNwM0S+z6EJpRcvH66orY6Eld4XBMCSYsaWp4xIm61jTWxK68BrR7ibO+vSDnZqw==", - "dependencies": { - "@octokit/types": "^12.0.0", - "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/graphql": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.0.2.tgz", - "integrity": "sha512-OJ2iGMtj5Tg3s6RaXH22cJcxXRi7Y3EBqbHTBRq+PQAqfaS8f/236fUrWhfSn8P4jovyzqucxme7/vWSSZBX2Q==", - "dependencies": { - "@octokit/request": "^8.0.1", - "@octokit/types": "^12.0.0", - "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/openapi-types": { - "version": "19.1.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-19.1.0.tgz", - "integrity": "sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==" - }, - "node_modules/@octokit/plugin-paginate-rest": { - "version": "9.1.5", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.1.5.tgz", - "integrity": "sha512-WKTQXxK+bu49qzwv4qKbMMRXej1DU2gq017euWyKVudA6MldaSSQuxtz+vGbhxV4CjxpUxjZu6rM2wfc1FiWVg==", - "dependencies": { - "@octokit/types": "^12.4.0" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=5" - } - }, - "node_modules/@octokit/plugin-request-log": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-4.0.0.tgz", - "integrity": "sha512-2uJI1COtYCq8Z4yNSnM231TgH50bRkheQ9+aH8TnZanB6QilOnx8RMD2qsnamSOXtDj0ilxvevf5fGsBhBBzKA==", - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=5" - } - }, - "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.2.0.tgz", - "integrity": "sha512-ePbgBMYtGoRNXDyKGvr9cyHjQ163PbwD0y1MkDJCpkO2YH4OeXX40c4wYHKikHGZcpGPbcRLuy0unPUuafco8Q==", - "dependencies": { - "@octokit/types": "^12.3.0" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=5" - } - }, - "node_modules/@octokit/plugin-retry": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-6.0.1.tgz", - "integrity": "sha512-SKs+Tz9oj0g4p28qkZwl/topGcb0k0qPNX/i7vBKmDsjoeqnVfFUquqrE/O9oJY7+oLzdCtkiWSXLpLjvl6uog==", - "dependencies": { - "@octokit/request-error": "^5.0.0", - "@octokit/types": "^12.0.0", - "bottleneck": "^2.15.3" - }, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": ">=5" - } - }, - "node_modules/@octokit/request": { - "version": "8.1.6", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.6.tgz", - "integrity": "sha512-YhPaGml3ncZC1NfXpP3WZ7iliL1ap6tLkAp6MvbK2fTTPytzVUyUesBBogcdMm86uRYO5rHaM1xIWxigWZ17MQ==", - "dependencies": { - "@octokit/endpoint": "^9.0.0", - "@octokit/request-error": "^5.0.0", - "@octokit/types": "^12.0.0", - "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/request-error": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.0.1.tgz", - "integrity": "sha512-X7pnyTMV7MgtGmiXBwmO6M5kIPrntOXdyKZLigNfQWSEQzVxR4a4vo49vJjTWX70mPndj8KhfT4Dx+2Ng3vnBQ==", - "dependencies": { - "@octokit/types": "^12.0.0", - "deprecation": "^2.0.0", - "once": "^1.4.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/rest": { - "version": "20.0.2", - "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-20.0.2.tgz", - "integrity": "sha512-Ux8NDgEraQ/DMAU1PlAohyfBBXDwhnX2j33Z1nJNziqAfHi70PuxkFYIcIt8aIAxtRE7KVuKp8lSR8pA0J5iOQ==", - "dependencies": { - "@octokit/core": "^5.0.0", - "@octokit/plugin-paginate-rest": "^9.0.0", - "@octokit/plugin-request-log": "^4.0.0", - "@octokit/plugin-rest-endpoint-methods": "^10.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@octokit/types": { - "version": "12.4.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.4.0.tgz", - "integrity": "sha512-FLWs/AvZllw/AGVs+nJ+ELCDZZJk+kY0zMen118xhL2zD0s1etIUHm1odgjP7epxYU1ln7SZxEUWYop5bhsdgQ==", - "dependencies": { - "@octokit/openapi-types": "^19.1.0" - } - }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" - }, - "node_modules/before-after-hook": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", - "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" - }, - "node_modules/bottleneck": { - "version": "2.19.5", - "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz", - "integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==" - }, - "node_modules/chalk": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", - "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", - "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/deprecation": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", - "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" - }, - "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/universal-user-agent": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", - "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==" - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" - } - } -} diff --git a/scripts/fetch-from-github/package.json b/scripts/fetch-from-github/package.json deleted file mode 100644 index 4e9c022bbb..0000000000 --- a/scripts/fetch-from-github/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "get-api-specs", - "version": "1.0.0", - "description": "", - "main": "get-cloud-api-spec.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@octokit/plugin-retry": "^6.0.1", - "@octokit/rest": "^20.0.2", - "chalk": "^5.3.0", - "js-yaml": "^4.1.0" - } -} diff --git a/scripts/generate-k8s-compatibility-matrix/generate-rp-matrix.js b/scripts/generate-k8s-compatibility-matrix/generate-rp-matrix.js deleted file mode 100644 index cc923e0b7a..0000000000 --- a/scripts/generate-k8s-compatibility-matrix/generate-rp-matrix.js +++ /dev/null @@ -1,291 +0,0 @@ -const axios = require('axios'); - -const REDPANDA_DATA_API_URL = 'https://artifacthub.io/api/v1/packages/helm/redpanda-data'; -const REDPANDA_HELM_CHART_REFERENCE = `${REDPANDA_DATA_API_URL}/redpanda`; -const CONSOLE_HELM_CHART_REFERENCE = `${REDPANDA_DATA_API_URL}/console`; -const OPERATOR_HELM_CHART_REFERENCE = `${REDPANDA_DATA_API_URL}/operator`; -const ARTIFACT_HUB_API_KEY_ID = process.env.ARTIFACT_HUB_API_KEY_ID; -const ARTIFACT_HUB_API_KEY_SECRET = process.env.ARTIFACT_HUB_API_KEY_SECRET; - -// User input: -// Earliest supported version of Redpanda. -// Users can pass this into the script as the first argument. -// We display only charts that support later versions of Redpanda. -const MIN_RP_VERSION = process.argv[2] || '22.3'; -// Which matrix to generate. Can be redpanda, console, or operator. -const MATRIX_TO_GENERATE = process.argv[3] || 'redpanda'; - -main(); - -async function main() { - try { - await generateTable(); - } catch (error) { - console.error('An error occurred:', error.message); - process.exit(1); - } -} - -async function generateTable() { - const allRedpandaChartVersions = await fetchAllChartVersions(REDPANDA_HELM_CHART_REFERENCE); - const allConsoleChartVersions = await fetchAllChartVersions(CONSOLE_HELM_CHART_REFERENCE); - const allOperatorChartVersions = await fetchAllChartVersions(OPERATOR_HELM_CHART_REFERENCE); - - let table; - - if (MATRIX_TO_GENERATE === 'redpanda') table = '|===\n| Redpanda Helm Chart |Supported Redpanda Versions|Minimum Kubernetes Version|Minimum Helm Version\n\n'; - if (MATRIX_TO_GENERATE === 'console') table = '|===\n| Redpanda Helm Chart |Default Redpanda Console Chart|Redpanda Console Version\n\n'; - if (MATRIX_TO_GENERATE === 'operator') table = '|===\n| Redpanda Operator Helm Chart | Redpanda Operator|CRD|Supported Redpanda Helm chart\n\n'; - - const processedChartVersions = new Set(); - - let supportedRedpandaVersions = new Map(); - for (const chartVersion of allRedpandaChartVersions) { - const chartDetails = await fetchRedpandaChartDetails(chartVersion); - if (chartDetails) { - const appMajorMinor = convertToMajorMinorVersion(chartDetails.appVersion); - supportedRedpandaVersions.set(appMajorMinor, chartDetails.appVersion); - } - } - - for (const chartVersion of allRedpandaChartVersions) { - const chartMajorMinor = convertToMajorMinorVersion(chartVersion); - if (!processedChartVersions.has(chartMajorMinor)) { - const chartDetails = await fetchRedpandaChartDetails(chartVersion); - if (chartDetails && MATRIX_TO_GENERATE === 'redpanda') { - const appMajorMinor = convertToMajorMinorVersion(chartDetails.appVersion); - - // Redpanda always has three supported versions available. - // Calculate which versions are supported by the Redpanda Helm chart, - // based on the current app version (n - 2). - const supportedVersions = getThreeSupportedVersions(appMajorMinor, supportedRedpandaVersions); - - table += `| link:https://artifacthub.io/packages/helm/redpanda-data/redpanda/${chartDetails.chartVersion}[${chartMajorMinor}]\n`; - table += `| ${supportedVersions.join(', ')}\n`; - table += `| ${chartDetails.kubernetesVersion}\n`; - table += `| ${chartDetails.helmVersion}\n\n`; - - processedChartVersions.add(chartMajorMinor); - - } else if (chartDetails && chartDetails.consoleChartVersions && MATRIX_TO_GENERATE === 'console') { - - await fetchLatestConsoleChartVersion(chartDetails.consoleChartVersions, allConsoleChartVersions) - .then(({ latestVersion, appVersion }) => { - table += `| link:https://github.com/redpanda-data/helm-charts/releases/redpanda-${chartDetails.chartVersion}[${chartMajorMinor}]\n`; - table += `| link:https://github.com/redpanda-data/helm-charts/releases/console-${latestVersion}[${latestVersion}]\n`; - table += `| link:https://github.com/redpanda-data/console/releases/v${appVersion}[${appVersion}]\n\n`; - }) - .catch(error => { - console.error('Error fetching console chart version:', error.message); - }); - - processedChartVersions.add(chartMajorMinor); - } - } - } - - if (MATRIX_TO_GENERATE === 'operator') { - // Fetch the latest n-2 versions of the Redpanda Helm chart. - // Redpanda Operator supports these versions. - const supportedRedpandaCharts = getLatestThreeMajorMinorVersions(allRedpandaChartVersions); - for (const chartVersion of allOperatorChartVersions) { - const chartMajorMinor = convertToMajorMinorVersion(chartVersion); - if (!processedChartVersions.has(chartMajorMinor)) { - const chartDetails = await fetchOperatorChartDetails(chartVersion); - if (!chartDetails.crd) continue - const appMajorMinor = convertToMajorMinorVersion(chartDetails.appVersion); - table += `| link:https://github.com/redpanda-data/helm-charts/releases/operator-${chartDetails.chartVersion}[${chartMajorMinor}]\n`; - table += `| link:https://github.com/redpanda-data/redpanda-operator/releases[${appMajorMinor}]\n`; - table += `|${chartDetails.crd}\n`; - table += `|${supportedRedpandaCharts.join(', ')}\n\n`; - - processedChartVersions.add(chartMajorMinor); - } - } - } - - table += '|===\n'; - console.log(table); -} - -function getLatestThreeMajorMinorVersions(chartVersions) { - return chartVersions - .map(convertToMajorMinorVersion) - .filter((value, index, self) => self.indexOf(value) === index) - .sort((a, b) => -compareVersions(a, b)) - .slice(0, 3); -} - -// Assuming consoleChartVersions is a string like ">=0.5 <1.0" -async function fetchLatestConsoleChartVersion(consoleChartVersions, allConsoleChartVersions) { - const versionRange = parseVersionRange(consoleChartVersions); - const filteredVersions = filterVersionsInRange(allConsoleChartVersions, versionRange); - const latestVersion = getLatestVersion(filteredVersions); - const appVersion = await fetchAppVersionForChart(latestVersion); - return { latestVersion, appVersion }; -} - -function parseVersionRange(rangeStr) { - const matches = rangeStr.match(/>=([0-9.]+) <([0-9.]+)/); - return { minVersion: matches[1], maxVersion: matches[2] }; -} - -function filterVersionsInRange(versions, range) { - return versions.filter(version => - compareVersions(version, range.minVersion) >= 0 && - compareVersions(version, range.maxVersion) < 0); -} - -function getLatestVersion(versions) { - return versions[0]; -} - -async function fetchAppVersionForChart(chartVersion) { - const url = `${CONSOLE_HELM_CHART_REFERENCE}/${chartVersion}` - const response = await fetchWithExponentialBackoff(url) - return response.data.app_version.replace(/^v/, ''); -} - -async function fetchOperatorChartDetails(chartVersion) { - try { - const url = `${OPERATOR_HELM_CHART_REFERENCE}/${chartVersion}`; - const response = await fetchWithExponentialBackoff(url) - const appVersion = response.data.app_version.replace(/^v/, ''); - let crdVersions = '' - - const crds = response.data.crds; - if (crds) { - for (i = 0; i < crds.length; i++) { - crdVersions += `\n\nxref:reference:k-crd-index.adoc[${crds[i].kind} ${crds[i].version}]` - } - } - - return { - chartVersion, - appVersion, - crd: crdVersions - }; - } catch (error) { - console.error(`Error fetching details for chart ${chartVersion}:`, error.message); - process.exit(1) - } -} - -async function fetchRedpandaChartDetails(chartVersion) { - try { - const url = `${REDPANDA_HELM_CHART_REFERENCE}/${chartVersion}`; - const response = await fetchWithExponentialBackoff(url) - const appVersion = response.data.app_version.replace(/^v/, ''); - if (appVersion === 'latest' || !versionIsGreaterOrEqual(appVersion, MIN_RP_VERSION)) { - return null; - } - - let kubernetesVersion; - let helmVersion; - let consoleChartVersions; - - const deps = response.data.data.dependencies; - if (deps) { - for (i = 0; i < deps.length; i++) { - if (deps[i].name !== 'console') continue - consoleChartVersions = deps[i].version - } - } - - // Check the links array for the Helm version - if (response.data.links) { - const helmLink = response.data.links.find(link => link.name && link.name.startsWith('Helm (>=')); - if (helmLink) { - helmVersionMatch = helmLink.name.match(/Helm \(>= ([0-9.]+)\)/); - helmVersion = helmVersionMatch ? helmVersionMatch[1] : '3.6.0' - } - } - - // Get the Kubernetes version defined in the chart metadata - if (response.data.data.kubeVersion) { - const kubeVersionRegex = /([0-9]+\.[0-9]+(?:\.[0-9]+)?(?:-[0-9]+)?)/; - let kubeVersionMatch = response.data.data.kubeVersion.match(kubeVersionRegex); - kubernetesVersion = kubeVersionMatch ? kubeVersionMatch[1] : '{supported-kubernetes-version}'; - } - - return { - chartVersion, - consoleChartVersions, - appVersion, - kubernetesVersion, - helmVersion - }; - } catch (error) { - console.error(`Error fetching details for chart ${chartVersion}:`, error.message); - process.exit(1) - } -} - -async function fetchWithExponentialBackoff(url, retries = 5, delay = 1000) { - try { - const response = await axios.get(url, { - headers: { - 'X-API-KEY-ID': ARTIFACT_HUB_API_KEY_ID, - 'X-API-KEY-SECRET': ARTIFACT_HUB_API_KEY_SECRET - } - }); - return response; - } catch (error) { - if (retries === 0 || error.response.status !== 429) throw error; - - console.log(`Rate limit exceeded. Retrying in ${delay}ms...`); - await new Promise(resolve => setTimeout(resolve, delay)); - return fetchWithExponentialBackoff(url, retries - 1, delay * 2); - } -} - -async function fetchAllChartVersions(chart) { - try { - const response = await fetchWithExponentialBackoff(chart) - return response.data.available_versions - .filter(item => item.prerelease === false) - .map(v => v.version) - .filter(v => v !== 'latest'); - } catch (error) { - console.error('Error fetching chart versions:', error.message); - process.exit(1) - } -} - -function versionIsGreaterOrEqual(version, minVersion) { - const versionParts = version.split('.').map(Number); - const minVersionParts = minVersion.split('.').map(Number); - for (let i = 0; i < Math.min(versionParts.length, minVersionParts.length); i++) { - if (versionParts[i] > minVersionParts[i]) return true; - if (versionParts[i] < minVersionParts[i]) return false; - } - return versionParts.length >= minVersionParts.length; -} - -function convertToMajorMinorVersion(version) { - return version.split('.').slice(0, 2).join('.') + '.x'; -} - -function compareVersions(v1, v2) { - const parts1 = v1.split('.').map(Number); - const parts2 = v2.split('.').map(Number); - - for (let i = 0; i < 2; i++) { - if (parts1[i] > parts2[i]) return 1; - if (parts1[i] < parts2[i]) return -1; - } - return 0; -} - -function getThreeSupportedVersions(currentVersion, supportedRedpandaVersions) { - const sortedVersions = Array.from(supportedRedpandaVersions.keys()).sort((a, b) => -compareVersions(a, b)); - const currentIndex = sortedVersions.indexOf(currentVersion); - const supportedVersions = []; - - for (let i = currentIndex; i < sortedVersions.length && supportedVersions.length < 3; i++) { - if (supportedRedpandaVersions.has(sortedVersions[i])) { - supportedVersions.push(`link:https://github.com/redpanda-data/redpanda/releases/[${sortedVersions[i]}]`); - } - } - return supportedVersions; -} diff --git a/scripts/generate-k8s-compatibility-matrix/package-lock.json b/scripts/generate-k8s-compatibility-matrix/package-lock.json deleted file mode 100644 index c169c49070..0000000000 --- a/scripts/generate-k8s-compatibility-matrix/package-lock.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "name": "k-compatibility", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "k-compatibility", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "axios": "^1.6.2" - } - }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - } - } -} diff --git a/scripts/generate-k8s-compatibility-matrix/package.json b/scripts/generate-k8s-compatibility-matrix/package.json deleted file mode 100644 index 906272f7ca..0000000000 --- a/scripts/generate-k8s-compatibility-matrix/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "k-compatibility", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "axios": "^1.6.2" - } -} diff --git a/tests/setup-tests/fetch-versions-and-rpk.json b/tests/setup-tests/fetch-versions-and-rpk.json index 63b9d3932e..16b4388f9c 100644 --- a/tests/setup-tests/fetch-versions-and-rpk.json +++ b/tests/setup-tests/fetch-versions-and-rpk.json @@ -10,7 +10,7 @@ }, { "action": "runShell", - "command": "node ./redpanda-versions/fetch-console.js", + "command": "npx doc-tools get-console-version --from-antora", "setVariables": [ { "name": "REDPANDA_CONSOLE_VERSION", @@ -24,7 +24,7 @@ }, { "action": "runShell", - "command": "node ./redpanda-versions/fetch-redpanda.js", + "command": "npx doc-tools get-redpanda-version --from-antora", "setVariables": [ { "name": "REDPANDA_VERSION", @@ -38,7 +38,7 @@ }, { "action": "runShell", - "command": "bash ./tools/install-dependencies.sh" + "command": "npx doc-tools install-test-dependencies" }, { "action": "runShell", diff --git a/tests/setup-tests/install-rpk.json b/tests/setup-tests/install-rpk.json deleted file mode 100644 index d90d6eac18..0000000000 --- a/tests/setup-tests/install-rpk.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "tests": [ - { - "id": "install-rpk", - "description": "Install the latest version of rpk", - "steps": [ - { - "action": "runShell", - "command": "bash ./tools/install-dependencies.sh" - } - ] - } - ] -} diff --git a/tests/setup-tests/redpanda-versions/fetch-console.js b/tests/setup-tests/redpanda-versions/fetch-console.js deleted file mode 100644 index 32ec320f11..0000000000 --- a/tests/setup-tests/redpanda-versions/fetch-console.js +++ /dev/null @@ -1,68 +0,0 @@ -// Import the version fetcher module -const GetLatestConsoleVersion = require('../../../node_modules/@redpanda-data/docs-extensions-and-macros/extensions/version-fetcher/get-latest-console-version.js'); -const yaml = require('../../../node_modules/js-yaml/index.js'); -const fs = require('fs'); - -if (process.argv.length > 3) { - const overrideDockerRepo = process.argv[2]; - const overrideVersion = process.argv[3]; - console.log(`CONSOLE_DOCKER_REPO=${overrideDockerRepo}`); - console.log(`CONSOLE_VERSION=${overrideVersion}`); - process.exit(0); -} - -const owner = 'redpanda-data'; -const repo = 'console'; -const CONSOLE_DOCKER_REPO = 'console' - -function getPrereleaseFromAntora() { - try { - const fileContents = fs.readFileSync('../../antora.yml', 'utf8'); - const antoraConfig = yaml.load(fileContents); - return antoraConfig.prerelease === true; - } catch (error) { - console.error("Error reading antora.yml:", error); - return false; - } -} - -// Set beta based on the prerelease field in antora.yml or fallback to environment variable -const beta = getPrereleaseFromAntora() - -// GitHub Octokit initialization -async function loadOctokit() { - const { Octokit } = await import('@octokit/rest'); - if (!process.env.REDPANDA_GITHUB_TOKEN) { - return new Octokit(); - } - return new Octokit({ - auth: process.env.REDPANDA_GITHUB_TOKEN, - }); -} - -(async () => { - try { - const github = await loadOctokit(); - - const results = await Promise.allSettled([ - GetLatestConsoleVersion(github, owner, repo), - ]); - const LatestConsoleVersion = results[0].status === 'fulfilled' ? results[0].value : null; - if (!LatestConsoleVersion) { - throw new Error('Failed to fetch the latest Redpanda version'); - } - // Determine the release version based on the beta flag, with a fallback to stable release if RC is null - const latestConsoleReleaseVersion = beta - ? (LatestConsoleVersion.latestBetaRelease - ? LatestConsoleVersion.latestBetaRelease - : `${LatestConsoleVersion.latestStableRelease}`) - : `${LatestConsoleVersion.latestStableRelease}`; - - // Print both version and Docker repo for Doc Detective to capture - console.log(`CONSOLE_VERSION=${latestConsoleReleaseVersion}`); - console.log(`CONSOLE_DOCKER_REPO=${CONSOLE_DOCKER_REPO}`); - } catch (error) { - console.error(error); - process.exit(1); - } -})(); \ No newline at end of file diff --git a/tests/setup-tests/redpanda-versions/fetch-redpanda.js b/tests/setup-tests/redpanda-versions/fetch-redpanda.js deleted file mode 100644 index 75bebecd99..0000000000 --- a/tests/setup-tests/redpanda-versions/fetch-redpanda.js +++ /dev/null @@ -1,75 +0,0 @@ -// Import the version fetcher module -const GetLatestRedpandaVersion = require('../../../node_modules/@redpanda-data/docs-extensions-and-macros/extensions/version-fetcher/get-latest-redpanda-version.js'); -const yaml = require('../../../node_modules/js-yaml/index.js'); -const fs = require('fs'); - -if (process.argv.length > 3) { - const overrideDockerRepo = process.argv[2]; - const overrideVersion = process.argv[3]; - console.log(`REDPANDA_DOCKER_REPO=${overrideDockerRepo}`); - console.log(`REDPANDA_VERSION=${overrideVersion}`); - process.exit(0); -} - -// Fetch the latest release version from GitHub -const owner = 'redpanda-data'; -function getPrereleaseFromAntora() { - try { - const fileContents = fs.readFileSync('../../antora.yml', 'utf8'); - const antoraConfig = yaml.load(fileContents); - return antoraConfig.prerelease === true; - } catch (error) { - console.error("Error reading antora.yml:", error); - return false; - } -} - -// Set beta based on the prerelease field in antora.yml or fallback to environment variable -const beta = getPrereleaseFromAntora() -// Conditionally set DOCKER_REPO for subsequent test steps such as the Docker Compose file -if (beta) { - REDPANDA_DOCKER_REPO = 'redpanda-unstable'; -} else { - REDPANDA_DOCKER_REPO = 'redpanda'; -} -const repo = 'redpanda'; - -async function loadOctokit() { - const { Octokit } = await import('@octokit/rest'); - if (!process.env.REDPANDA_GITHUB_TOKEN) { - return new Octokit(); - } - return new Octokit({ - auth: process.env.REDPANDA_GITHUB_TOKEN, - }); -} - -(async () => { - try { - const github = await loadOctokit(); - const results = await Promise.allSettled([ - GetLatestRedpandaVersion(github, owner, repo), - ]); - - const LatestRedpandaVersion = results[0].status === 'fulfilled' ? results[0].value : null; - - if (!LatestRedpandaVersion) { - throw new Error('Failed to fetch the latest Redpanda version'); - } - // Determine the release version based on the beta flag, with a fallback to stable release if RC is null - const latestRedpandaReleaseVersion = beta - ? (LatestRedpandaVersion.latestRcRelease && LatestRedpandaVersion.latestRcRelease.version - ? LatestRedpandaVersion.latestRcRelease.version - : `${LatestRedpandaVersion.latestRedpandaRelease.version}`) - : `${LatestRedpandaVersion.latestRedpandaRelease.version}`; - - if (!LatestRedpandaVersion.latestRcRelease) REDPANDA_DOCKER_REPO = 'redpanda' - - // Print both version and Docker repo for Doc Detective to capture - console.log(`REDPANDA_VERSION=${latestRedpandaReleaseVersion}`); - console.log(`REDPANDA_DOCKER_REPO=${REDPANDA_DOCKER_REPO}`); - } catch (error) { - console.error(error); - process.exit(1); - } -})(); diff --git a/tests/setup-tests/tools/install-dependencies.sh b/tests/setup-tests/tools/install-dependencies.sh deleted file mode 100755 index 174bf21785..0000000000 --- a/tests/setup-tests/tools/install-dependencies.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/bin/bash -set -e - -# Function to install Node.js -install_node() { - if command -v node &>/dev/null; then - echo "Node.js is already installed. Version: $(node -v)" - else - echo "Installing Node.js..." - curl -fsSL https://fnm.vercel.app/install | bash || { echo "Failed to install fnm"; exit 1; } - # Load fnm into the current shell - export PATH=$HOME/.fnm:$PATH - eval "$(fnm env)" || { echo "Failed to load fnm environment"; exit 1; } - fnm install --lts || { echo "Failed to install Node.js"; exit 1; } - fnm use --lts || { echo "Failed to use Node.js"; exit 1; } - echo "Node.js version: $(node -v)" - fi -} - -# Function to install Rust -install_rust() { - if command -v rustc &>/dev/null; then - echo "Rust is already installed. Version: $(rustc --version)" - else - echo "Installing Rust..." - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y || { echo "Failed to install Rust"; exit 1; } - source $HOME/.cargo/env || { echo "Failed to load Rust environment"; exit 1; } - echo "Rust version: $(rustc --version)" - fi -} - -# Function to check if expect and jq are installed and install them if they're not -ensure_dependencies_installed() { - - if ! command -v expect &> /dev/null; then - echo "Expect is not installed. Trying to install..." - missing_deps=1 - - # Detect OS - case "$(uname -s)" in - Linux) - echo "Detected Linux." - sudo apt-get update && sudo apt-get install expect -y || sudo yum install expect -y || { echo "Failed to install expect"; exit 1; } - ;; - Darwin) - echo "Detected macOS." - # Assumes Homebrew is installed. If not, it attempts to install Homebrew first. - if ! command -v brew &> /dev/null; then - echo "Homebrew not found." - exit 1 - fi - brew install expect || { echo "Failed to install expect"; exit 1; } - ;; - *) - echo "Unsupported operating system. Please install expect manually." - exit 1 - ;; - esac - fi - - if ! command -v jq &> /dev/null; then - echo "jq is not installed. Trying to install..." - - # Install jq based on OS - case "$(uname -s)" in - Linux) - sudo apt-get install jq -y || sudo yum install jq -y || { echo "Failed to install jq"; exit 1; } - ;; - Darwin) - brew install jq || { echo "Failed to install jq"; exit 1; } - ;; - *) - echo "Unsupported operating system. Please install jq manually." - exit 1 - ;; - esac - fi - - install_node - install_rust -} - -# Ensure expect and jq are installed -ensure_dependencies_installed - -# Function to check rpk installation and display its version -check_rpk_installed() { - if command -v rpk &>/dev/null; then - echo "rpk is already installed. Version information:" - rpk version - return 0 - else - return 1 - fi -} - -# Determine OS and architecture -OS="$(uname -s)" -ARCH="$(uname -m)" - -# Check if rpk is already installed -if check_rpk_installed; then - exit 0 -fi - -# Check if running on macOS and use Homebrew to install rpk -if [ "${OS}" == "Darwin" ]; then - echo "Detected macOS. Attempting to install rpk using Homebrew..." - - # Check if Homebrew is installed - if ! command -v brew &>/dev/null; then - echo "Homebrew not found." - exit 1 - fi - - # Install rpk - brew install redpanda-data/tap/redpanda || { echo "Failed to install rpk via Homebrew"; exit 1; } - - # Verify installation - echo "rpk has been installed. Version information:" - rpk version - exit 0 -fi - -# For Linux systems -if [ "${OS}" == "Linux" ]; then - FILENAME="rpk-linux-amd64.zip" - URL_BASE="https://github.com/redpanda-data/redpanda/releases" - - # Download latest version of rpk - echo "Downloading ${FILENAME}..." - curl -LO "${URL_BASE}/latest/download/${FILENAME}" || { echo "Failed to download rpk"; exit 1; } - - # Ensure the target directory exists - mkdir -p $HOME/.local/bin || { echo "Failed to create directory"; exit 1; } - - # Unzip the rpk binary to the target directory - unzip -o "${FILENAME}" -d $HOME/.local/bin || { echo "Failed to unzip rpk"; exit 1; } - - # Remove the downloaded archive - rm "${FILENAME}" || { echo "Failed to remove downloaded archive"; exit 1; } - - # Add the target directory to PATH for the current session - export PATH=$HOME/.local/bin:$PATH - - # Add the target directory to PATH for future sessions - echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc - source ~/.bashrc - - # Verify installation - echo "rpk has been installed. Version information:" - rpk version - exit 0 -fi - -echo "Unsupported operating system: ${OS}" -exit 1