Skip to content

Commit

Permalink
Merge pull request #17 from ThinkDeepTech/hm/init-impl
Browse files Browse the repository at this point in the history
updated api create to return resultant object from the api
  • Loading branch information
haydenmcp authored Apr 6, 2022
2 parents bbf1899 + aabb436 commit 98ac5a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@thinkdeep/k8s",
"version": "3.0.2",
"version": "3.0.3",
"description": "K8s node client tag for processing yaml configurations in javascript code.",
"main": "src/k8s-client.mjs",
"repository": "[email protected]:ThinkDeepTech/k8s.git",
Expand Down
21 changes: 15 additions & 6 deletions src/k8s-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,23 @@ class K8sApi {
}
}

createAll(manifests) {
return Promise.all(manifests.map(async(manifest) => {
async createAll(manifests) {
return (await Promise.all(manifests.map(async(manifest) => {
try {
await this._creationStrategy(manifest)();

const received = await this._creationStrategy(manifest)();

return this._configuredManifest(received.response.body);
} catch (e) {

const {response: {statusCode}} = e;
if (statusCode !== 409) {
throw e;
}

return null;
}
}));
}))).filter((val) => !!val);
}

_creationStrategy(manifest) {
Expand Down Expand Up @@ -327,11 +332,15 @@ class K8sApi {

_deletionStrategy(manifest) {

if (!manifest?.kind) {
if (!manifest) {
throw new Error(`The manifest value is invalid: ${manifest}`);
}

if (!manifest.kind) {
throw new Error(`The manifest requires a kind.`);
}

if (!manifest?.apiVersion) {
if (!manifest.apiVersion) {
throw new Error(`The manifest requires an api version.`);
}

Expand Down
4 changes: 1 addition & 3 deletions src/k8s-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class K8sClient {

const manifest = this._manifest(configuration);

await this._api.createAll([manifest]);

return manifest;
return (await this._api.createAll([manifest]))[0] || manifest;
}

async applyAll(configurations) {
Expand Down

0 comments on commit 98ac5a2

Please sign in to comment.