Skip to content

Commit

Permalink
Merge pull request #22 from platformercloud/hotfix/changes-to-import
Browse files Browse the repository at this point in the history
Ignore yaml apply errors & continue
  • Loading branch information
ChathurangaKCD authored Jan 25, 2021
2 parents 32bb425 + 6cbc1ab commit d01482e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/commands/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ async function printLogs(parsedFiles: Observable<ManifestFile>) {
const kind = manifest.manifest.kind;
const name = manifest.manifest.metadata.name;
const fileName = manifest.file.file.fileName;
successTree.insert(`${kind} ${name} created (${fileName})`, subTree);
successTree.insert(`${kind} ${name} applied (${fileName})`, subTree);
if (manifest.state === ManifestState.UNKNOWN_SUCCESS_RESPONSE) {
subTree.insert(chalk.yellow('Unknown server response'));
}
Expand All @@ -255,7 +255,7 @@ async function printLogs(parsedFiles: Observable<ManifestFile>) {
tap((count) => {
if (count === 0) return;
cli.log('');
cli.log(chalk.green('Created resources'));
cli.log(chalk.green('Applied resources'));
successTree.display();
})
)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export default class Apply extends Command {
try {
try {
for (const group of importGroups) {
const manifestOfGroup = group.getManifests();
const manifestsOfGroup = group.getManifests();
await applyManifests(
manifestOfGroup,
manifestsOfGroup,
{ orgId, projectId, envId },
{
start: `Applying ${group.resourceTypes.description}`,
Expand Down Expand Up @@ -262,7 +262,7 @@ async function printLogs(groups: ManifestImportGroup[]) {
const subTree = cli.tree();
const kind = manifest.manifest.kind;
const name = manifest.manifest.metadata.name;
successTree.insert(`${kind} ${name} created`, subTree);
successTree.insert(`${kind} ${name} applied`, subTree);
if (manifest.state === ManifestState.UNKNOWN_SUCCESS_RESPONSE) {
subTree.insert(chalk.yellow('Unknown server response'));
}
Expand All @@ -274,7 +274,7 @@ async function printLogs(groups: ManifestImportGroup[]) {
tap((count) => {
if (count === 0) return;
cli.log('');
cli.log(chalk.green('Created resources'));
cli.log(chalk.green('Applied resources'));
successTree.display();
})
)
Expand Down
16 changes: 13 additions & 3 deletions src/modules/gitops/manifest-group.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defer, EMPTY, Observable, of } from 'rxjs';
import { defer, EMPTY, Observable, of, timer } from 'rxjs';
import {
catchError,
filter,
map,
mergeAll,
mergeMap,
retry,
retryWhen,
shareReplay,
takeUntil,
tap,
Expand Down Expand Up @@ -99,7 +99,17 @@ function fetchResourcesOfType(query: ResourceQuery, r: ResourceType) {
throw new YamlFectchFailure(r, query, cause);
}
}).pipe(
retry(2),
retryWhen((errors) =>
errors.pipe(
mergeMap((v, i) => {
// error msg available, no need to retry
if (v instanceof YamlFectchFailure && v.cause) throw v;
// allow 2 retries, retry in 1s
if (i > 1) throw v;
return timer(1000);
})
)
),
catchError(async (err) => {
if (err instanceof YamlFectchFailure) return err;
return EMPTY;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/gitops/manifest-import-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const importTypes: Array<ImportType> = [
{ kind: 'Deployment', apiVersion: 'extensions/v1beta1' },
{ kind: 'StatefulSet', apiVersion: 'apps/v1' },
{ kind: 'DaemonSet', apiVersion: 'apps/v1' },
{ kind: 'Job', apiVersion: 'batch/v1' },
{ kind: 'CronJob', apiVersion: 'batch/v1' },
{ kind: 'CronJob', apiVersion: 'batch/v1beta1' },
],
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/modules/gitops/manifest-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class ManifestObject {
this.errorMsg = (error as Error).message;
s.error(ManifestState.ERROR);
}
throw error;
// return without throwing error, to allow other manifests to be applied
return;
}
s.next(ManifestState.WRITING_TO_FILE);
try {
Expand Down

0 comments on commit d01482e

Please sign in to comment.