mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-27 17:49:27 +08:00
use @kubernetes/client-node to generate default config (#51)
This commit is contained in:
+15
-21
@@ -1,5 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as jsyaml from "js-yaml";
|
||||
import { KubeConfig } from "@kubernetes/client-node";
|
||||
import { K8sSecret, parseK8sSecret } from "../types/k8sSecret";
|
||||
import { Method, parseMethod } from "../types/method";
|
||||
|
||||
@@ -58,25 +59,18 @@ export function createKubeconfig(
|
||||
token: string,
|
||||
clusterUrl: string
|
||||
): string {
|
||||
const kubeconfig = {
|
||||
apiVersion: "v1",
|
||||
kind: "Config",
|
||||
clusters: [
|
||||
{
|
||||
cluster: {
|
||||
"certificate-authority-data": certAuth,
|
||||
server: clusterUrl,
|
||||
},
|
||||
},
|
||||
],
|
||||
users: [
|
||||
{
|
||||
user: {
|
||||
token: token,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return JSON.stringify(kubeconfig);
|
||||
const kc = new KubeConfig();
|
||||
kc.loadFromClusterAndUser(
|
||||
{
|
||||
name: "default",
|
||||
server: clusterUrl,
|
||||
caData: certAuth,
|
||||
skipTLSVerify: false,
|
||||
},
|
||||
{
|
||||
name: "default-user",
|
||||
token,
|
||||
}
|
||||
);
|
||||
return kc.exportConfig();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user