Skip to content

Commit e9eb6ac

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

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
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
@@ -37,9 +37,9 @@ export class WorkspaceClusterDBImpl implements WorkspaceClusterDB {
3737
await repo.delete(name);
3838
}
3939

40-
async findByName(name: string): Promise<WorkspaceCluster | undefined> {
40+
async findByName(name: string, applicationCluster: string): Promise<WorkspaceCluster | undefined> {
4141
const repo = await this.getRepo();
42-
return repo.findOne(name);
42+
return repo.findOne({ name, applicationCluster });
4343
}
4444

4545
async findFiltered(predicate: WorkspaceClusterFilter): Promise<WorkspaceClusterWoTLS[]> {

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as chai from "chai";
88
import { suite, test, timeout } from "mocha-typescript";
99
import { testContainer } from "./test-container";
1010
import { TypeORM } from "./typeorm/typeorm";
11-
import { WorkspaceClusterDB } from "@gitpod/gitpod-protocol/lib/workspace-cluster";
11+
import { WorkspaceCluster, WorkspaceClusterDB } from "@gitpod/gitpod-protocol/lib/workspace-cluster";
1212
import { DBWorkspaceCluster } from "./typeorm/entity/db-workspace-cluster";
1313
const expect = chai.expect;
1414

@@ -32,6 +32,34 @@ export class WorkspaceClusterDBSpec {
3232
await manager.clear(DBWorkspaceCluster);
3333
}
3434

35+
@test public async findByName() {
36+
const wsc1: DBWorkspaceCluster = {
37+
name: "eu71",
38+
applicationCluster: "eu02",
39+
url: "some-url",
40+
state: "available",
41+
score: 100,
42+
maxScore: 100,
43+
govern: true,
44+
};
45+
const wsc2: DBWorkspaceCluster = {
46+
name: "us71",
47+
applicationCluster: "eu02",
48+
url: "some-url",
49+
state: "cordoned",
50+
score: 0,
51+
maxScore: 0,
52+
govern: false,
53+
};
54+
55+
await this.db.save(wsc1);
56+
await this.db.save(wsc2);
57+
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");
61+
}
62+
3563
@test public async testFindFilteredByName() {
3664
const wsc1: DBWorkspaceCluster = {
3765
name: "eu71",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface WorkspaceClusterDB {
9696
* Finds a WorkspaceCluster with the given name. If there is none, `undefined` is returned.
9797
* @param name
9898
*/
99-
findByName(name: string): Promise<WorkspaceCluster | undefined>;
99+
findByName(name: string, applicationCluster: string): Promise<WorkspaceCluster | undefined>;
100100

101101
/**
102102
* Lists all WorkspaceClusterWoTls for which the given predicate is true (does not return TLS for size/speed concerns)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ClusterService implements IClusterServiceServer {
8787
// check if the name or URL are already registered/in use
8888
const req = call.request.toObject();
8989

90-
const clusterByNamePromise = this.clusterDB.findByName(req.name);
90+
const clusterByNamePromise = this.clusterDB.findByName(req.name, this.config.installation);
9191
const clusterByUrlPromise = this.clusterDB.findFiltered({
9292
url: req.url,
9393
applicationCluster: this.config.installation,
@@ -211,7 +211,7 @@ export class ClusterService implements IClusterServiceServer {
211211
this.queue.enqueue(async () => {
212212
try {
213213
const req = call.request.toObject();
214-
const cluster = await this.clusterDB.findByName(req.name);
214+
const cluster = await this.clusterDB.findByName(req.name, this.config.installation);
215215
if (!cluster) {
216216
throw new GRPCError(
217217
grpc.status.NOT_FOUND,

0 commit comments

Comments
 (0)