From a07edde34d0517f9f2cc6c98d3d4fbc22fff18a5 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Mon, 10 Oct 2022 07:44:16 +0000 Subject: [PATCH 1/4] Add `applicationCluster` field to table This field will record to which workspace cluster the information in each row belongs. --- .../typeorm/entity/db-workspace-cluster.ts | 6 ++++++ ...320428-AddColumnToWorkspaceClusterTable.ts | 21 +++++++++++++++++++ .../src/typeorm/workspace-cluster-db-impl.ts | 1 + .../gitpod-protocol/src/workspace-cluster.ts | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts diff --git a/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts b/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts index 6ff2a3255f8e62..0d817a8ac26263 100644 --- a/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts +++ b/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts @@ -84,4 +84,10 @@ export class DBWorkspaceCluster implements WorkspaceCluster { })(), }) admissionConstraints?: AdmissionConstraint[]; + + @Column({ + type: "varchar", + length: 255, + }) + applicationCluster: string; } diff --git a/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts b/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts new file mode 100644 index 00000000000000..be2c891de4ed25 --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts @@ -0,0 +1,21 @@ +/** + * 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 { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddColumnToWorkspaceClusterTable1665071320428 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + const installationShortname = process.env.GITPOD_INSTALLATION_SHORTNAME ?? ""; + + await queryRunner.query( + `ALTER TABLE d_b_workspace_cluster ADD COLUMN applicationCluster varchar(255) NOT NULL DEFAULT ''`, + ); + + await queryRunner.query(`UPDATE d_b_workspace_cluster SET applicationCluster = '${installationShortname}'`); + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/components/gitpod-db/src/typeorm/workspace-cluster-db-impl.ts b/components/gitpod-db/src/typeorm/workspace-cluster-db-impl.ts index 266abbbf681089..ca0c378b9d17c5 100644 --- a/components/gitpod-db/src/typeorm/workspace-cluster-db-impl.ts +++ b/components/gitpod-db/src/typeorm/workspace-cluster-db-impl.ts @@ -51,6 +51,7 @@ export class WorkspaceClusterDBImpl implements WorkspaceClusterDB { state: "available", govern: false, admissionConstraints: [], + applicationCluster: "", }; const repo = await this.getRepo(); diff --git a/components/gitpod-protocol/src/workspace-cluster.ts b/components/gitpod-protocol/src/workspace-cluster.ts index 853565f8aa9158..9cddd7cb53c848 100644 --- a/components/gitpod-protocol/src/workspace-cluster.ts +++ b/components/gitpod-protocol/src/workspace-cluster.ts @@ -15,6 +15,9 @@ export interface WorkspaceCluster { // Must be identical to the installationShortname of the cluster it represents! name: string; + // The name of the application cluster to which this cluster should be registered. + applicationCluster: string; + // URL of the cluster's ws-manager API url: string; From 5fe5771a5d235d52a75398cc8a56161f8cb10cbd Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Mon, 10 Oct 2022 07:50:46 +0000 Subject: [PATCH 2/4] Update test data --- .../ws-manager-api/typescript/src/client-provider.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/ws-manager-api/typescript/src/client-provider.spec.ts b/components/ws-manager-api/typescript/src/client-provider.spec.ts index 7b365c2b7e240a..845b8573281e63 100644 --- a/components/ws-manager-api/typescript/src/client-provider.spec.ts +++ b/components/ws-manager-api/typescript/src/client-provider.spec.ts @@ -39,6 +39,7 @@ class TestClientProvider { state: "cordoned", url: "", admissionConstraints: [], + applicationCluster: "xx01", }, { name: "c2", @@ -48,6 +49,7 @@ class TestClientProvider { state: "cordoned", url: "", admissionConstraints: [], + applicationCluster: "xx01", }, { name: "c3", @@ -57,6 +59,7 @@ class TestClientProvider { state: "cordoned", url: "", admissionConstraints: [], + applicationCluster: "xx01", }, { name: "a1", @@ -66,6 +69,7 @@ class TestClientProvider { state: "available", url: "", admissionConstraints: [], + applicationCluster: "xx01", }, { name: "a2", @@ -75,6 +79,7 @@ class TestClientProvider { state: "available", url: "", admissionConstraints: [], + applicationCluster: "xx01", }, { name: "a3", @@ -84,6 +89,7 @@ class TestClientProvider { state: "available", url: "", admissionConstraints: [], + applicationCluster: "xx01", }, { name: "con1", @@ -93,6 +99,7 @@ class TestClientProvider { state: "available", url: "", admissionConstraints: [{ type: "has-permission", permission: "new-workspace-cluster" }], + applicationCluster: "xx01", }, { name: "con2", @@ -104,6 +111,7 @@ class TestClientProvider { admissionConstraints: [ { type: "has-permission", permission: "monitor" }, // This is meant to representent a permission that does not take special predence (cmp. constraints.ts) ], + applicationCluster: "xx01", }, ]; return { From 339dcb9e489eb7c4685c8e9bd3bf26ece814a441 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Mon, 10 Oct 2022 14:36:16 +0000 Subject: [PATCH 3/4] Set applicationCluster when registering cluster Set the application cluster when registering a new workspace cluster. The applicationCluster is set to the value of the GITPOD_INSTALLATION_SHORTNAME env var which must be set in the environment of ws manager bridge. --- .../ws-manager-bridge/src/cluster-service-server.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/ws-manager-bridge/src/cluster-service-server.ts b/components/ws-manager-bridge/src/cluster-service-server.ts index 6b30c6e63227f1..c01710eb64f586 100644 --- a/components/ws-manager-bridge/src/cluster-service-server.ts +++ b/components/ws-manager-bridge/src/cluster-service-server.ts @@ -107,6 +107,14 @@ export class ClusterService implements IClusterServiceServer { } } + const applicationCluster = process.env.GITPOD_INSTALLATION_SHORTNAME; + if (applicationCluster === undefined) { + throw new GRPCError( + grpc.status.INTERNAL, + "no GITPOD_INSTALLATION_SHORTNAME environment variable is set on the server", + ); + } + // store the ws-manager into the database let perfereability = Preferability.NONE; let govern = false; @@ -141,6 +149,7 @@ export class ClusterService implements IClusterServiceServer { const newCluster: WorkspaceCluster = { name: req.name, url: req.url, + applicationCluster, state, score, maxScore: 100, From 80f626ab2200cc9d17f28e49a98197fa7a6c66f4 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Wed, 12 Oct 2022 09:15:18 +0000 Subject: [PATCH 4/4] Change length of `applicationCluster` field --- components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts | 2 +- .../migration/1665071320428-AddColumnToWorkspaceClusterTable.ts | 2 +- components/gitpod-protocol/src/workspace-cluster.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts b/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts index 0d817a8ac26263..831e2ffa41e989 100644 --- a/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts +++ b/components/gitpod-db/src/typeorm/entity/db-workspace-cluster.ts @@ -87,7 +87,7 @@ export class DBWorkspaceCluster implements WorkspaceCluster { @Column({ type: "varchar", - length: 255, + length: 60, }) applicationCluster: string; } diff --git a/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts b/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts index be2c891de4ed25..62929e511a8b36 100644 --- a/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts +++ b/components/gitpod-db/src/typeorm/migration/1665071320428-AddColumnToWorkspaceClusterTable.ts @@ -11,7 +11,7 @@ export class AddColumnToWorkspaceClusterTable1665071320428 implements MigrationI const installationShortname = process.env.GITPOD_INSTALLATION_SHORTNAME ?? ""; await queryRunner.query( - `ALTER TABLE d_b_workspace_cluster ADD COLUMN applicationCluster varchar(255) NOT NULL DEFAULT ''`, + `ALTER TABLE d_b_workspace_cluster ADD COLUMN applicationCluster varchar(60) NOT NULL DEFAULT ''`, ); await queryRunner.query(`UPDATE d_b_workspace_cluster SET applicationCluster = '${installationShortname}'`); diff --git a/components/gitpod-protocol/src/workspace-cluster.ts b/components/gitpod-protocol/src/workspace-cluster.ts index 9cddd7cb53c848..8725ed730dc052 100644 --- a/components/gitpod-protocol/src/workspace-cluster.ts +++ b/components/gitpod-protocol/src/workspace-cluster.ts @@ -16,6 +16,7 @@ export interface WorkspaceCluster { name: string; // The name of the application cluster to which this cluster should be registered. + // The name can be at most 60 characters. applicationCluster: string; // URL of the cluster's ws-manager API