-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server] Use workspace cluster as image-builder (feature flag: "moved…
…ImageBuilder")
- Loading branch information
Showing
7 changed files
with
144 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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
57 changes: 57 additions & 0 deletions
57
components/server/src/workspace/workspace-cluster-imagebuilder-client-provider.ts
This file contains 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,57 @@ | ||
/** | ||
* 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 { Workspace, WorkspaceInstance } from "@gitpod/gitpod-protocol"; | ||
import { IClientCallMetrics } from "@gitpod/gitpod-protocol/lib/messaging/client-call-metrics"; | ||
import { defaultGRPCOptions } from "@gitpod/gitpod-protocol/lib/util/grpc"; | ||
import { | ||
ImageBuilderClient, | ||
ImageBuilderClientCallMetrics, | ||
ImageBuilderClientProvider, | ||
PromisifiedImageBuilderClient, | ||
} from "@gitpod/image-builder/lib"; | ||
import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider"; | ||
import { | ||
WorkspaceManagerClientProviderCompositeSource, | ||
WorkspaceManagerClientProviderSource, | ||
} from "@gitpod/ws-manager/lib/client-provider-source"; | ||
import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints"; | ||
import { inject, injectable, optional } from "inversify"; | ||
|
||
@injectable() | ||
export class WorkspaceClusterImagebuilderClientProvider implements ImageBuilderClientProvider { | ||
@inject(WorkspaceManagerClientProviderCompositeSource) | ||
protected readonly source: WorkspaceManagerClientProviderSource; | ||
@inject(WorkspaceManagerClientProvider) protected readonly clientProvider: WorkspaceManagerClientProvider; | ||
@inject(ImageBuilderClientCallMetrics) @optional() protected readonly clientCallMetrics: IClientCallMetrics; | ||
|
||
// gRPC connections can be used concurrently, even across services. | ||
// Thus it makes sense to cache them rather than create a new connection for each request. | ||
protected readonly connectionCache = new Map<string, ImageBuilderClient>(); | ||
|
||
async getClient( | ||
user: ExtendedUser, | ||
workspace: Workspace, | ||
instance: WorkspaceInstance, | ||
): Promise<PromisifiedImageBuilderClient> { | ||
const clusters = await this.clientProvider.getStartClusterSets(user, workspace, instance); | ||
for await (let cluster of clusters) { | ||
const info = await this.source.getWorkspaceCluster(cluster.installation); | ||
if (!info) { | ||
continue; | ||
} | ||
|
||
var client = this.connectionCache.get(info.name); | ||
if (!client) { | ||
client = this.clientProvider.createConnection(ImageBuilderClient, info, defaultGRPCOptions); | ||
this.connectionCache.set(info.name, client); | ||
} | ||
return new PromisifiedImageBuilderClient(client, []); | ||
} | ||
|
||
throw new Error("no image-builder available"); | ||
} | ||
} |
This file contains 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 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 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