-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
configs.ts
276 lines (268 loc) · 8.52 KB
/
configs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// Copyright 2019 The Kubeflow Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as path from 'path';
import { loadJSON } from './utils';
import { loadArtifactsProxyConfig, ArtifactsProxyConfig } from './handlers/artifacts';
export const BASEPATH = '/pipeline';
export const apiVersion = 'v1beta1';
export const apiVersionPrefix = `apis/${apiVersion}`;
export enum Deployments {
NOT_SPECIFIED = 'NOT_SPECIFIED',
KUBEFLOW = 'KUBEFLOW',
MARKETPLACE = 'MARKETPLACE',
}
/** converts string to bool */
const asBool = (value: string) => ['true', '1'].includes(value.toLowerCase());
function parseArgs(argv: string[]) {
if (argv.length < 3) {
const msg = `\
Usage: node server.js <static-dir> [port].
You can specify the API server address using the
ML_PIPELINE_SERVICE_HOST and ML_PIPELINE_SERVICE_PORT
env vars.`;
throw new Error(msg);
}
const staticDir = path.resolve(argv[2]);
const port = parseInt(argv[3] || '3000', 10);
return { staticDir, port };
}
export type ProcessEnv = NodeJS.ProcessEnv | { [key: string]: string };
export function loadConfigs(argv: string[], env: ProcessEnv): UIConfigs {
const { staticDir, port } = parseArgs(argv);
/** All configurable environment variables can be found here. */
const {
/** minio client use these to retrieve minio objects/artifacts */
MINIO_ACCESS_KEY = 'minio',
MINIO_SECRET_KEY = 'minio123',
MINIO_PORT = '9000',
MINIO_HOST = 'minio-service',
MINIO_NAMESPACE = 'kubeflow',
MINIO_SSL = 'false',
/** minio client use these to retrieve s3 objects/artifacts */
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
AWS_REGION,
AWS_S3_ENDPOINT,
/** http/https base URL */
HTTP_BASE_URL = '',
/** http/https fetch with this authorization header key (for example: 'Authorization') */
HTTP_AUTHORIZATION_KEY = '',
/** http/https fetch with this authorization header value by default when absent in client request at above key */
HTTP_AUTHORIZATION_DEFAULT_VALUE = '',
/** API service will listen to this host */
ML_PIPELINE_SERVICE_HOST = 'localhost',
/** API service will listen to this port */
ML_PIPELINE_SERVICE_PORT = '3001',
/** path to viewer:tensorboard pod template spec */
VIEWER_TENSORBOARD_POD_TEMPLATE_SPEC_PATH,
/** Tensorflow image used for tensorboard viewer */
VIEWER_TENSORBOARD_TF_IMAGE_NAME = 'tensorflow/tensorflow',
/** Whether custom visualizations are allowed to be generated by the frontend */
ALLOW_CUSTOM_VISUALIZATIONS = 'false',
/** Envoy service will listen to this host */
METADATA_ENVOY_SERVICE_SERVICE_HOST = 'localhost',
/** Envoy service will listen to this port */
METADATA_ENVOY_SERVICE_SERVICE_PORT = '9090',
/** Is Argo log archive enabled? */
ARGO_ARCHIVE_LOGS = 'false',
/** Use minio or s3 client to retrieve archives. */
ARGO_ARCHIVE_ARTIFACTORY = 'minio',
/** Bucket to retrive logs from */
ARGO_ARCHIVE_BUCKETNAME = 'mlpipeline',
/** Prefix to logs. */
ARGO_ARCHIVE_PREFIX = 'logs',
/** Should use server API for log streaming? */
STREAM_LOGS_FROM_SERVER_API = 'false',
/** Disables GKE metadata endpoint. */
DISABLE_GKE_METADATA = 'false',
/** Enable authorization checks for multi user mode. */
ENABLE_AUTHZ = 'false',
/** Deployment type. */
DEPLOYMENT: DEPLOYMENT_STR = '',
/**
* Set to true to hide the SideNav. When DEPLOYMENT is KUBEFLOW, HIDE_SIDENAV
* defaults to true if not explicitly set to false.
*/
HIDE_SIDENAV,
/**
* A header user requests have when authenticated. It carries user identity information.
* The default value works with Google Cloud IAP.
*/
KUBEFLOW_USERID_HEADER = 'x-goog-authenticated-user-email',
/**
* KUBEFLOW_USERID_HEADER's value may have a prefix before user identity.
* Use this header to specify what the prefix is.
*
* e.g. a valid header value for default values can be like `accounts.google.com:[email protected]`.
*/
KUBEFLOW_USERID_PREFIX = 'accounts.google.com:',
} = env;
return {
argo: {
archiveArtifactory: ARGO_ARCHIVE_ARTIFACTORY,
archiveBucketName: ARGO_ARCHIVE_BUCKETNAME,
archiveLogs: asBool(ARGO_ARCHIVE_LOGS),
archivePrefix: ARGO_ARCHIVE_PREFIX,
},
artifacts: {
aws: {
accessKey: AWS_ACCESS_KEY_ID || '',
endPoint: AWS_S3_ENDPOINT || 's3.amazonaws.com',
region: AWS_REGION || 'us-east-1',
secretKey: AWS_SECRET_ACCESS_KEY || '',
},
http: {
auth: {
defaultValue: HTTP_AUTHORIZATION_DEFAULT_VALUE,
key: HTTP_AUTHORIZATION_KEY,
},
baseUrl: HTTP_BASE_URL,
},
minio: {
accessKey: MINIO_ACCESS_KEY,
endPoint:
MINIO_NAMESPACE && MINIO_NAMESPACE.length > 0
? `${MINIO_HOST}.${MINIO_NAMESPACE}`
: MINIO_HOST,
port: parseInt(MINIO_PORT, 10),
secretKey: MINIO_SECRET_KEY,
useSSL: asBool(MINIO_SSL),
},
proxy: loadArtifactsProxyConfig(env),
streamLogsFromServerApi: asBool(STREAM_LOGS_FROM_SERVER_API),
},
metadata: {
envoyService: {
host: METADATA_ENVOY_SERVICE_SERVICE_HOST,
port: METADATA_ENVOY_SERVICE_SERVICE_PORT,
},
},
pipeline: {
host: ML_PIPELINE_SERVICE_HOST,
port: ML_PIPELINE_SERVICE_PORT,
},
server: {
apiVersionPrefix,
basePath: BASEPATH,
deployment:
DEPLOYMENT_STR.toUpperCase() === Deployments.KUBEFLOW
? Deployments.KUBEFLOW
: DEPLOYMENT_STR.toUpperCase() === Deployments.MARKETPLACE
? Deployments.MARKETPLACE
: Deployments.NOT_SPECIFIED,
hideSideNav:
HIDE_SIDENAV === undefined
? DEPLOYMENT_STR.toUpperCase() === Deployments.KUBEFLOW
: asBool(HIDE_SIDENAV),
port,
staticDir,
},
viewer: {
tensorboard: {
podTemplateSpec: loadJSON<object>(VIEWER_TENSORBOARD_POD_TEMPLATE_SPEC_PATH),
tfImageName: VIEWER_TENSORBOARD_TF_IMAGE_NAME,
},
},
visualizations: {
allowCustomVisualizations: asBool(ALLOW_CUSTOM_VISUALIZATIONS),
},
gkeMetadata: {
disabled: asBool(DISABLE_GKE_METADATA),
},
auth: {
enabled: asBool(ENABLE_AUTHZ),
kubeflowUserIdHeader: KUBEFLOW_USERID_HEADER,
kubeflowUserIdPrefix: KUBEFLOW_USERID_PREFIX,
},
};
}
export interface MinioConfigs {
accessKey: string;
secretKey: string;
endPoint: string;
port: number;
useSSL: boolean;
}
export interface AWSConfigs {
endPoint: string;
region: string;
accessKey: string;
secretKey: string;
}
export interface HttpConfigs {
baseUrl: string;
auth: {
key: string;
defaultValue: string;
};
}
export interface PipelineConfigs {
host: string;
port: string | number;
}
export interface ViewerTensorboardConfig {
podTemplateSpec?: object;
tfImageName: string;
}
export interface ViewerConfigs {
tensorboard: ViewerTensorboardConfig;
}
export interface VisualizationsConfigs {
allowCustomVisualizations: boolean;
}
export interface MetadataConfigs {
envoyService: {
host: string;
port: string | number;
};
}
export interface ArgoConfigs {
archiveLogs: boolean;
archiveArtifactory: string;
archiveBucketName: string;
archivePrefix: string;
}
export interface ServerConfigs {
basePath: string;
port: string | number;
staticDir: string;
apiVersionPrefix: string;
deployment: Deployments;
hideSideNav: boolean;
}
export interface GkeMetadataConfigs {
disabled: boolean;
}
export interface AuthConfigs {
enabled: boolean;
kubeflowUserIdHeader: string;
kubeflowUserIdPrefix: string;
}
export interface UIConfigs {
server: ServerConfigs;
artifacts: {
aws: AWSConfigs;
minio: MinioConfigs;
http: HttpConfigs;
proxy: ArtifactsProxyConfig;
streamLogsFromServerApi: boolean;
};
argo: ArgoConfigs;
metadata: MetadataConfigs;
visualizations: VisualizationsConfigs;
viewer: ViewerConfigs;
pipeline: PipelineConfigs;
gkeMetadata: GkeMetadataConfigs;
auth: AuthConfigs;
}