Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
27bfb38730 | |||
a72463cdd7 | |||
f2d80c8192 | |||
3624a1fc64 | |||
ab43e1cba5 | |||
f7b05df5e5 | |||
6332864ca0 | |||
d7e25ce077 | |||
0689e8a931 | |||
03c6fe6b8a | |||
b0cfd07ecc | |||
ccc0c881dc | |||
e617f31159 | |||
778581b6aa | |||
6331e961d2 |
36
.github/ISSUE_TEMPLATE/bugReportForm.yml
vendored
Normal file
36
.github/ISSUE_TEMPLATE/bugReportForm.yml
vendored
Normal 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
6
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal 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.
|
13
.github/ISSUE_TEMPLATE/featureRequestForm.yml
vendored
Normal file
13
.github/ISSUE_TEMPLATE/featureRequestForm.yml
vendored
Normal 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
|
3
.github/workflows/integration-tests.yml
vendored
3
.github/workflows/integration-tests.yml
vendored
@ -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:
|
||||
|
20
.github/workflows/release-pr.yml
vendored
20
.github/workflows/release-pr.yml
vendored
@ -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
1
.gitignore
vendored
@ -331,4 +331,3 @@ node_modules
|
||||
coverage
|
||||
|
||||
# Transpiled JS
|
||||
lib/
|
||||
|
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Change Log
|
||||
|
||||
## [4.0.0] - 2024-02-13
|
||||
|
||||
- #83 update to node20 as node16 is deprecated
|
@ -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
|
||||
|
@ -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
39
lib/exec-child.js
Normal 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
192191
lib/index.js
Normal file
File diff suppressed because one or more lines are too long
686
package-lock.json
generated
686
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -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",
|
||||
|
@ -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
33
src/action.ts
Normal 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)
|
||||
}
|
33
src/run.ts
33
src/run.ts
@ -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)
|
||||
|
Reference in New Issue
Block a user