Skip to content

Commit

Permalink
Delete HelmRelease on Tear Down | SRENEW-1126 (#167)
Browse files Browse the repository at this point in the history
* Delete HelmRelease on Tear Down | SRENEW-1126

* Build | SRENEW-1126

* Rename consts | SRENEW-1126
  • Loading branch information
guitarislife87 authored Apr 13, 2022
1 parent bf9fbdd commit 2202a46
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
14 changes: 11 additions & 3 deletions __tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ describe('#destroy', () => {
beforeEach(async () => {
api = {
deleteNamespacedKustomization: jest.fn(),
deleteNamespacedGitRepository: jest.fn()
deleteNamespacedGitRepository: jest.fn(),
deleteNamespacedHelmRelease: jest.fn()
}
const d = fluxDeploy(mockDeploy, api)
await d.destroy()
Expand All @@ -23,8 +24,15 @@ describe('#destroy', () => {
)
})

it('should delete a GitRepository', () => {
expect(api.deleteNamespacedGitRepository).toHaveBeenCalledWith(
it('should delete a Kustomization', () => {
expect(api.deleteNamespacedKustomization).toHaveBeenCalledWith(
'mock',
'mock-ns'
)
})

it('should delete a HelmRelease', () => {
expect(api.deleteNamespacedHelmRelease).toHaveBeenCalledWith(
'mock',
'mock-ns'
)
Expand Down
32 changes: 31 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as core from '@actions/core'

import {kustomization, KustomizationSpec} from './kustomization'
import {gitRepository, GitRepositorySpec} from './gitrepository'
import {helmRelease} from './helmrelease'
import {ActionOnInvalid} from '@kubernetes/client-node/dist/config_types'

export interface Api {
Expand All @@ -28,6 +29,7 @@ export interface Api {
spec: GitRepositorySpec
): Promise<void>
deleteNamespacedGitRepository(name: string, namespace: string): Promise<void>
deleteNamespacedHelmRelease(name: string, namespace: string): Promise<void>
}

interface K8sPatch {
Expand Down Expand Up @@ -197,13 +199,25 @@ export function K8sApi(): Api {
)
}

async function deleteNamespacedHelmRelease(
name: string,
namespace: string
): Promise<void> {
debug('DELETE', helmRelease, name)
await customApi.deleteNamespacedCustomObject(
...namespacedCustomObjectArgs(namespace, helmRelease),
name
)
}

return {
getNamespacedKustomization,
createNamespacedKustomization,
patchNamespacedKustomization,
deleteNamespacedKustomization,

createNamespacedGitRepository,
deleteNamespacedGitRepository
deleteNamespacedGitRepository,
deleteNamespacedHelmRelease
}
}
1 change: 1 addition & 0 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function fluxDeploy(d: FluxDeployConfig, api = K8sApi()): Deploy {
async function destroy(): Promise<void> {
await api.deleteNamespacedKustomization(d.name, d.namespace)
await api.deleteNamespacedGitRepository(d.name, d.namespace)
await api.deleteNamespacedHelmRelease(d.name, d.namespace)
}

async function rollout(): Promise<void> {
Expand Down
13 changes: 13 additions & 0 deletions src/helmrelease.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {CustomObjectDefinition} from './api'

const HELM_RELEASE_API_GROUP = 'helm.toolkit.fluxcd.io'
const HELM_RELEASE_API_VERSION = 'v2beta1'
const HELM_RELEASE_PLURAL = 'helmreleases'
const HELM_RELEASE_KIND = 'HelmRelease'

export const helmRelease: CustomObjectDefinition = {
group: HELM_RELEASE_API_GROUP,
version: HELM_RELEASE_API_VERSION,
kind: HELM_RELEASE_KIND,
plural: HELM_RELEASE_PLURAL
}

0 comments on commit 2202a46

Please sign in to comment.