Skip to content

Commit

Permalink
Implement KUBE_CLEANER_FORCE_CLEAN_ALL to remove all releases in ns
Browse files Browse the repository at this point in the history
  • Loading branch information
wirwolf committed Jan 8, 2024
1 parent 538e4b8 commit ce4b721
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ HELM_DEBUG=false
HELM_DRY_RUN=false
KUBE_NAMESPACE=default
KUBE_CLEANER_DEBUG=false
KUBE_CLEANER_FORCE_CLEAN_ALL=false
2 changes: 2 additions & 0 deletions src/Config/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ConfigFactory {
KUBECTL_CMD_ARGS: env('KUBECTL_CMD_ARGS', ''),
KUBE_NAMESPACE: env('KUBE_NAMESPACE', 'default'),
KUBE_CLEANER_DEBUG: envBoolean('KUBE_CLEANER_DEBUG', false),
KUBE_CLEANER_FORCE_CLEAN_ALL: envBoolean('KUBE_CLEANER_FORCE_CLEAN_ALL', false),
};
}
}
Expand All @@ -35,4 +36,5 @@ interface CoreConfigInterface {
KUBECTL_CMD_ARGS: string;
KUBE_NAMESPACE: string;
KUBE_CLEANER_DEBUG: boolean;
KUBE_CLEANER_FORCE_CLEAN_ALL: boolean;
}
19 changes: 18 additions & 1 deletion src/Modules/RemoverModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,26 @@ export class RemoverModule {
);
});
const realisesList = await Promise.all(promiseList);

if (ConfigFactory.getCore().KUBE_CLEANER_FORCE_CLEAN_ALL === true) {
console.log('[kube-resource-cleanup] KUBE_CLEANER_FORCE_CLEAN_ALL - true');
console.log('[kube-resource-cleanup] Remove all helm releases');
}
const deletedRealisesPromiseList = realisesList.map((item) => {
return new Promise<any>((resolve, reject) => {
if (ConfigFactory.getCore().KUBE_CLEANER_FORCE_CLEAN_ALL === true) {
KubeProcessHelper.helm(
[
'uninstall',
'--namespace', ConfigFactory.getCore().KUBE_NAMESPACE,
item.helmReleaseName
],
{
grabStdOut: true,
}
).then((data) => {
resolve({helmReleaseName: item.helmReleaseName, status: true, reason: data});
});
}
if (typeof item === 'object') {
const releaseGitlabProjectName = item?.metadata?.gitlabProjectName;
const releaseGitlabProjectBranch = item?.metadata?.gitlabProjectBranch;
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/VersionModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ConfigFactory} from '../Config/app-config';

export class VersionModule {
public async run(cliArgs: string[]) {
console.log('[kube-resource-cleanup]' + ConfigFactory.getBase().id + ': ' + ConfigFactory.getBase().version);
console.log('[kube-resource-cleanup] ' + ConfigFactory.getBase().id + ': ' + ConfigFactory.getBase().version);
return Promise.resolve();

}
Expand Down

0 comments on commit ce4b721

Please sign in to comment.