Skip to content

Commit 4564892

Browse files
committed
Improve support for two (or more) clusters
1 parent 7e82db0 commit 4564892

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

functions/kubernetes/k8sCommand.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ async function k8sCommand(ins, outs, context, cb) {
1111
// let cluster = await getCluster();
1212
// const token = await getGCPToken();
1313

14-
// support for two clusters (cloud bursting)
15-
// if 'HF_VAR_REMOTE_CLUSTER' is defined, we check where this job is assigned to:
16-
// - the local cluster: we do nothing
17-
// - the remote cluster: we set KUBECONFIG to load its configuration
18-
var remoteClusterId = process.env.HF_VAR_REMOTE_CLUSTER;
19-
if (remoteClusterId) {
20-
let partition = context.executor.partition;
21-
if (partition == remoteClusterId) {
22-
// this will cause reading the kube_config of the remote cluster
23-
process.env.KUBECONFIG = process.env.HF_VAR_KUBE_CONFIG_PATH || "./kube_config";
24-
}
14+
// support for two (or more) clusters (for cloud bursting)
15+
// if 'partition' is defined, check if there is a custom config file
16+
// for that partition. This config file may override parameters of the job,
17+
// possibly even define a path to a different kube_config to be loaded
18+
let partition = context.executor.partition;
19+
let partitionConfigDir = process.env.HF_VAR_PARTITION_CONFIG_DIR || "/opt/hyperflow/partitions";
20+
let partitionConfigFile = partitionConfigDir + "/" + "part." + partition + ".config.json";
21+
22+
// custom parameters for the job YAML template (will overwrite default values)
23+
var customParams = {};
24+
try {
25+
// if file exists, all configuration parameters will be read to 'customParams'
26+
let rawdata = fs.readFileSync(partitionConfigFile);
27+
customParams = JSON.parse(rawdata);
28+
} catch {
29+
}
30+
console.log(partitionConfigFile);
31+
console.log("CUSTOM...", customParams);
32+
33+
// Set kube_config path if overridden
34+
if (customParams.kubeConfigPath) {
35+
process.env.KUBECONFIG = customParams.kubeConfigPath;
36+
console.log(process.env.KUBECONFIG);
2537
}
2638

2739
const kubeconfig = new k8s.KubeConfig();
@@ -32,9 +44,6 @@ async function k8sCommand(ins, outs, context, cb) {
3244
job.ins = ins;
3345
job.outs = outs;
3446

35-
// custom parameters to the job YAML template (will overwrite default values)
36-
var customParams = {};
37-
3847
let jobExitCode = await submitK8sJob(kubeconfig, job, context.taskId, context, customParams);
3948

4049
let endTime = Date.now();

functions/kubernetes/k8sJobSubmit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var submitK8sJob = async(kubeconfig, job, taskId, context, customParams) => {
101101
var jobMessage = jobSpec.jobMessage;
102102

103103
// Test mode -- just print, do not actually create jobs
104-
if (process.env.HF_VAR_K8S_TEST) {
104+
if (process.env.HF_VAR_K8S_TEST=="1") {
105105
console.log(JSON.stringify(jobYaml, null, 4));
106106
console.log(JSON.stringify(jobMessage, null, 2));
107107
return 0;

0 commit comments

Comments
 (0)