mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-25 08:19:27 +08:00
Vidya reddy pretty code (#53)
* updated action file with node16 * Code consistency using prettier and its workflow * Enforce Prettier * code fix * code fix * code fix Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>
This commit is contained in:
+29
-29
@@ -1,9 +1,9 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as fs from "fs";
|
||||
import { KubeConfig } from "@kubernetes/client-node";
|
||||
import { getDefaultKubeconfig } from "./kubeconfigs/default";
|
||||
import { getArcKubeconfig } from "./kubeconfigs/arc";
|
||||
import { Cluster } from "./types/cluster";
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import {KubeConfig} from '@kubernetes/client-node'
|
||||
import {getDefaultKubeconfig} from './kubeconfigs/default'
|
||||
import {getArcKubeconfig} from './kubeconfigs/arc'
|
||||
import {Cluster} from './types/cluster'
|
||||
|
||||
/**
|
||||
* Gets the kubeconfig based on Kubernetes cluster type
|
||||
@@ -11,19 +11,19 @@ import { Cluster } from "./types/cluster";
|
||||
* @returns A promise of the kubeconfig
|
||||
*/
|
||||
export async function getKubeconfig(
|
||||
type: Cluster | undefined
|
||||
type: Cluster | undefined
|
||||
): Promise<string> {
|
||||
switch (type) {
|
||||
case Cluster.ARC: {
|
||||
return await getArcKubeconfig();
|
||||
}
|
||||
case undefined: {
|
||||
core.warning("Cluster type not recognized. Defaulting to generic.");
|
||||
}
|
||||
default: {
|
||||
return getDefaultKubeconfig();
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case Cluster.ARC: {
|
||||
return await getArcKubeconfig()
|
||||
}
|
||||
case undefined: {
|
||||
core.warning('Cluster type not recognized. Defaulting to generic.')
|
||||
}
|
||||
default: {
|
||||
return getDefaultKubeconfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,17 +32,17 @@ export async function getKubeconfig(
|
||||
* @returns Updated kubeconfig with the context
|
||||
*/
|
||||
export function setContext(kubeconfig: string): string {
|
||||
const context: string = core.getInput("context");
|
||||
if (!context) {
|
||||
core.debug("Can't set context because context is unspecified.");
|
||||
return kubeconfig;
|
||||
}
|
||||
const context: string = core.getInput('context')
|
||||
if (!context) {
|
||||
core.debug("Can't set context because context is unspecified.")
|
||||
return kubeconfig
|
||||
}
|
||||
|
||||
// load current kubeconfig
|
||||
const kc = new KubeConfig();
|
||||
kc.loadFromString(kubeconfig);
|
||||
// load current kubeconfig
|
||||
const kc = new KubeConfig()
|
||||
kc.loadFromString(kubeconfig)
|
||||
|
||||
// update kubeconfig
|
||||
kc.setCurrentContext(context);
|
||||
return kc.exportConfig();
|
||||
// update kubeconfig
|
||||
kc.setCurrentContext(context)
|
||||
return kc.exportConfig()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user