15 Commits
v3.1 ... v4.0.0

Author SHA1 Message Date
27bfb38730 build 2024-02-13 20:45:12 +00:00
a72463cdd7 v4 release (#84) 2024-02-13 15:44:18 -05:00
f2d80c8192 Update to Node 20 (#83) 2024-02-13 15:07:04 -05:00
3624a1fc64 separate action and execution (#77) 2023-01-27 14:49:09 -05:00
ab43e1cba5 Bump minimatch from 3.0.4 to 3.1.2 (#74)
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-26 14:07:12 -05:00
f7b05df5e5 Bump json5 from 2.2.1 to 2.2.3 (#75)
Bumps [json5](https://github.com/json5/json5) from 2.2.1 to 2.2.3.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v2.2.1...v2.2.3)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-26 13:25:42 -05:00
6332864ca0 Update README with v3 version (#72) 2023-01-09 12:32:46 -06:00
d7e25ce077 Bump qs from 6.5.2 to 6.5.3 (#73)
Bumps [qs](https://github.com/ljharb/qs) from 6.5.2 to 6.5.3.
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.5.2...v6.5.3)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-12 13:44:07 -05:00
0689e8a931 Update @actions/core (#68)
to address https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
2022-11-02 10:25:00 -04:00
03c6fe6b8a Bump jose from 2.0.5 to 2.0.6 (#65)
Bumps [jose](https://github.com/panva/jose) from 2.0.5 to 2.0.6.
- [Release notes](https://github.com/panva/jose/releases)
- [Changelog](https://github.com/panva/jose/blob/v2.0.6/CHANGELOG.md)
- [Commits](https://github.com/panva/jose/compare/v2.0.5...v2.0.6)

---
updated-dependencies:
- dependency-name: jose
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-03 13:34:45 -04:00
b0cfd07ecc Systax error fixes (#64) 2022-09-19 09:47:11 -07:00
ccc0c881dc Added the bug report and feature request form (#63)
* Added the bug report and feature request form

* updated the url
2022-09-06 17:33:42 -04:00
e617f31159 Bump @actions/core from 1.2.6 to 1.9.1 (#62)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.6 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-22 13:40:02 -04:00
778581b6aa Vidya reddy/vercel ncc (#58)
* updated action file with node16

* Code consistency using prettier and its workflow

* Enforce Prettier

* code fix

* code fix

* code fix

* add vercel/ncc to build script

* modified action file

Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>
2022-07-05 10:17:19 -07:00
6331e961d2 fix broken build - switch to ncc build (#56)
* switch to ncc build

* update

* bump ncc
2022-06-30 16:24:00 -04:00
16 changed files with 192803 additions and 287 deletions

View File

@ -0,0 +1,36 @@
name: Bug Report
description: File a bug report specifying all inputs you provided for the action, we will respond to this thread with any questions.
title: 'Bug: '
labels: ['bug', 'triage']
assignees: '@Azure/aks-atlanta'
body:
- type: textarea
id: What-happened
attributes:
label: What happened?
description: Tell us what happened and how is it different from the expected?
placeholder: Tell us what you see!
validations:
required: true
- type: checkboxes
id: Version
attributes:
label: Version
options:
- label: I am using the latest version
required: true
- type: input
id: Runner
attributes:
label: Runner
description: What runner are you using?
placeholder: Mention the runner info (self-hosted, operating system)
validations:
required: true
- type: textarea
id: Logs
attributes:
label: Relevant log output
description: Run in debug mode for the most verbose logs. Please feel free to attach a screenshot of the logs
validations:
required: true

6
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,6 @@
blank_issues_enabled: false
contact_links:
- name: GitHub Action "k8s-set-context" Support
url: https://github.com/Azure/k8s-set-context
security: https://github.com/Azure/k8s-set-context/blob/main/SECURITY.md
about: Please ask and answer questions here.

View File

@ -0,0 +1,13 @@
name: Feature Request
description: File a Feature Request form, we will respond to this thread with any questions.
title: 'Feature Request: '
labels: ['Feature']
assignees: '@Azure/aks-atlanta'
body:
- type: textarea
id: Feature_request
attributes:
label: Feature request
description: Provide example functionality and links to relevant docs
validations:
required: true

View File

@ -20,7 +20,8 @@ jobs:
id: npm-build
run: |
npm install
npm run build
- name: Build
run: npm run build
- name: Set Context
uses: ./
with:

View File

@ -1,14 +1,18 @@
name: Create release PR
name: Release Project
on:
push:
branches:
- main
paths:
- CHANGELOG.md
workflow_dispatch:
inputs:
release:
description: 'Define release version (ex: v1, v2, v3)'
required: true
jobs:
release-pr:
uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
release:
permissions:
actions: read
contents: write
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@a705b2ab6a3ee889f2b0d925ad0bd2f9eb733ce6
with:
release: ${{ github.event.inputs.release }}
changelogPath: ./CHANGELOG.md

1
.gitignore vendored
View File

@ -331,4 +331,3 @@ node_modules
coverage
# Transpiled JS
lib/

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
# Change Log
## [4.0.0] - 2024-02-13
- #83 update to node20 as node16 is deprecated

View File

@ -19,7 +19,7 @@ Refer to the [action metadata file](./action.yml) for details about inputs. Note
### Kubeconfig approach
```yaml
- uses: azure/k8s-set-context@v2
- uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: <your kubeconfig>
@ -50,7 +50,7 @@ Please refer to documentation on fetching [kubeconfig for any generic K8s cluste
### Service account approach
```yaml
- uses: azure/k8s-set-context@v2
- uses: azure/k8s-set-context@v3
with:
method: service-account
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
```yaml
- uses: azure/k8s-set-context@v2
- uses: azure/k8s-set-context@v3
with:
method: service-account
cluster-type: arc
@ -86,7 +86,7 @@ kubectl get secret <service-account-secret-name> -n <namespace> -o yaml
### Service principal approach for arc cluster
```yaml
- uses: azure/k8s-set-context@v2
- uses: azure/k8s-set-context@v3
with:
method: service-principal
cluster-type: arc

View File

@ -35,5 +35,5 @@ inputs:
branding:
color: 'blue'
runs:
using: 'node16'
main: 'lib/run.js'
using: 'node20'
main: 'lib/index.js'

39
lib/exec-child.js Normal file
View File

@ -0,0 +1,39 @@
if (require.main !== module) {
throw new Error('This file should not be required');
}
var childProcess = require('child_process');
var fs = require('fs');
var paramFilePath = process.argv[2];
var serializedParams = fs.readFileSync(paramFilePath, 'utf8');
var params = JSON.parse(serializedParams);
var cmd = params.command;
var execOptions = params.execOptions;
var pipe = params.pipe;
var stdoutFile = params.stdoutFile;
var stderrFile = params.stderrFile;
var c = childProcess.exec(cmd, execOptions, function (err) {
if (!err) {
process.exitCode = 0;
} else if (err.code === undefined) {
process.exitCode = 1;
} else {
process.exitCode = err.code;
}
});
var stdoutStream = fs.createWriteStream(stdoutFile);
var stderrStream = fs.createWriteStream(stderrFile);
c.stdout.pipe(stdoutStream);
c.stderr.pipe(stderrStream);
c.stdout.pipe(process.stdout);
c.stderr.pipe(process.stderr);
if (pipe) {
c.stdin.end(pipe);
}

192191
lib/index.js Normal file

File diff suppressed because one or more lines are too long

686
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
{
"name": "k8s-set-context-action",
"version": "1.0.0",
"version": "4.0.0",
"private": true,
"main": "lib/run.js",
"main": "lib/index.js",
"scripts": {
"build": "tsc --outDir ./lib --rootDir ./src",
"prebuild": "npm i @vercel/ncc",
"build": "ncc build src/run.ts -o lib",
"test": "jest",
"test-coverage": "jest --coverage",
"format": "prettier --write .",
@ -18,7 +19,7 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.0.0",
"@actions/io": "^1.1.2",
"@kubernetes/client-node": "^0.16.0",
@ -28,6 +29,7 @@
"@types/jest": "^28.1.2",
"@types/js-yaml": "^4.0.4",
"@types/node": "^16.0.0",
"@vercel/ncc": "^0.34.0",
"jest": "^28.1.1",
"prettier": "2.7.1",
"ts-jest": "^28.0.5",

View File

@ -1,5 +1,5 @@
import {getRequiredInputError} from '../tests/util'
import {run} from './run'
import {run} from './action'
import fs from 'fs'
import * as utils from './utils'

33
src/action.ts Normal file
View File

@ -0,0 +1,33 @@
import * as core from '@actions/core'
import * as path from 'path'
import * as fs from 'fs'
import {Cluster, parseCluster} from './types/cluster'
import {setContext, getKubeconfig} from './utils'
/**
* Sets the Kubernetes context based on supplied action inputs
*/
export async function run() {
// get inputs
const clusterType: Cluster | undefined = parseCluster(
core.getInput('cluster-type', {
required: true
})
)
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
const kubeconfigPath: string = path.join(
runnerTempDirectory,
`kubeconfig_${Date.now()}`
)
// get kubeconfig and update context
const kubeconfig: string = await getKubeconfig(clusterType)
const kubeconfigWithContext: string = setContext(kubeconfig)
// output kubeconfig
core.debug(`Writing kubeconfig contents to ${kubeconfigPath}`)
fs.writeFileSync(kubeconfigPath, kubeconfigWithContext)
fs.chmodSync(kubeconfigPath, '600')
core.debug('Setting KUBECONFIG environment variable')
core.exportVariable('KUBECONFIG', kubeconfigPath)
}

View File

@ -1,36 +1,5 @@
import {run} from './action'
import * as core from '@actions/core'
import * as path from 'path'
import * as fs from 'fs'
import {Cluster, parseCluster} from './types/cluster'
import {setContext, getKubeconfig} from './utils'
/**
* Sets the Kubernetes context based on supplied action inputs
*/
export async function run() {
// get inputs
const clusterType: Cluster | undefined = parseCluster(
core.getInput('cluster-type', {
required: true
})
)
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
const kubeconfigPath: string = path.join(
runnerTempDirectory,
`kubeconfig_${Date.now()}`
)
// get kubeconfig and update context
const kubeconfig: string = await getKubeconfig(clusterType)
const kubeconfigWithContext: string = setContext(kubeconfig)
// output kubeconfig
core.debug(`Writing kubeconfig contents to ${kubeconfigPath}`)
fs.writeFileSync(kubeconfigPath, kubeconfigWithContext)
fs.chmodSync(kubeconfigPath, '600')
core.debug('Setting KUBECONFIG environment variable')
core.exportVariable('KUBECONFIG', kubeconfigPath)
}
// Run the application
run().catch(core.setFailed)