-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from datawire/rlane/formatting
Auto-formatting Javascript files
- Loading branch information
Showing
11 changed files
with
590 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
const core = require('@actions/core') | ||
const core = require("@actions/core"); | ||
|
||
const registry = require('./lib/registry.js') | ||
const utils = require('./lib/utils.js') | ||
const registry = require("./lib/registry.js"); | ||
const utils = require("./lib/utils.js"); | ||
|
||
async function create() { | ||
// inputs are defined in action metadata file | ||
const distribution = core.getInput('distribution') | ||
const action = core.getInput('action') | ||
const version = core.getInput('version') | ||
const lifespan = core.getInput('lifespan') | ||
const kubeconfigPath = core.getInput('kubeconfig') | ||
const distribution = core.getInput("distribution"); | ||
const action = core.getInput("action"); | ||
const version = core.getInput("version"); | ||
const lifespan = core.getInput("lifespan"); | ||
const kubeconfigPath = core.getInput("kubeconfig"); | ||
|
||
let provider = registry.getProvider(distribution) | ||
let provider = registry.getProvider(distribution); | ||
|
||
if (action === 'expire') { | ||
return | ||
if (action === "expire") { | ||
return; | ||
} | ||
|
||
core.notice(`Creating ${distribution} ${version} and writing kubeconfig to file: ${kubeconfigPath}!`) | ||
let cluster = await provider.allocateCluster(version, lifespan) | ||
core.saveState(registry.CLUSTER_NAME, cluster.name) | ||
core.notice( | ||
`Creating ${distribution} ${version} and writing kubeconfig to file: ${kubeconfigPath}!` | ||
); | ||
let cluster = await provider.allocateCluster(version, lifespan); | ||
core.saveState(registry.CLUSTER_NAME, cluster.name); | ||
|
||
core.setOutput("clusterName", cluster?.name); | ||
core.setOutput("projectId", cluster?.project); | ||
core.setOutput("location", cluster?.zone); | ||
|
||
core.notice(`Creating ${distribution} cluster ${cluster.name} ...`) | ||
let kubeconfig = await provider.makeKubeconfig(cluster) | ||
core.notice(`Cluster created: ${cluster.name}!`) | ||
let contents = JSON.stringify(kubeconfig, undefined, 2) + "\n" | ||
utils.writeFile(kubeconfigPath, contents) | ||
core.notice(`Creating ${distribution} cluster ${cluster.name} ...`); | ||
let kubeconfig = await provider.makeKubeconfig(cluster); | ||
core.notice(`Cluster created: ${cluster.name}!`); | ||
let contents = JSON.stringify(kubeconfig, undefined, 2) + "\n"; | ||
utils.writeFile(kubeconfigPath, contents); | ||
|
||
core.notice(`Kubeconfig written to ${kubeconfigPath}.`) | ||
core.notice(`Exporting KUBECONFIG as ${kubeconfigPath}`) | ||
core.exportVariable("KUBECONFIG", kubeconfigPath) | ||
core.notice(`Kubeconfig written to ${kubeconfigPath}.`); | ||
core.notice(`Exporting KUBECONFIG as ${kubeconfigPath}`); | ||
core.exportVariable("KUBECONFIG", kubeconfigPath); | ||
} | ||
|
||
create().catch((error)=>{ | ||
core.setFailed(error.message) | ||
}) | ||
create().catch((error) => { | ||
core.setFailed(error.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
const core = require('@actions/core') | ||
const core = require("@actions/core"); | ||
|
||
const registry = require('./lib/registry.js') | ||
const slack = require('./lib/slack.js') | ||
const registry = require("./lib/registry.js"); | ||
const slack = require("./lib/slack.js"); | ||
|
||
async function do_delete() { | ||
// inputs are defined in action metadata file | ||
const distribution = core.getInput('distribution') | ||
const clusterName = core.getState(registry.CLUSTER_NAME) | ||
const distribution = core.getInput("distribution"); | ||
const clusterName = core.getState(registry.CLUSTER_NAME); | ||
|
||
let provider = registry.getProvider(distribution) | ||
let provider = registry.getProvider(distribution); | ||
|
||
let promises = [] | ||
promises.push(expire(provider, distribution)) | ||
let promises = []; | ||
promises.push(expire(provider, distribution)); | ||
|
||
if (typeof clusterName !== typeof undefined && clusterName !== "") { | ||
core.notice(`Deleting ${distribution} cluster ${clusterName}!`) | ||
promises.push(delete_allocated(provider, clusterName)) | ||
core.notice(`Deleting ${distribution} cluster ${clusterName}!`); | ||
promises.push(delete_allocated(provider, clusterName)); | ||
} | ||
|
||
return Promise.all(promises) | ||
return Promise.all(promises); | ||
} | ||
|
||
async function expire(provider) { | ||
let orphaned = await provider.expireClusters() | ||
let orphaned = await provider.expireClusters(); | ||
|
||
if (orphaned.length == 0) { | ||
return | ||
return; | ||
} | ||
|
||
core.notice(`Orphaned Clusters: ${orphaned.join(', ')}`) | ||
slack.notify(`Orphaned clusters:\n\n - ${orphaned.join("\n - ")}`) | ||
core.notice(`Orphaned Clusters: ${orphaned.join(", ")}`); | ||
slack.notify(`Orphaned clusters:\n\n - ${orphaned.join("\n - ")}`); | ||
} | ||
|
||
async function delete_allocated(provider, name) { | ||
let cluster = await provider.getCluster(name) | ||
return provider.deleteCluster(cluster) | ||
let cluster = await provider.getCluster(name); | ||
return provider.deleteCluster(cluster); | ||
} | ||
|
||
do_delete().catch((error)=>{ | ||
core.setFailed(error.message) | ||
}) | ||
do_delete().catch((error) => { | ||
core.setFailed(error.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
'use string'; | ||
"use string"; | ||
|
||
const mock = require('./mock.js') | ||
let MOCK = mock.MOCK | ||
let cluster = mock.cluster | ||
const mock = require("./mock.js"); | ||
let MOCK = mock.MOCK; | ||
let cluster = mock.cluster; | ||
|
||
async function lifecycle(client) { | ||
let allocated = await client.allocateCluster('1.22', 300) | ||
let kubeconfig = await client.makeKubeconfig(allocated) | ||
expect(kubeconfig).toEqual( | ||
{ | ||
"apiVersion": "v1", | ||
"kind":"Config", | ||
"clusters": [{ | ||
"cluster": { | ||
let allocated = await client.allocateCluster("1.22", 300); | ||
let kubeconfig = await client.makeKubeconfig(allocated); | ||
expect(kubeconfig).toEqual({ | ||
apiVersion: "v1", | ||
kind: "Config", | ||
clusters: [ | ||
{ | ||
cluster: { | ||
"certificate-authority-data": cluster.masterAuth.clusterCaCertificate, | ||
"server":"https://34.172.65.239" | ||
server: "https://34.172.65.239", | ||
}, | ||
"name":"gke-cluster" | ||
}], | ||
"users": [{ | ||
"name":"gke-user", | ||
"user":{ | ||
"token":MOCK.ACCESS_TOKEN | ||
}}], | ||
"contexts": [{ | ||
"context":{"cluster":"gke-cluster","namespace":"default","user":"gke-user"}, | ||
"name":"gke-context"}], | ||
"current-context":"gke-context" | ||
}) | ||
name: "gke-cluster", | ||
}, | ||
], | ||
users: [ | ||
{ | ||
name: "gke-user", | ||
user: { | ||
token: MOCK.ACCESS_TOKEN, | ||
}, | ||
}, | ||
], | ||
contexts: [ | ||
{ | ||
context: { | ||
cluster: "gke-cluster", | ||
namespace: "default", | ||
user: "gke-user", | ||
}, | ||
name: "gke-context", | ||
}, | ||
], | ||
"current-context": "gke-context", | ||
}); | ||
|
||
let op = await client.deleteCluster(cluster) | ||
expect(op.done).toBeTruthy() | ||
let op = await client.deleteCluster(cluster); | ||
expect(op.done).toBeTruthy(); | ||
} | ||
|
||
module.exports = { lifecycle } | ||
module.exports = { lifecycle }; |
Oops, something went wrong.