use @kubernetes/client-node to generate default config (#51)

This commit is contained in:
Sigurd Fosseng
2022-06-22 16:58:10 +02:00
committed by GitHub
parent b19619f34c
commit e972a5b196
4 changed files with 2248 additions and 9338 deletions
+15 -21
View File
@@ -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();
}