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..831e2ffa41e989 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: 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 new file mode 100644 index 00000000000000..62929e511a8b36 --- /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(60) 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..8725ed730dc052 100644 --- a/components/gitpod-protocol/src/workspace-cluster.ts +++ b/components/gitpod-protocol/src/workspace-cluster.ts @@ -15,6 +15,10 @@ 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. + // The name can be at most 60 characters. + applicationCluster: string; + // URL of the cluster's ws-manager API url: string; 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 { 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,