@@ -35,7 +35,12 @@ import {
35
35
UpdateResponse ,
36
36
AdmissionConstraint as GRPCAdmissionConstraint ,
37
37
} from "@gitpod/ws-manager-bridge-api/lib" ;
38
- import { DescribeClusterRequest , DescribeClusterResponse , WorkspaceClass } from "@gitpod/ws-manager/lib" ;
38
+ import {
39
+ DescribeClusterRequest ,
40
+ DescribeClusterResponse ,
41
+ GetWorkspacesRequest ,
42
+ WorkspaceClass ,
43
+ } from "@gitpod/ws-manager/lib" ;
39
44
import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider" ;
40
45
import {
41
46
WorkspaceManagerClientProviderCompositeSource ,
@@ -46,6 +51,7 @@ import { ServiceError as grpcServiceError } from "@grpc/grpc-js";
46
51
import { inject , injectable } from "inversify" ;
47
52
import { BridgeController } from "./bridge-controller" ;
48
53
import { Configuration } from "./config" ;
54
+ import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server" ;
49
55
50
56
export interface ClusterServiceServerOptions {
51
57
port : number ;
@@ -149,8 +155,32 @@ export class ClusterService implements IClusterServiceServer {
149
155
tls,
150
156
} ;
151
157
152
- let classConstraints = await getSupportedWorkspaceClasses ( this . clientProvider , newCluster ) ;
153
- newCluster . admissionConstraints = admissionConstraints . concat ( classConstraints ) ;
158
+ const enabled = await getExperimentsClientForBackend ( ) . getValueAsync (
159
+ "workspace_classes_backend" ,
160
+ false ,
161
+ { } ,
162
+ ) ;
163
+ if ( enabled ) {
164
+ let classConstraints = await getSupportedWorkspaceClasses ( this . clientProvider , newCluster ) ;
165
+ newCluster . admissionConstraints = admissionConstraints . concat ( classConstraints ) ;
166
+ } else {
167
+ // try to connect to validate the config. Throws an exception if it fails.
168
+ await new Promise < void > ( ( resolve , reject ) => {
169
+ const c = this . clientProvider . createClient ( newCluster ) ;
170
+ c . getWorkspaces ( new GetWorkspacesRequest ( ) , ( err : any ) => {
171
+ if ( err ) {
172
+ reject (
173
+ new GRPCError (
174
+ grpc . status . FAILED_PRECONDITION ,
175
+ `cannot reach ${ req . url } : ${ err . message } ` ,
176
+ ) ,
177
+ ) ;
178
+ } else {
179
+ resolve ( ) ;
180
+ }
181
+ } ) ;
182
+ } ) ;
183
+ }
154
184
155
185
await this . clusterDB . save ( newCluster ) ;
156
186
log . info ( { } , "cluster registered" , { cluster : req . name } ) ;
@@ -433,8 +463,11 @@ export class ClusterSyncService {
433
463
434
464
protected timer : NodeJS . Timer ;
435
465
436
- public start ( ) {
437
- this . timer = setInterval ( ( ) => this . reconcile ( ) , this . config . clusterSyncIntervalSeconds * 1000 ) ;
466
+ public async start ( ) {
467
+ const enabled = await getExperimentsClientForBackend ( ) . getValueAsync ( "workspace_classes_backend" , false , { } ) ;
468
+ if ( enabled ) {
469
+ this . timer = setInterval ( ( ) => this . reconcile ( ) , this . config . clusterSyncIntervalSeconds * 1000 ) ;
470
+ }
438
471
}
439
472
440
473
private async reconcile ( ) {
@@ -453,8 +486,11 @@ export class ClusterSyncService {
453
486
log . debug ( "done reconciling workspace classes" ) ;
454
487
}
455
488
456
- public stop ( ) {
457
- clearInterval ( this . timer ) ;
489
+ public async stop ( ) {
490
+ const enabled = await getExperimentsClientForBackend ( ) . getValueAsync ( "workspace_classes_backend" , false , { } ) ;
491
+ if ( enabled ) {
492
+ clearInterval ( this . timer ) ;
493
+ }
458
494
}
459
495
}
460
496
0 commit comments