Skip to content

[db] Add applicationCluster field to d_b_workspace_cluster table #13722

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 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ export class DBWorkspaceCluster implements WorkspaceCluster {
})(),
})
admissionConstraints?: AdmissionConstraint[];

@Column({
type: "varchar",
length: 60,
})
applicationCluster: string;
}
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class WorkspaceClusterDBImpl implements WorkspaceClusterDB {
state: "available",
govern: false,
admissionConstraints: [],
applicationCluster: "",
};

const repo = await this.getRepo();
Expand Down
4 changes: 4 additions & 0 deletions components/gitpod-protocol/src/workspace-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TestClientProvider {
state: "cordoned",
url: "",
admissionConstraints: [],
applicationCluster: "xx01",
},
{
name: "c2",
Expand All @@ -48,6 +49,7 @@ class TestClientProvider {
state: "cordoned",
url: "",
admissionConstraints: [],
applicationCluster: "xx01",
},
{
name: "c3",
Expand All @@ -57,6 +59,7 @@ class TestClientProvider {
state: "cordoned",
url: "",
admissionConstraints: [],
applicationCluster: "xx01",
},
{
name: "a1",
Expand All @@ -66,6 +69,7 @@ class TestClientProvider {
state: "available",
url: "",
admissionConstraints: [],
applicationCluster: "xx01",
},
{
name: "a2",
Expand All @@ -75,6 +79,7 @@ class TestClientProvider {
state: "available",
url: "",
admissionConstraints: [],
applicationCluster: "xx01",
},
{
name: "a3",
Expand All @@ -84,6 +89,7 @@ class TestClientProvider {
state: "available",
url: "",
admissionConstraints: [],
applicationCluster: "xx01",
},
{
name: "con1",
Expand All @@ -93,6 +99,7 @@ class TestClientProvider {
state: "available",
url: "",
admissionConstraints: [{ type: "has-permission", permission: "new-workspace-cluster" }],
applicationCluster: "xx01",
},
{
name: "con2",
Expand All @@ -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 <WorkspaceManagerClientProviderSource>{
Expand Down
9 changes: 9 additions & 0 deletions components/ws-manager-bridge/src/cluster-service-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -141,6 +149,7 @@ export class ClusterService implements IClusterServiceServer {
const newCluster: WorkspaceCluster = {
name: req.name,
url: req.url,
applicationCluster,
state,
score,
maxScore: 100,
Expand Down