cherry-picked v1.1 commit
This commit is contained in:
41
lib/login.js
41
lib/login.js
@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.run = exports.setContext = exports.getKubectlPath = exports.getExecutableExtension = exports.getKubeconfig = void 0;
|
||||
const core = require("@actions/core");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
@ -19,6 +18,7 @@ const os = require("os");
|
||||
const toolrunner_1 = require("@actions/exec/lib/toolrunner");
|
||||
const jsyaml = require("js-yaml");
|
||||
const util = require("util");
|
||||
const arc_login_1 = require("./arc-login");
|
||||
function getKubeconfig() {
|
||||
const method = core.getInput('method', { required: true });
|
||||
if (method == 'kubeconfig') {
|
||||
@ -31,7 +31,7 @@ function getKubeconfig() {
|
||||
core.debug("Found clusterUrl, creating kubeconfig using certificate and token");
|
||||
let k8sSecret = core.getInput('k8s-secret', { required: true });
|
||||
var parsedk8sSecret = jsyaml.safeLoad(k8sSecret);
|
||||
let kubernetesServiceAccountSecretFieldNotPresent = 'The service account secret yaml does not contain %s; field. Make sure that its present and try again.';
|
||||
let kubernetesServiceAccountSecretFieldNotPresent = 'The service acount secret yaml does not contain %s; field. Make sure that its present and try again.';
|
||||
if (!parsedk8sSecret) {
|
||||
throw Error("The service account secret yaml specified is invalid. Make sure that its a valid yaml and try again.");
|
||||
}
|
||||
@ -71,14 +71,12 @@ function getKubeconfig() {
|
||||
throw Error("Invalid method specified. Acceptable values are kubeconfig and service-account.");
|
||||
}
|
||||
}
|
||||
exports.getKubeconfig = getKubeconfig;
|
||||
function getExecutableExtension() {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
exports.getExecutableExtension = getExecutableExtension;
|
||||
function getKubectlPath() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let kubectlPath = yield io.which('kubectl', false);
|
||||
@ -93,7 +91,6 @@ function getKubectlPath() {
|
||||
return kubectlPath;
|
||||
});
|
||||
}
|
||||
exports.getKubectlPath = getKubectlPath;
|
||||
function setContext(kubeconfigPath) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let context = core.getInput('context');
|
||||
@ -108,19 +105,31 @@ function setContext(kubeconfigPath) {
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.setContext = setContext;
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let kubeconfig = getKubeconfig();
|
||||
const runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
|
||||
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
|
||||
core.debug(`Writing kubeconfig contents to ${kubeconfigPath}`);
|
||||
fs.writeFileSync(kubeconfigPath, kubeconfig);
|
||||
fs.chmodSync(kubeconfigPath, '600');
|
||||
core.exportVariable('KUBECONFIG', kubeconfigPath);
|
||||
console.log('KUBECONFIG environment variable is set');
|
||||
yield setContext(kubeconfigPath);
|
||||
try {
|
||||
let kubeconfig = '';
|
||||
const cluster_type = core.getInput('cluster-type', { required: true });
|
||||
if (cluster_type == 'arc') {
|
||||
yield arc_login_1.getArcKubeconfig().catch(ex => {
|
||||
throw new Error('Error: Could not get the KUBECONFIG for arc cluster: ' + ex);
|
||||
});
|
||||
}
|
||||
else {
|
||||
const runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
|
||||
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
|
||||
kubeconfig = getKubeconfig();
|
||||
core.debug(`Writing kubeconfig contents to ${kubeconfigPath}`);
|
||||
fs.writeFileSync(kubeconfigPath, kubeconfig);
|
||||
fs.chmodSync(kubeconfigPath, '600');
|
||||
core.exportVariable('KUBECONFIG', kubeconfigPath);
|
||||
console.log('KUBECONFIG environment variable is set');
|
||||
yield setContext(kubeconfigPath);
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.run = run;
|
||||
run().catch(core.setFailed);
|
||||
|
Reference in New Issue
Block a user