Skip to content

Commit

Permalink
Fix node server typing problems (#2807)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobgy authored and k8s-ci-robot committed Jan 7, 2020
1 parent 07efee5 commit 70bce6d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 29 deletions.
2 changes: 1 addition & 1 deletion frontend/server/aws-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AWSInstanceProfileCredentials {
/**
* Get the AWS metadata store session credentials.
*/
async getCredentials(): Promise<AWSMetadataCredentials> {
async getCredentials(): Promise<AWSMetadataCredentials | undefined> {
// query for credentials if going to expire or no credentials yet
if (Date.now() + 10 >= this._expiration || !this._credentials) {
this._credentials = await this._fetchCredentials();
Expand Down
6 changes: 3 additions & 3 deletions frontend/server/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export function loadConfigs(
},
artifacts: {
aws: {
accessKey: AWS_ACCESS_KEY_ID,
accessKey: AWS_ACCESS_KEY_ID || '',
endPoint: 's3.amazonaws.com',
secretKey: AWS_SECRET_ACCESS_KEY,
secretKey: AWS_SECRET_ACCESS_KEY || '',
},
http: {
auth: {
Expand Down Expand Up @@ -140,7 +140,7 @@ export function loadConfigs(
},
viewer: {
tensorboard: {
podTemplateSpec: loadJSON<object | undefined>(VIEWER_TENSORBOARD_POD_TEMPLATE_SPEC_PATH),
podTemplateSpec: loadJSON<object>(VIEWER_TENSORBOARD_POD_TEMPLATE_SPEC_PATH),
},
},
visualizations: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/server/k8s-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ export async function getArgoWorkflow(workflowName: string): Promise<PartialArgo
workflowName,
);

if (res.response.statusCode == null) {
throw new Error(`Unable to query workflow:${workflowName}: No status code present.`);
}

if (res.response.statusCode >= 400) {
throw new Error(`Unable to query workflow:${workflowName}: Access denied.`);
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/server/minio-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function getTarObjectAsString({ bucket, key, client }: MinioRequestConfig
try {
const stream = await getObjectStream({ bucket, key, client });
let contents = '';
stream.pipe(new tar.Parse()).on('entry', (entry: Stream) => {
// TODO: fix tar.Parse typing problem
stream.pipe(new (tar.Parse as any)()).on('entry', (entry: Stream) => {
entry.on('data', buffer => (contents += buffer.toString()));
});
stream.on('end', () => {
Expand Down
53 changes: 39 additions & 14 deletions frontend/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion frontend/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
"lodash": ">=4.17.13",
"minio": "^7.0.0",
"node-fetch": "^2.1.2",
"tar": "^4.4.11"
"tar": "^4.4.13"
},
"devDependencies": {
"@types/crypto-js": "^3.1.43",
"@types/express": "^4.11.1",
"@types/jest": "^24.0.23",
"@types/minio": "^7.0.3",
"@types/node": "^10.17.11",
"@types/node-fetch": "^2.1.2",
"@types/supertest": "^2.0.8",
"@types/tar": "^4.0.3",
"jest": "^24.9.0",
"supertest": "^4.0.2",
"ts-jest": "^24.2.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function generateRandomString(length: number): string {
return str;
}

export function loadJSON<T>(filepath: string, defaultValue?: T): T {
export function loadJSON<T>(filepath?: string, defaultValue?: T): T | undefined {
if (!filepath) {
return defaultValue;
}
Expand Down
16 changes: 8 additions & 8 deletions frontend/server/workflow-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ export async function getPodLogsMinioRequestConfigfromWorkflow(
throw new Error(`Unable to retrieve workflow status: ${err}.`);
}

let artifacts: ArtifactRecord[] | undefined;
// check if required fields are available
if (
!workflow.status ||
!workflow.status.nodes ||
!workflow.status.nodes[podName] ||
!workflow.status.nodes[podName].outputs ||
!workflow.status.nodes[podName].outputs.artifacts
) {
if (workflow.status && workflow.status.nodes) {
const node = workflow.status.nodes[podName];
if (node && node.outputs && node.outputs.artifacts) {
artifacts = node.outputs.artifacts;
}
}
if (!artifacts) {
throw new Error('Unable to find pod info in workflow status to retrieve logs.');
}

const artifacts: ArtifactRecord[] = workflow.status.nodes[podName].outputs.artifacts;
const archiveLogs: ArtifactRecord[] = artifacts.filter((artifact: any) => artifact.archiveLogs);

if (archiveLogs.length === 0) {
Expand Down

0 comments on commit 70bce6d

Please sign in to comment.