diff --git a/src/types/privatekubectl.test.ts b/src/types/privatekubectl.test.ts index 91cad2c85..068f535cb 100644 --- a/src/types/privatekubectl.test.ts +++ b/src/types/privatekubectl.test.ts @@ -8,7 +8,7 @@ import { import * as exec from '@actions/exec' describe('Private kubectl', () => { - const testString = `kubectl annotate -f /tmp/testdir/test.yml,/tmp/test2.yml,/tmp/testdir/subdir/test3.yml -f /tmp/test4.yml --filename /tmp/test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832` + const testString = `kubectl annotate -f /tmp/testdir/test.yml,/tmp/test2.yml,/tmp/testdir/subdir/test3.yml -f /tmp/test4.yml --filename /tmp/test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832` const mockKube = new PrivateKubectl( 'kubectlPath', 'namespace', @@ -42,7 +42,7 @@ describe('Private kubectl', () => { expect( replaceFileNamesWithShallowNamesRelativeToTemp(testString) ).toEqual( - `kubectl annotate -f testdir-test.yml,test2.yml,testdir-subdir-test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832` + `kubectl annotate -f testdir-test.yml,test2.yml,testdir-subdir-test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832` ) }) diff --git a/src/types/privatekubectl.ts b/src/types/privatekubectl.ts index 4eeb54e37..7c94f88ec 100644 --- a/src/types/privatekubectl.ts +++ b/src/types/privatekubectl.ts @@ -44,7 +44,8 @@ export class PrivateKubectl extends Kubectl { if (addFileFlag) { const tempDirectory = getTempDirectory() - privateClusterArgs.push(...['--file', tempDirectory]) + eo.cwd = path.join(tempDirectory, 'manifests') + privateClusterArgs.push(...['--file', '.']) } core.debug( @@ -85,14 +86,8 @@ export class PrivateKubectl extends Kubectl { return str.includes('-f ') || str.includes('filename ') } - private createTempManifestsDirectory() { - if (!fs.existsSync('/tmp/manifests')) { - fs.mkdirSync('/tmp/manifests', {recursive: true}) - } - } - private moveFileToTempManifestDir(file: string) { - this.createTempManifestsDirectory() + createTempManifestsDirectory() if (!fs.existsSync('/tmp/' + file)) { core.debug( '/tmp/' + @@ -124,6 +119,15 @@ export class PrivateKubectl extends Kubectl { } } +function createTempManifestsDirectory(): string { + const manifestsDirPath = path.join(getTempDirectory(), 'manifests') + if (!fs.existsSync(manifestsDirPath)) { + fs.mkdirSync(manifestsDirPath, {recursive: true}) + } + + return manifestsDirPath +} + export function replaceFileNamesWithShallowNamesRelativeToTemp( kubectlCmd: string ) { @@ -133,7 +137,10 @@ export function replaceFileNamesWithShallowNamesRelativeToTemp( const relativeName = path.relative(getTempDirectory(), filename) const shallowName = relativeName.replace(/\//g, '-') - const shallowPath = path.join(getTempDirectory(), shallowName) + // make manifests dir in temp if it doesn't already exist + const manifestsTempDir = createTempManifestsDirectory() + + const shallowPath = path.join(manifestsTempDir, shallowName) core.debug( `moving contents from ${filename} to shallow location at ${shallowPath}` )