Skip to content

Commit

Permalink
Merge pull request #1764 from AmericanAirlines/feat/argo-cd-backend-f…
Browse files Browse the repository at this point in the history
…inalizers

fix(backstage-plugin-argo-cd-backend): adding finalizer to allow deleting of application
  • Loading branch information
Xantier authored Dec 19, 2024
2 parents dbf15a8 + 2bf0fa2 commit b71177a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-files-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/backstage-plugin-argo-cd-backend': patch
---

Adding the `resources-finalizer.argocd.argoproj.io` finalizer when creating a project. This allows the ability to delete the project first without getting stuck when deleting the application afterwards. This fix will allow the application to delete and not get stuck deleting.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class ArgoService implements ArgoServiceApi {
metadata: {
name: projectName,
resourceVersion,
finalizers: ['resources-finalizer.argocd.argoproj.io'],
},
spec: {
destinations: [
Expand Down Expand Up @@ -350,6 +351,7 @@ export class ArgoService implements ArgoServiceApi {
},
body: JSON.stringify(data),
};

const resp = await fetch(`${baseUrl}/api/v1/projects`, options);
const responseData = await resp.json();
if (resp.status === 403) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,39 @@ describe('ArgoCD service', () => {
},
});
});

it('creates project with resources-finalizer.argocd.argoproj.io finalizer', async () => {
fetchMock.mockResponseOnce(
JSON.stringify({
argocdCreateProjectResp,
}),
);
const service = new ArgoService(
'testusername',
'testpassword',
getConfig({
token: 'token',
}),
loggerMock,
);

await service.createArgoProject({
baseUrl: 'baseUrl',
argoToken: 'token',
projectName: 'projectName',
namespace: 'namespace',
sourceRepo: 'sourceRepo',
});

expect(fetchMock).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
body: expect.stringContaining(
'{"metadata":{"name":"projectName","finalizers":["resources-finalizer.argocd.argoproj.io"]}',
),
}),
);
});
});

describe('createArgoApplication', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export type Metadata = {
deletionTimestamp?: string;
deletionGracePeriodSeconds?: number;
resourceVersion?: string;
finalizers?: string[];
};

export type ResourceItem = {
Expand Down

0 comments on commit b71177a

Please sign in to comment.