mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-07-01 04:09:27 +08:00
Refactor entire project (#39)
- Use more modern TypeScript conventions - Use JavaScript Kubernetes Client - Add unit tests - Add integration tests - Add TypeScript compile verify workflow - Switch codeowners
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
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