Skip to content

Commit 076f35a

Browse files
Andrew Farriesroboquat
Andrew Farries
authored andcommitted
Make deleteByName take an applicationCluster
Deleting a workspace cluster by name only makes sense in the context of a particular workspace cluster.
1 parent e9eb6ac commit 076f35a

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

components/gitpod-db/src/typeorm/workspace-cluster-db-impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export class WorkspaceClusterDBImpl implements WorkspaceClusterDB {
3232
await repo.save(cluster);
3333
}
3434

35-
async deleteByName(name: string): Promise<void> {
35+
async deleteByName(name: string, applicationCluster: string): Promise<void> {
3636
const repo = await this.getRepo();
37-
await repo.delete(name);
37+
await repo.delete({ name, applicationCluster });
3838
}
3939

4040
async findByName(name: string, applicationCluster: string): Promise<WorkspaceCluster | undefined> {

components/gitpod-db/src/workspace-cluster-db.spec.db.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,49 @@ export class WorkspaceClusterDBSpec {
5555
await this.db.save(wsc1);
5656
await this.db.save(wsc2);
5757

58-
const wsc = await this.db.findByName("eu71", "eu02");
59-
expect(wsc).not.to.be.undefined;
60-
expect((wsc as WorkspaceCluster).name).to.equal("eu71");
58+
// Can find the eu71 cluster as seen by the eu02 application cluster.
59+
const result = await this.db.findByName("eu71", "eu02");
60+
expect(result).not.to.be.undefined;
61+
expect((result as WorkspaceCluster).name).to.equal("eu71");
62+
63+
// Can't find the eu71 cluster as seen by the us02 application cluster.
64+
// (no record in the db for that (ws-cluster, app-cluster) combination).
65+
const result2 = await this.db.findByName("eu71", "us02");
66+
expect(result2).to.be.undefined;
67+
68+
// Can find the us71 cluster as seen by the eu02 application cluster.
69+
const result3 = await this.db.findByName("us71", "eu02");
70+
expect(result3).not.to.be.undefined;
71+
expect((result3 as WorkspaceCluster).name).to.equal("us71");
72+
}
73+
74+
@test public async deleteByName() {
75+
const wsc1: DBWorkspaceCluster = {
76+
name: "eu71",
77+
applicationCluster: "eu02",
78+
url: "some-url",
79+
state: "available",
80+
score: 100,
81+
maxScore: 100,
82+
govern: true,
83+
};
84+
const wsc2: DBWorkspaceCluster = {
85+
name: "us71",
86+
applicationCluster: "eu02",
87+
url: "some-url",
88+
state: "cordoned",
89+
score: 0,
90+
maxScore: 0,
91+
govern: false,
92+
};
93+
94+
await this.db.save(wsc1);
95+
await this.db.save(wsc2);
96+
97+
// Can delete the eu71 cluster as seen by the eu02 application cluster.
98+
await this.db.deleteByName("eu71", "eu02");
99+
expect(await this.db.findByName("eu71", "eu02")).to.be.undefined;
100+
expect(await this.db.findByName("us71", "eu02")).not.to.be.undefined;
61101
}
62102

63103
@test public async testFindFilteredByName() {

components/gitpod-protocol/src/workspace-cluster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface WorkspaceClusterDB {
9090
* Deletes the cluster identified by this name, if any.
9191
* @param name
9292
*/
93-
deleteByName(name: string): Promise<void>;
93+
deleteByName(name: string, applicationCluster: string): Promise<void>;
9494

9595
/**
9696
* Finds a WorkspaceCluster with the given name. If there is none, `undefined` is returned.

components/ws-manager-bridge/src/cluster-service-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class ClusterService implements IClusterServiceServer {
288288
);
289289
}
290290

291-
await this.clusterDB.deleteByName(req.name);
291+
await this.clusterDB.deleteByName(req.name, this.config.installation);
292292
log.info({}, "cluster deregistered", { cluster: req.name });
293293
this.triggerReconcile("deregister", req.name);
294294

0 commit comments

Comments
 (0)