Skip to content

Commit

Permalink
moving everything out of temp
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiveerk committed Aug 2, 2024
1 parent 8d665db commit 270fda3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/types/privatekubectl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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`
)
})

Expand Down
25 changes: 16 additions & 9 deletions src/types/privatekubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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/' +
Expand Down Expand Up @@ -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
) {
Expand All @@ -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}`
)
Expand Down

0 comments on commit 270fda3

Please sign in to comment.