From a14aa674a2dffc5b5fe3a96fe4443e9eff1332e5 Mon Sep 17 00:00:00 2001 From: Daniel Herbolt Date: Fri, 26 Sep 2025 15:17:52 +0200 Subject: [PATCH 1/5] feat: allow to set the cwd in copyFromPod for use in tar --- src/cp.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cp.ts b/src/cp.ts index d84d34cf86..39f8e4213b 100644 --- a/src/cp.ts +++ b/src/cp.ts @@ -18,6 +18,7 @@ export class Cp { * @param {string} containerName - The name of the container in the pod to exec the command inside. * @param {string} srcPath - The source path in the pod * @param {string} tgtPath - The target path in local + * @param {string} cwd - The directory that is used as the parent in the pod when downloading */ public async cpFromPod( namespace: string, @@ -25,10 +26,15 @@ export class Cp { containerName: string, srcPath: string, tgtPath: string, + cwd?: string, ): Promise { const tmpFile = tmp.fileSync(); const tmpFileName = tmpFile.name; - const command = ['tar', 'zcf', '-', srcPath]; + const command = ['tar', 'zcf', '-']; + if (cwd) { + command.push('-C', cwd); + } + command.push(srcPath); const writerStream = fs.createWriteStream(tmpFileName); const errStream = new WritableStreamBuffer(); this.execInstance.exec( From 7b041ffb37a59965c5ef86e738028898b556ee8b Mon Sep 17 00:00:00 2001 From: Daniel Herbolt Date: Sat, 27 Sep 2025 13:46:18 +0200 Subject: [PATCH 2/5] added simple test --- src/cp_test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/cp_test.ts b/src/cp_test.ts index 7cfcafa7d4..0782106cba 100644 --- a/src/cp_test.ts +++ b/src/cp_test.ts @@ -38,6 +38,35 @@ describe('Cp', () => { await cp.cpFromPod(namespace, pod, container, srcPath, tgtPath); verify(fakeWebSocket.connect(`${path}?${queryStr}`, null, anyFunction())).called(); }); + + it('should run create tar command to a url with cwd', async () => { + const kc = new KubeConfig(); + const fakeWebSocket: WebSocketInterface = mock(WebSocketHandler); + const exec = new Exec(kc, instance(fakeWebSocket)); + const cp = new Cp(kc, exec); + + const namespace = 'somenamespace'; + const pod = 'somepod'; + const container = 'container'; + const srcPath = '/'; + const tgtPath = '/'; + const cwd = '/abc'; + const cmdArray = ['tar', 'zcf', '-', '-C', cwd, srcPath]; + const path = `/api/v1/namespaces/${namespace}/pods/${pod}/exec`; + + const query = { + stdout: true, + stderr: true, + stdin: false, + tty: false, + command: cmdArray, + container, + }; + const queryStr = querystring.stringify(query); + + await cp.cpFromPod(namespace, pod, container, srcPath, tgtPath, cwd); + verify(fakeWebSocket.connect(`${path}?${queryStr}`, null, anyFunction())).called(); + }); }); describe('cpToPod', () => { From 9d3d472b99300f254628cb15e94f6cdb105706e7 Mon Sep 17 00:00:00 2001 From: Daniel Herbolt Date: Mon, 29 Sep 2025 15:12:06 +0200 Subject: [PATCH 3/5] cwd is optional, reset unwanted changes --- src/cp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cp.ts b/src/cp.ts index 270e18dc78..7e676bfb0b 100644 --- a/src/cp.ts +++ b/src/cp.ts @@ -16,7 +16,7 @@ export class Cp { * @param {string} containerName - The name of the container in the pod to exec the command inside. * @param {string} srcPath - The source path in the pod * @param {string} tgtPath - The target path in local - * @param {string} cwd - The directory that is used as the parent in the pod when downloading + * @param {string} [cwd] - The directory that is used as the parent in the pod when downloading */ public async cpFromPod( namespace: string, From 1b585ea769cf1f652eea0f480250dda0a4a3d83d Mon Sep 17 00:00:00 2001 From: Daniel Herbolt Date: Mon, 29 Sep 2025 15:22:22 +0200 Subject: [PATCH 4/5] reset --- .github/workflows/generate-javascript.yml | 95 ++++++++++++----------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/.github/workflows/generate-javascript.yml b/.github/workflows/generate-javascript.yml index 7f96f8efe9..f6776f2549 100644 --- a/.github/workflows/generate-javascript.yml +++ b/.github/workflows/generate-javascript.yml @@ -1,52 +1,53 @@ name: Generate on: - workflow_dispatch: - inputs: - kubernetesBranch: - type: string - required: true - description: 'The remote kubernetes release branch to fetch openapi spec. .e.g. "release-1.23"' - genCommit: - type: string - required: true - default: 'b461333bb57fa2dc2152f939ed70bac3cef2c1f6' - description: 'The commit to use for the kubernetes-client/gen repo' + workflow_dispatch: + inputs: + kubernetesBranch: + type: string + required: true + description: 'The remote kubernetes release branch to fetch openapi spec. .e.g. "release-1.23"' + genCommit: + type: string + required: true + default: 'b461333bb57fa2dc2152f939ed70bac3cef2c1f6' + description: 'The commit to use for the kubernetes-client/gen repo' + jobs: - generate: - runs-on: ubuntu-latest - steps: - - name: Checkout Javascript - uses: actions/checkout@v5.0.0 - - name: Setup Node - uses: actions/setup-node@v5 - with: - node-version: '20' - - name: Generate Openapi - run: | - echo "export KUBERNETES_BRANCH=${{ github.event.inputs.kubernetesBranch }} >> ./settings" - echo "export GEN_COMMIT="${{ github.event.inputs.genCommit }}" >> ./settings" - ./generate-client.sh - - name: Generate Branch Name - run: | - SUFFIX=$(openssl rand -hex 4) - echo "BRANCH=automated-generate-$SUFFIX" >> $GITHUB_ENV - - name: Commit and push - run: | - # Commit and push - git config user.email "k8s.ci.robot@gmail.com" - git config user.name "Kubernetes Prow Robot" - git checkout -b "$BRANCH" - git add . - # we modify the settings file in "Generate Openapi" but do not want to commit this - git reset settings - git commit -s -m 'Automated openapi generation from ${{ github.event.inputs.kubernetesBranch }}' - git push origin "$BRANCH" - - name: Pull Request - uses: repo-sync/pull-request@v2 - with: - source_branch: ${{ env.BRANCH }} - destination_branch: ${{ github.ref_name }} - github_token: ${{ secrets.GITHUB_TOKEN }} - pr_title: 'Automated Generate from openapi ${{ github.event.inputs.kubernetesBranch }}' + generate: + runs-on: ubuntu-latest + steps: + - name: Checkout Javascript + uses: actions/checkout@v5.0.0 + - name: Setup Node + uses: actions/setup-node@v5 + with: + node-version: '20' + - name: Generate Openapi + run: | + echo "export KUBERNETES_BRANCH=${{ github.event.inputs.kubernetesBranch }} >> ./settings" + echo "export GEN_COMMIT="${{ github.event.inputs.genCommit }}" >> ./settings" + ./generate-client.sh + - name: Generate Branch Name + run: | + SUFFIX=$(openssl rand -hex 4) + echo "BRANCH=automated-generate-$SUFFIX" >> $GITHUB_ENV + - name: Commit and push + run: | + # Commit and push + git config user.email "k8s.ci.robot@gmail.com" + git config user.name "Kubernetes Prow Robot" + git checkout -b "$BRANCH" + git add . + # we modify the settings file in "Generate Openapi" but do not want to commit this + git reset settings + git commit -s -m 'Automated openapi generation from ${{ github.event.inputs.kubernetesBranch }}' + git push origin "$BRANCH" + - name: Pull Request + uses: repo-sync/pull-request@v2 + with: + source_branch: ${{ env.BRANCH }} + destination_branch: ${{ github.ref_name }} + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_title: "Automated Generate from openapi ${{ github.event.inputs.kubernetesBranch }}" From f8283d4d8ceebe35cf15f2144d68c49cc110b34b Mon Sep 17 00:00:00 2001 From: Daniel Herbolt Date: Mon, 29 Sep 2025 15:23:18 +0200 Subject: [PATCH 5/5] reset --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d5b318bd03..c2895b731d 100644 --- a/README.md +++ b/README.md @@ -114,15 +114,15 @@ We switched from `request` to `fetch` as the HTTP(S) backend for the `1.0.0` rel Generally speaking newer clients will work with older Kubernetes, but compatibility isn't 100% guaranteed. -| client version | older versions | 1.28 | 1.29 | 1.30 | 1.31 | 1.32 | 1.33 | -| -------------- | -------------- | ---- | ---- | ---- | ---- | ---- | ---- | -| 0.19.x | - | ✓ | x | x | x | x | x | -| 0.20.x | - | + | ✓ | x | x | x | x | -| 0.21.x | - | + | + | ✓ | x | x | x | -| 0.22.x | - | + | + | + | ✓ | x | x | -| 1.0.x | - | + | + | + | + | ✓ | x | -| 1.1.x | - | + | + | + | + | ✓ | x | -| 1.2.x | - | + | + | + | + | + | ✓ | +| client version | older versions | 1.28 | 1.29 | 1.30 | 1.31 | 1.32 | 1.33| +| -------------- | -------------- | ---- | ---- | ---- | ---- | ---- |----| +| 0.19.x | - | ✓ | x | x | x | x | x | +| 0.20.x | - | + | ✓ | x | x | x | x | +| 0.21.x | - | + | + | ✓ | x | x | x | +| 0.22.x | - | + | + | + | ✓ | x | x | +| 1.0.x | - | + | + | + | + | ✓ | x | +| 1.1.x | - | + | + | + | + | ✓ | x | +| 1.2.x | - | + | + | + | + | + | ✓ | Key: