Skip to content

Commit

Permalink
Merge pull request #37 from webzard-io/bowen/remore-create-update
Browse files Browse the repository at this point in the history
don't create non-exist resource when updating
  • Loading branch information
tanbowensg authored Mar 14, 2024
2 parents b9c6de5 + 84dc60a commit 7dbecbf
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions src/kube-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ export class KubeSdk {
const restoredSpecs = this.restoreItemsFromPlugins(validSpecs);

const changed: Unstructured[] = [];
const created: Unstructured[] = [];
const updated: Unstructured[] = [];

for (const index in restoredSpecs) {
Expand All @@ -709,38 +708,13 @@ export class KubeSdk {
delete (spec as any).metadata.resourceVersion;
}

let exist = true;
try {
await this.read(spec);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
if (e.response?.status === 404) {
exist = false;
} else {
throw e;
}
}
const response = await this.patch(spec, strategy, replacePaths?.[index]);

const response = exist
? await this.patch(spec, strategy, replacePaths?.[index])
: await this.create(spec);
updated.push(response as Unstructured);

if (exist) {
updated.push(response as Unstructured);
} else {
created.push(response as Unstructured);
}
changed.push(response as Unstructured);
}

if (created.length) {
event.emit('change', {
type: 'ADDED',
basePath: this.basePath,
items: created,
});
}

if (updated.length) {
event.emit('change', {
type: 'MODIFIED',
Expand Down

0 comments on commit 7dbecbf

Please sign in to comment.