Skip to content

Commit

Permalink
Merge pull request #20 from platformercloud/hotfix/remove-unnecessary…
Browse files Browse the repository at this point in the history
…-properties-from-yaml

remove properties from yaml
  • Loading branch information
ChathurangaKCD authored Jan 23, 2021
2 parents f3a43bd + 56e350c commit 85974b7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/modules/gitops/manifest-file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FileInfo } from './fs';
import { KindPriorityMap } from './manifest-import-types';
import { ManifestFileObject, modifyTargetNS } from './manifest-object';
import { ManifestFileObject, modifyYAML } from './manifest-object';
import { parseK8sManifestsFromFile } from './parser';

export class ManifestFile {
Expand Down Expand Up @@ -39,7 +39,7 @@ export class ManifestFile {
? sorted.filter((m) => m.kind !== 'Namespace')
: sorted;
this.#manifests = filtered.map(
(m) => new ManifestFileObject(modifyTargetNS(m, this.#targetNS), this)
(m) => new ManifestFileObject(modifyYAML(m, this.#targetNS), this)
);
} catch (error) {}
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/gitops/manifest-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { queryResource } from '../cluster/api';
import { ImportType, ResourceType } from './manifest-import-types';
import {
ManifestObject,
modifyTargetNS,
modifyYAML,
skippedStateNotifier,
} from './manifest-object';
import { K8sObject } from './parser';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class ManifestImportGroup {
map((v) => v.payload),
mergeAll(),
filter((v) => shouldImport(v, sourceNS)),
map((v) => new ManifestObject(modifyTargetNS(v, targetNS))),
map((v) => new ManifestObject(modifyYAML(v, targetNS))),
tap((v) => this.#manifests.push(v)),
shareReplay()
);
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 @@ -17,7 +17,7 @@ const importTypes: Array<ImportType> = [
},
{
priority: 1,
description: 'configuration',
description: 'configurations',
types: [
{ kind: 'Secret', apiVersion: 'v1' },
{ kind: 'ConfigMap', apiVersion: 'v1' },
Expand Down
20 changes: 19 additions & 1 deletion src/modules/gitops/manifest-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,30 @@ export class ManifestFileObject extends ManifestObject {
}
}

export function modifyTargetNS(manifest: K8sObject, target?: string) {
const metadataToDelete = [
'selfLink',
'uid',
'resourceVersion',
'generation',
'creationTimestamp',
];
const annotationsToDelete = [
'kubectl.kubernetes.io/last-applied-configuration',
];

export function modifyYAML(manifest: K8sObject, target?: string) {
if (!target) return manifest;
if (manifest.kind === 'Namespace') {
manifest.metadata.name = target;
} else {
manifest.metadata.namespace = target;
}
delete manifest['status'];
metadataToDelete.forEach((key) => {
delete manifest.metadata[key];
});
annotationsToDelete.forEach((key) => {
delete manifest.metadata.annotations?.[key];
});
return manifest;
}
2 changes: 2 additions & 0 deletions src/modules/gitops/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface K8sObject {
name: string;
namespace?: string;
[key: string]: any;
labels?: Record<string, string> | null;
annotations?: Record<string, string> | null;
};
ownerReferences?: null | Array<OwnerReference>;
[key: string]: any;
Expand Down

0 comments on commit 85974b7

Please sign in to comment.