-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ws-manager] Make cluster selection filter by application cluster #14050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f88c0f5
Extend WorkspaceClusterFilter in gitpod-protocol
f4a59ce
Add tests for workspace-cluster-db implementation
5cab1d6
Make client providers filter by app cluster
5ec6429
Pass applicationCluster everywhere
a468b60
Make applicationCluster mandatory when filtering
062d201
Make `findByName` take an applicationCluster
3cdaa1d
Make `deleteByName` take an applicationCluster
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
components/gitpod-db/src/workspace-cluster-db.spec.db.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/** | ||
* Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import * as chai from "chai"; | ||
import { suite, test, timeout } from "mocha-typescript"; | ||
import { testContainer } from "./test-container"; | ||
import { TypeORM } from "./typeorm/typeorm"; | ||
import { WorkspaceCluster, WorkspaceClusterDB } from "@gitpod/gitpod-protocol/lib/workspace-cluster"; | ||
import { DBWorkspaceCluster } from "./typeorm/entity/db-workspace-cluster"; | ||
const expect = chai.expect; | ||
|
||
@suite | ||
@timeout(5000) | ||
export class WorkspaceClusterDBSpec { | ||
typeORM = testContainer.get<TypeORM>(TypeORM); | ||
db = testContainer.get<WorkspaceClusterDB>(WorkspaceClusterDB); | ||
|
||
async before() { | ||
await this.clear(); | ||
} | ||
|
||
async after() { | ||
await this.clear(); | ||
} | ||
|
||
protected async clear() { | ||
const connection = await this.typeORM.getConnection(); | ||
const manager = connection.manager; | ||
await manager.clear(DBWorkspaceCluster); | ||
} | ||
|
||
@test public async findByName() { | ||
const wsc1: DBWorkspaceCluster = { | ||
name: "eu71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "available", | ||
score: 100, | ||
maxScore: 100, | ||
govern: true, | ||
}; | ||
const wsc2: DBWorkspaceCluster = { | ||
name: "us71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "cordoned", | ||
score: 0, | ||
maxScore: 0, | ||
govern: false, | ||
}; | ||
|
||
await this.db.save(wsc1); | ||
await this.db.save(wsc2); | ||
|
||
// Can find the eu71 cluster as seen by the eu02 application cluster. | ||
const result = await this.db.findByName("eu71", "eu02"); | ||
expect(result).not.to.be.undefined; | ||
expect((result as WorkspaceCluster).name).to.equal("eu71"); | ||
|
||
// Can't find the eu71 cluster as seen by the us02 application cluster. | ||
// (no record in the db for that (ws-cluster, app-cluster) combination). | ||
const result2 = await this.db.findByName("eu71", "us02"); | ||
expect(result2).to.be.undefined; | ||
|
||
// Can find the us71 cluster as seen by the eu02 application cluster. | ||
const result3 = await this.db.findByName("us71", "eu02"); | ||
expect(result3).not.to.be.undefined; | ||
expect((result3 as WorkspaceCluster).name).to.equal("us71"); | ||
} | ||
|
||
@test public async deleteByName() { | ||
const wsc1: DBWorkspaceCluster = { | ||
name: "eu71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "available", | ||
score: 100, | ||
maxScore: 100, | ||
govern: true, | ||
}; | ||
const wsc2: DBWorkspaceCluster = { | ||
name: "us71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "cordoned", | ||
score: 0, | ||
maxScore: 0, | ||
govern: false, | ||
}; | ||
|
||
await this.db.save(wsc1); | ||
await this.db.save(wsc2); | ||
|
||
// Can delete the eu71 cluster as seen by the eu02 application cluster. | ||
await this.db.deleteByName("eu71", "eu02"); | ||
expect(await this.db.findByName("eu71", "eu02")).to.be.undefined; | ||
expect(await this.db.findByName("us71", "eu02")).not.to.be.undefined; | ||
} | ||
|
||
@test public async testFindFilteredByName() { | ||
const wsc1: DBWorkspaceCluster = { | ||
name: "eu71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "available", | ||
score: 100, | ||
maxScore: 100, | ||
govern: true, | ||
}; | ||
const wsc2: DBWorkspaceCluster = { | ||
name: "us71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "cordoned", | ||
score: 0, | ||
maxScore: 0, | ||
govern: false, | ||
}; | ||
|
||
await this.db.save(wsc1); | ||
await this.db.save(wsc2); | ||
|
||
const wscs = await this.db.findFiltered({ name: "eu71", applicationCluster: "eu02" }); | ||
expect(wscs.length).to.equal(1); | ||
expect(wscs[0].name).to.equal("eu71"); | ||
} | ||
|
||
@test public async testFindFilteredByApplicationCluster() { | ||
const wsc1: DBWorkspaceCluster = { | ||
name: "eu71", | ||
applicationCluster: "eu02", | ||
url: "some-url", | ||
state: "available", | ||
score: 100, | ||
maxScore: 100, | ||
govern: true, | ||
}; | ||
const wsc2: DBWorkspaceCluster = { | ||
name: "us71", | ||
applicationCluster: "us02", | ||
url: "some-url", | ||
state: "available", | ||
score: 100, | ||
maxScore: 100, | ||
govern: true, | ||
}; | ||
|
||
await this.db.save(wsc1); | ||
await this.db.save(wsc2); | ||
|
||
const wscs = await this.db.findFiltered({ applicationCluster: "eu02" }); | ||
expect(wscs.length).to.equal(1); | ||
expect(wscs[0].name).to.equal("eu71"); | ||
} | ||
} | ||
|
||
module.exports = WorkspaceClusterDBSpec; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.