mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-04-13 12:02:16 +08:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb028f04f3 | ||
|
|
f4285249b3 | ||
|
|
9b0406cb40 | ||
|
|
1c8fffe8b3 | ||
|
|
2be70f5a52 | ||
|
|
1f527c033f | ||
|
|
eb220500b5 | ||
|
|
55f8f705e4 | ||
|
|
2220ef0140 | ||
|
|
1b2b1d4a34 | ||
|
|
7d5d1039d9 | ||
|
|
fd396fb546 | ||
|
|
823366077e | ||
|
|
2919b4c2ec | ||
|
|
8c863f5204 | ||
|
|
13f6bcc9fc | ||
|
|
3befb84894 | ||
|
|
a9bc5b5b6c | ||
|
|
917fe3d272 | ||
|
|
196028534d | ||
|
|
e2a641d846 | ||
|
|
1c926961fc | ||
|
|
40eb8c04b5 | ||
|
|
ea0fceaf51 | ||
|
|
b18d9f2e35 | ||
|
|
f52b3916c9 | ||
|
|
ba8e2d4f92 | ||
|
|
7a4e089283 | ||
|
|
e7694c0134 | ||
|
|
cb0277571c | ||
|
|
3b8eece8c7 |
6
.github/workflows/codeql.yml
vendored
6
.github/workflows/codeql.yml
vendored
@ -55,11 +55,11 @@ jobs:
|
|||||||
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5
|
uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v3.29.5
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
build-mode: ${{ matrix.build-mode }}
|
build-mode: ${{ matrix.build-mode }}
|
||||||
@ -86,6 +86,6 @@ jobs:
|
|||||||
echo ' make release'
|
echo ' make release'
|
||||||
exit 1
|
exit 1
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5
|
uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v3.29.5
|
||||||
with:
|
with:
|
||||||
category: '/language:${{matrix.language}}'
|
category: '/language:${{matrix.language}}'
|
||||||
|
|||||||
4
.github/workflows/default-labels.yml
vendored
4
.github/workflows/default-labels.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
|
|
||||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10.1.0
|
- uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10.2.0
|
||||||
name: Setting Issue as Idle
|
name: Setting Issue as Idle
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@ -24,7 +24,7 @@ jobs:
|
|||||||
operations-per-run: 100
|
operations-per-run: 100
|
||||||
exempt-issue-labels: 'backlog'
|
exempt-issue-labels: 'backlog'
|
||||||
|
|
||||||
- uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10.1.0
|
- uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10.2.0
|
||||||
name: Setting PR as Idle
|
name: Setting PR as Idle
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
2
.github/workflows/integration-tests.yml
vendored
2
.github/workflows/integration-tests.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout Source Code
|
- name: Checkout Source Code
|
||||||
id: checkout-code
|
id: checkout-code
|
||||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- name: Npm Install and Build
|
- name: Npm Install and Build
|
||||||
id: npm-build
|
id: npm-build
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
4
.github/workflows/prettify-code.yml
vendored
4
.github/workflows/prettify-code.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
||||||
with:
|
with:
|
||||||
node-version: 'lts/*'
|
node-version: 'lts/*'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|||||||
2
.github/workflows/unit-tests.yml
vendored
2
.github/workflows/unit-tests.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
unit-test:
|
unit-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- name: Run Unit Tests
|
- name: Run Unit Tests
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
|
|||||||
39
CHANGELOG.md
39
CHANGELOG.md
@ -1,5 +1,44 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## [5.0.0] - 2026-04-07
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- #227 Migrate to ESM with esbuild, vitest
|
||||||
|
|
||||||
|
### Runtime and platform
|
||||||
|
|
||||||
|
- #222 Update Node version from 20 to 24
|
||||||
|
|
||||||
|
### Dependabot updates
|
||||||
|
|
||||||
|
- #231 Bump github/codeql-action in /.github/workflows in the actions group
|
||||||
|
- #230 Bump typescript in the actions group across 1 directory
|
||||||
|
- #228 Bump picomatch
|
||||||
|
- #226 Bump github/codeql-action in /.github/workflows in the actions group
|
||||||
|
- #223 Bump undici from 6.23.0 to 6.24.0
|
||||||
|
- #221 Bump the actions group in /.github/workflows with 2 updates
|
||||||
|
- #218 Bump the actions group in /.github/workflows with 2 updates
|
||||||
|
- #219 Bump minimatch
|
||||||
|
- #217 Bump undici and @actions/http-client
|
||||||
|
- #216 Bump github/codeql-action in /.github/workflows in the actions group
|
||||||
|
- #214 Bump the actions group in /.github/workflows with 2 updates
|
||||||
|
- #212 Bump the actions group in /.github/workflows with 2 updates
|
||||||
|
- #211 Bump the actions group with 3 updates
|
||||||
|
- #210 Bump the actions group with 2 updates
|
||||||
|
- #208 Bump @types/node from 25.0.2 to 25.0.3 in the actions group
|
||||||
|
- #209 Bump github/codeql-action in /.github/workflows in the actions group
|
||||||
|
- #206 Bump the actions group with 3 updates
|
||||||
|
- #207 Bump github/codeql-action in /.github/workflows in the actions group
|
||||||
|
- #205 Bump the actions group in /.github/workflows with 4 updates
|
||||||
|
- #204 Bump the actions group with 2 updates
|
||||||
|
- #202 Bump the actions group in /.github/workflows with 2 updates
|
||||||
|
- #203 Bump prettier from 3.6.2 to 3.7.3 in the actions group
|
||||||
|
- #201 Bump glob from 10.4.5 to 10.5.0
|
||||||
|
- #200 Bump js-yaml from 3.14.1 to 3.14.2
|
||||||
|
- #198 Bump js-yaml from 4.1.0 to 4.1.1
|
||||||
|
- #199 Bump the actions group with 2 updates
|
||||||
|
|
||||||
## [4.0.2] - 2025-11-13
|
## [4.0.2] - 2025-11-13
|
||||||
|
|
||||||
- #[164](https://github.com/Azure/k8s-set-context/pull/164) Adding optional kubeconfig encoding variable
|
- #[164](https://github.com/Azure/k8s-set-context/pull/164) Adding optional kubeconfig encoding variable
|
||||||
|
|||||||
@ -19,7 +19,7 @@ Refer to the [action metadata file](./action.yml) for details about inputs. Note
|
|||||||
### Kubeconfig approach
|
### Kubeconfig approach
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: azure/k8s-set-context@v4
|
- uses: azure/k8s-set-context@v5
|
||||||
with:
|
with:
|
||||||
method: kubeconfig
|
method: kubeconfig
|
||||||
kubeconfig: <your kubeconfig>
|
kubeconfig: <your kubeconfig>
|
||||||
@ -50,7 +50,7 @@ Please refer to documentation on fetching [kubeconfig for any generic K8s cluste
|
|||||||
### Service account approach
|
### Service account approach
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: azure/k8s-set-context@v4
|
- uses: azure/k8s-set-context@v5
|
||||||
with:
|
with:
|
||||||
method: service-account
|
method: service-account
|
||||||
k8s-url: <URL of the cluster's API server>
|
k8s-url: <URL of the cluster's API server>
|
||||||
@ -74,7 +74,7 @@ kubectl get secret <service-account-secret-name> -n <namespace> -o yaml
|
|||||||
### Service account approach for arc cluster
|
### Service account approach for arc cluster
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: azure/k8s-set-context@v4
|
- uses: azure/k8s-set-context@v5
|
||||||
with:
|
with:
|
||||||
method: service-account
|
method: service-account
|
||||||
cluster-type: arc
|
cluster-type: arc
|
||||||
@ -86,7 +86,7 @@ kubectl get secret <service-account-secret-name> -n <namespace> -o yaml
|
|||||||
### Service principal approach for arc cluster
|
### Service principal approach for arc cluster
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: azure/k8s-set-context@v4
|
- uses: azure/k8s-set-context@v5
|
||||||
with:
|
with:
|
||||||
method: service-principal
|
method: service-principal
|
||||||
cluster-type: arc
|
cluster-type: arc
|
||||||
|
|||||||
@ -39,5 +39,5 @@ inputs:
|
|||||||
branding:
|
branding:
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node24'
|
||||||
main: 'lib/index.js'
|
main: 'lib/index.js'
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
// babel.config.js
|
|
||||||
export default {
|
|
||||||
presets: [
|
|
||||||
'@babel/preset-env', // For handling ES modules
|
|
||||||
'@babel/preset-typescript' // For handling TypeScript
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
export default {
|
|
||||||
restoreMocks: true,
|
|
||||||
clearMocks: true,
|
|
||||||
resetMocks: true,
|
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
|
||||||
testEnvironment: 'node',
|
|
||||||
testMatch: ['**/*.test.ts'],
|
|
||||||
transform: {
|
|
||||||
'^.+\\.ts$': 'ts-jest', // Use ts-jest for TypeScript files
|
|
||||||
'^.+\\.js$': 'babel-jest' // Transform TypeScript files
|
|
||||||
},
|
|
||||||
transformIgnorePatterns: [
|
|
||||||
'/node_modules/(?!@kubernetes/client-node)/' // Make sure to transform the Kubernetes client module
|
|
||||||
],
|
|
||||||
moduleNameMapper: {
|
|
||||||
'^.+\\.css$': 'jest-transform-stub' // Handle CSS imports (if any)
|
|
||||||
},
|
|
||||||
extensionsToTreatAsEsm: ['.ts', '.tsx'], // Treat TypeScript files as ESM
|
|
||||||
verbose: true,
|
|
||||||
coverageThreshold: {
|
|
||||||
global: {
|
|
||||||
branches: 0,
|
|
||||||
functions: 40,
|
|
||||||
lines: 22,
|
|
||||||
statements: 22
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11978
package-lock.json
generated
11978
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "k8s-set-context-action",
|
"name": "k8s-set-context-action",
|
||||||
"version": "4.0.2",
|
"version": "5.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "npm i @vercel/ncc",
|
"build": "tsc --noEmit && esbuild src/run.ts --bundle --platform=node --target=node20 --format=esm --outfile=lib/index.js --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\"",
|
||||||
"build": "ncc build src/run.ts -o lib",
|
"typecheck": "tsc --noEmit",
|
||||||
"test": "jest",
|
"test": "vitest run",
|
||||||
"test-coverage": "jest --coverage",
|
"test-coverage": "vitest run --coverage",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format-check": "prettier --check .",
|
"format-check": "prettier --check .",
|
||||||
"prepare": "husky"
|
"prepare": "husky"
|
||||||
@ -21,24 +21,19 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^3.0.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/io": "^2.0.0",
|
"@actions/io": "^3.0.2",
|
||||||
"@kubernetes/client-node": "^1.4.0",
|
"@kubernetes/client-node": "^1.4.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "^7.28.5",
|
|
||||||
"@babel/preset-typescript": "^7.28.5",
|
|
||||||
"@types/jest": "^30.0.0",
|
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@types/node": "^24.9.2",
|
"@types/node": "^25.5.2",
|
||||||
"@vercel/ncc": "^0.38.4",
|
"esbuild": "^0.28.0",
|
||||||
"babel-jest": "^30.2.0",
|
"prettier": "^3.8.0",
|
||||||
"jest": "^30.2.0",
|
"typescript": "^6.0.2",
|
||||||
"prettier": "^3.6.2",
|
"vitest": "^4.1.1"
|
||||||
"ts-jest": "^29.4.5",
|
|
||||||
"typescript": "^5.9.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import {getRequiredInputError} from '../tests/util'
|
import {vi, describe, it, expect} from 'vitest'
|
||||||
import {run} from './action'
|
import {getRequiredInputError} from '../tests/util.js'
|
||||||
import fs from 'fs'
|
import {run} from './action.js'
|
||||||
import * as utils from './utils'
|
|
||||||
|
vi.mock('fs')
|
||||||
|
vi.mock('./utils.js')
|
||||||
|
|
||||||
describe('Run', () => {
|
describe('Run', () => {
|
||||||
it('throws error without cluster type', async () => {
|
it('throws error without cluster type', async () => {
|
||||||
@ -9,22 +11,23 @@ describe('Run', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('writes kubeconfig and sets context', async () => {
|
it('writes kubeconfig and sets context', async () => {
|
||||||
|
const {getKubeconfig, setContext} = await import('./utils.js')
|
||||||
|
const fs = await import('fs')
|
||||||
const kubeconfig = 'kubeconfig'
|
const kubeconfig = 'kubeconfig'
|
||||||
|
|
||||||
process.env['INPUT_CLUSTER-TYPE'] = 'default'
|
process.env['INPUT_CLUSTER-TYPE'] = 'default'
|
||||||
process.env['RUNNER_TEMP'] = '/sample/path'
|
process.env['RUNNER_TEMP'] = '/sample/path'
|
||||||
|
|
||||||
jest
|
vi.mocked(getKubeconfig).mockResolvedValue(kubeconfig)
|
||||||
.spyOn(utils, 'getKubeconfig')
|
vi.mocked(setContext).mockReturnValue(kubeconfig)
|
||||||
.mockImplementation(async () => kubeconfig)
|
vi.mocked(fs.writeFileSync).mockImplementation(() => {})
|
||||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
vi.mocked(fs.chmodSync).mockImplementation(() => {})
|
||||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
|
||||||
jest.spyOn(utils, 'setContext').mockImplementation(() => kubeconfig)
|
|
||||||
|
|
||||||
expect(await run())
|
await run()
|
||||||
expect(utils.getKubeconfig).toHaveBeenCalled()
|
|
||||||
|
expect(getKubeconfig).toHaveBeenCalled()
|
||||||
expect(fs.writeFileSync).toHaveBeenCalled()
|
expect(fs.writeFileSync).toHaveBeenCalled()
|
||||||
expect(fs.chmodSync).toHaveBeenCalled()
|
expect(fs.chmodSync).toHaveBeenCalled()
|
||||||
expect(utils.setContext).toHaveBeenCalled()
|
expect(setContext).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import {Cluster, parseCluster} from './types/cluster'
|
import {Cluster, parseCluster} from './types/cluster.js'
|
||||||
import {setContext, getKubeconfig} from './utils'
|
import {setContext, getKubeconfig} from './utils.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Kubernetes context based on supplied action inputs
|
* Sets the Kubernetes context based on supplied action inputs
|
||||||
@ -14,7 +14,7 @@ export async function run() {
|
|||||||
required: true
|
required: true
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
|
const runnerTempDirectory: string = process.env['RUNNER_TEMP'] ?? ''
|
||||||
const kubeconfigPath: string = path.join(
|
const kubeconfigPath: string = path.join(
|
||||||
runnerTempDirectory,
|
runnerTempDirectory,
|
||||||
`kubeconfig_${Date.now()}`
|
`kubeconfig_${Date.now()}`
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import * as actions from '@actions/exec'
|
import {vi, describe, test, it, expect, beforeEach} from 'vitest'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import {getRequiredInputError} from '../../tests/util'
|
import {getRequiredInputError} from '../../tests/util.js'
|
||||||
import {getArcKubeconfig, KUBECONFIG_LOCATION} from './arc'
|
import {getArcKubeconfig, KUBECONFIG_LOCATION} from './arc.js'
|
||||||
import * as az from './azCommands'
|
import * as az from './azCommands.js'
|
||||||
|
|
||||||
|
vi.mock('@actions/io')
|
||||||
|
vi.mock('./azCommands.js')
|
||||||
|
|
||||||
describe('Arc kubeconfig', () => {
|
describe('Arc kubeconfig', () => {
|
||||||
test('it throws error without resource group', async () => {
|
test('it throws error without resource group', async () => {
|
||||||
@ -28,11 +31,11 @@ describe('Arc kubeconfig', () => {
|
|||||||
process.env['INPUT_RESOURCE-GROUP'] = group
|
process.env['INPUT_RESOURCE-GROUP'] = group
|
||||||
process.env['INPUT_CLUSTER-NAME'] = name
|
process.env['INPUT_CLUSTER-NAME'] = name
|
||||||
|
|
||||||
jest.spyOn(io, 'which').mockImplementation(async () => path)
|
vi.mocked(io.which).mockResolvedValue(path)
|
||||||
jest.spyOn(az, 'runAzCliCommand').mockImplementation(async () => {})
|
vi.mocked(az.runAzCliCommand).mockResolvedValue(undefined)
|
||||||
jest
|
vi.mocked(az.runAzKubeconfigCommandBlocking).mockResolvedValue(
|
||||||
.spyOn(az, 'runAzKubeconfigCommandBlocking')
|
kubeconfig
|
||||||
.mockImplementation(async () => kubeconfig)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error without method', async () => {
|
it('throws an error without method', async () => {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import {Method, parseMethod} from '../types/method'
|
import {Method, parseMethod} from '../types/method.js'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {runAzCliCommand, runAzKubeconfigCommandBlocking} from './azCommands'
|
import {runAzCliCommand, runAzKubeconfigCommandBlocking} from './azCommands.js'
|
||||||
|
|
||||||
const RUNNER_TEMP: string = process.env['RUNNER_TEMP'] || ''
|
const RUNNER_TEMP: string = process.env['RUNNER_TEMP'] || ''
|
||||||
export const KUBECONFIG_LOCATION: string = path.join(
|
export const KUBECONFIG_LOCATION: string = path.join(
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
|
import {vi, describe, test, expect, beforeEach} from 'vitest'
|
||||||
import * as actions from '@actions/exec'
|
import * as actions from '@actions/exec'
|
||||||
import {runAzCliCommand} from './azCommands'
|
import {runAzCliCommand} from './azCommands.js'
|
||||||
|
|
||||||
|
vi.mock('@actions/exec')
|
||||||
|
|
||||||
describe('Az commands', () => {
|
describe('Az commands', () => {
|
||||||
test('it runs an az cli command', async () => {
|
test('it runs an az cli command', async () => {
|
||||||
const path = 'path'
|
const path = 'path'
|
||||||
const args = ['args']
|
const args = ['args']
|
||||||
|
|
||||||
jest.spyOn(actions, 'exec').mockImplementation(async () => 0)
|
vi.mocked(actions.exec).mockResolvedValue(0)
|
||||||
|
|
||||||
expect(await runAzCliCommand(path, args))
|
await runAzCliCommand(path, args)
|
||||||
expect(actions.exec).toHaveBeenCalledWith(path, args, {})
|
expect(actions.exec).toHaveBeenCalledWith(path, args, {})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
import {ExecOptions, exec} from '@actions/exec'
|
||||||
import {exec} from '@actions/exec'
|
|
||||||
import {spawn} from 'child_process'
|
import {spawn} from 'child_process'
|
||||||
|
|
||||||
const AZ_TIMEOUT_SECONDS: number = 120
|
const AZ_TIMEOUT_SECONDS: number = 120
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
|
import {vi, describe, test, expect, beforeEach, afterEach} from 'vitest'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as core from '@actions/core'
|
import {getRequiredInputError} from '../../tests/util.js'
|
||||||
import {getRequiredInputError} from '../../tests/util'
|
import {createKubeconfig, getDefaultKubeconfig} from './default.js'
|
||||||
import {createKubeconfig, getDefaultKubeconfig} from './default'
|
|
||||||
|
|
||||||
describe('Default kubeconfig', () => {
|
describe('Default kubeconfig', () => {
|
||||||
test('it creates a kubeconfig with proper format', () => {
|
test('it creates a kubeconfig with proper format', () => {
|
||||||
@ -51,6 +51,11 @@ describe('Default kubeconfig', () => {
|
|||||||
process.env['INPUT_METHOD'] = 'default'
|
process.env['INPUT_METHOD'] = 'default'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
delete process.env['INPUT_KUBECONFIG']
|
||||||
|
delete process.env['INPUT_KUBECONFIG-ENCODING']
|
||||||
|
})
|
||||||
|
|
||||||
test('it throws error without kubeconfig', () => {
|
test('it throws error without kubeconfig', () => {
|
||||||
expect(() => getDefaultKubeconfig()).toThrow(
|
expect(() => getDefaultKubeconfig()).toThrow(
|
||||||
getRequiredInputError('kubeconfig')
|
getRequiredInputError('kubeconfig')
|
||||||
@ -66,39 +71,25 @@ describe('Default kubeconfig', () => {
|
|||||||
|
|
||||||
test('returns kubeconfig as plaintext when encoding is plaintext', () => {
|
test('returns kubeconfig as plaintext when encoding is plaintext', () => {
|
||||||
const kc = 'example kc'
|
const kc = 'example kc'
|
||||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
process.env['INPUT_KUBECONFIG'] = kc
|
||||||
if (name === 'method') return 'default'
|
process.env['INPUT_KUBECONFIG-ENCODING'] = 'plaintext'
|
||||||
if (name === 'kubeconfig-encoding') return 'plaintext'
|
|
||||||
if (name === 'kubeconfig') return kc
|
|
||||||
return ''
|
|
||||||
})
|
|
||||||
expect(getDefaultKubeconfig()).toBe(kc)
|
expect(getDefaultKubeconfig()).toBe(kc)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it gets default config through base64 kubeconfig input', () => {
|
test('it gets default config through base64 kubeconfig input', () => {
|
||||||
const kc = 'example kc'
|
const kc = 'example kc'
|
||||||
const base64Kc = Buffer.from(kc, 'utf-8').toString('base64')
|
const base64Kc = Buffer.from(kc, 'utf-8').toString('base64')
|
||||||
|
process.env['INPUT_KUBECONFIG'] = base64Kc
|
||||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
process.env['INPUT_KUBECONFIG-ENCODING'] = 'base64'
|
||||||
if (name === 'method') return 'default'
|
|
||||||
if (name === 'kubeconfig-encoding') return 'base64'
|
|
||||||
if (name === 'kubeconfig') return base64Kc
|
|
||||||
return ''
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(getDefaultKubeconfig()).toBe(kc)
|
expect(getDefaultKubeconfig()).toBe(kc)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it throws error for unknown kubeconfig-encoding', () => {
|
test('it throws error for unknown kubeconfig-encoding', () => {
|
||||||
const kc = 'example kc'
|
const kc = 'example kc'
|
||||||
const unknownEncoding = 'foobar'
|
process.env['INPUT_KUBECONFIG'] = kc
|
||||||
|
process.env['INPUT_KUBECONFIG-ENCODING'] = 'foobar'
|
||||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
|
||||||
if (name === 'method') return 'default'
|
|
||||||
if (name === 'kubeconfig-encoding') return unknownEncoding
|
|
||||||
if (name === 'kubeconfig') return kc
|
|
||||||
return ''
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(() => getDefaultKubeconfig()).toThrow(
|
expect(() => getDefaultKubeconfig()).toThrow(
|
||||||
"Invalid kubeconfig-encoding: 'foobar'. Must be 'plaintext' or 'base64'."
|
"Invalid kubeconfig-encoding: 'foobar'. Must be 'plaintext' or 'base64'."
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as jsyaml from 'js-yaml'
|
import * as jsyaml from 'js-yaml'
|
||||||
import {KubeConfig} from '@kubernetes/client-node'
|
import {KubeConfig} from '@kubernetes/client-node'
|
||||||
import {K8sSecret, parseK8sSecret} from '../types/k8sSecret'
|
import {K8sSecret, parseK8sSecret} from '../types/k8sSecret.js'
|
||||||
import {Method, parseMethod} from '../types/method'
|
import {Method, parseMethod} from '../types/method.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the kubeconfig based on provided method for a default Kubernetes cluster
|
* Gets the kubeconfig based on provided method for a default Kubernetes cluster
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import {run} from './action'
|
import {run} from './action.js'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
// Run the application
|
// Run the application
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import {Cluster, parseCluster} from './cluster'
|
import {describe, test, expect} from 'vitest'
|
||||||
|
import {Cluster, parseCluster} from './cluster.js'
|
||||||
|
|
||||||
describe('Cluster type', () => {
|
describe('Cluster type', () => {
|
||||||
test('it has required values', () => {
|
test('it has required values', () => {
|
||||||
const vals = <any>Object.values(Cluster)
|
const vals = Object.values(Cluster) as string[]
|
||||||
expect(vals.includes('arc')).toBe(true)
|
expect(vals.includes('arc')).toBe(true)
|
||||||
expect(vals.includes('generic')).toBe(true)
|
expect(vals.includes('generic')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -8,9 +8,10 @@ export enum Cluster {
|
|||||||
* @param str The cluster type (case insensitive)
|
* @param str The cluster type (case insensitive)
|
||||||
* @returns The Cluster enum or undefined if it can't be parsed
|
* @returns The Cluster enum or undefined if it can't be parsed
|
||||||
*/
|
*/
|
||||||
export const parseCluster = (str: string): Cluster | undefined =>
|
export const parseCluster = (str: string): Cluster | undefined => {
|
||||||
Cluster[
|
const key = Object.keys(Cluster).find(
|
||||||
Object.keys(Cluster).filter(
|
(k) =>
|
||||||
(k) => Cluster[k].toString().toLowerCase() === str.toLowerCase()
|
Cluster[k as keyof typeof Cluster].toLowerCase() === str.toLowerCase()
|
||||||
)[0] as keyof typeof Cluster
|
) as keyof typeof Cluster | undefined
|
||||||
]
|
return key !== undefined ? Cluster[key] : undefined
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {parseK8sSecret, K8sSecret} from './k8sSecret'
|
import {describe, test, expect} from 'vitest'
|
||||||
|
import {parseK8sSecret} from './k8sSecret.js'
|
||||||
|
|
||||||
describe('K8sSecret type', () => {
|
describe('K8sSecret type', () => {
|
||||||
describe('Parsing from any', () => {
|
describe('Parsing from any', () => {
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import {Method, parseMethod} from './method'
|
import {describe, test, expect} from 'vitest'
|
||||||
|
import {Method, parseMethod} from './method.js'
|
||||||
|
|
||||||
describe('Method type', () => {
|
describe('Method type', () => {
|
||||||
test('it has required values', () => {
|
test('it has required values', () => {
|
||||||
const vals = <any>Object.values(Method)
|
const vals = Object.values(Method) as string[]
|
||||||
expect(vals.includes('kubeconfig')).toBe(true)
|
expect(vals.includes('kubeconfig')).toBe(true)
|
||||||
expect(vals.includes('service-account')).toBe(true)
|
expect(vals.includes('service-account')).toBe(true)
|
||||||
expect(vals.includes('service-principal')).toBe(true)
|
expect(vals.includes('service-principal')).toBe(true)
|
||||||
|
|||||||
@ -9,9 +9,10 @@ export enum Method {
|
|||||||
* @param str The method (case insensitive)
|
* @param str The method (case insensitive)
|
||||||
* @returns The Method enum or undefined if it can't be parsed
|
* @returns The Method enum or undefined if it can't be parsed
|
||||||
*/
|
*/
|
||||||
export const parseMethod = (str: string): Method | undefined =>
|
export const parseMethod = (str: string): Method | undefined => {
|
||||||
Method[
|
const key = Object.keys(Method).find(
|
||||||
Object.keys(Method).filter(
|
(k) =>
|
||||||
(k) => Method[k].toString().toLowerCase() === str.toLowerCase()
|
Method[k as keyof typeof Method].toLowerCase() === str.toLowerCase()
|
||||||
)[0] as keyof typeof Method
|
) as keyof typeof Method | undefined
|
||||||
]
|
return key !== undefined ? Method[key] : undefined
|
||||||
|
}
|
||||||
|
|||||||
@ -1,25 +1,26 @@
|
|||||||
|
import {vi, describe, test, expect} from 'vitest'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import * as arc from './kubeconfigs/arc'
|
import * as arc from './kubeconfigs/arc.js'
|
||||||
import * as def from './kubeconfigs/default'
|
import * as def from './kubeconfigs/default.js'
|
||||||
import {Cluster} from './types/cluster'
|
import {Cluster} from './types/cluster.js'
|
||||||
import {getKubeconfig, setContext} from './utils'
|
import {getKubeconfig, setContext} from './utils.js'
|
||||||
|
|
||||||
describe('Utils', () => {
|
describe('Utils', () => {
|
||||||
describe('get kubeconfig', () => {
|
describe('get kubeconfig', () => {
|
||||||
test('it gets arc kubeconfig when type is arc', async () => {
|
test('it gets arc kubeconfig when type is arc', async () => {
|
||||||
const arcKubeconfig = 'arckubeconfig'
|
const arcKubeconfig = 'arckubeconfig'
|
||||||
jest
|
vi.spyOn(arc, 'getArcKubeconfig').mockImplementation(
|
||||||
.spyOn(arc, 'getArcKubeconfig')
|
async () => arcKubeconfig
|
||||||
.mockImplementation(async () => arcKubeconfig)
|
)
|
||||||
|
|
||||||
expect(await getKubeconfig(Cluster.ARC)).toBe(arcKubeconfig)
|
expect(await getKubeconfig(Cluster.ARC)).toBe(arcKubeconfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it defaults to default kubeconfig', async () => {
|
test('it defaults to default kubeconfig', async () => {
|
||||||
const defaultKubeconfig = 'arckubeconfig'
|
const defaultKubeconfig = 'arckubeconfig'
|
||||||
jest
|
vi.spyOn(def, 'getDefaultKubeconfig').mockImplementation(
|
||||||
.spyOn(def, 'getDefaultKubeconfig')
|
() => defaultKubeconfig
|
||||||
.mockImplementation(() => defaultKubeconfig)
|
)
|
||||||
|
|
||||||
expect(await getKubeconfig(undefined)).toBe(defaultKubeconfig)
|
expect(await getKubeconfig(undefined)).toBe(defaultKubeconfig)
|
||||||
expect(await getKubeconfig(Cluster.GENERIC)).toBe(defaultKubeconfig)
|
expect(await getKubeconfig(Cluster.GENERIC)).toBe(defaultKubeconfig)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import {KubeConfig} from '@kubernetes/client-node'
|
import {KubeConfig} from '@kubernetes/client-node'
|
||||||
import {getDefaultKubeconfig} from './kubeconfigs/default'
|
import {getDefaultKubeconfig} from './kubeconfigs/default.js'
|
||||||
import {getArcKubeconfig} from './kubeconfigs/arc'
|
import {getArcKubeconfig} from './kubeconfigs/arc.js'
|
||||||
import {Cluster} from './types/cluster'
|
import {Cluster} from './types/cluster.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the kubeconfig based on Kubernetes cluster type
|
* Gets the kubeconfig based on Kubernetes cluster type
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"target": "ES2020",
|
||||||
"module": "ESNext", // or "NodeNext" depending on your setup
|
"module": "NodeNext",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true,
|
"rootDir": "./src",
|
||||||
"allowSyntheticDefaultImports": true,
|
"outDir": "./lib",
|
||||||
|
"noImplicitAny": false,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"paths": {
|
"noEmit": true,
|
||||||
"@actions/core": ["node_modules/@actions/core"],
|
"types": ["node", "vitest/globals"]
|
||||||
"@kubernetes/client-node": ["node_modules/@kubernetes/client-node"]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "tests", "src/**/*.test.ts"]
|
"exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts", "tests/"]
|
||||||
}
|
}
|
||||||
|
|||||||
10
vitest.config.ts
Normal file
10
vitest.config.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import {defineConfig} from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
globals: true,
|
||||||
|
environment: 'node',
|
||||||
|
include: ['**/*.test.ts'],
|
||||||
|
clearMocks: true
|
||||||
|
}
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user