From 7e35657cf1e1d0bcd408a133cd953c468a7e7ff0 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 25 Aug 2020 09:45:47 -0700 Subject: [PATCH] node.cluster is optional in the bootstrap file --- packages/grpc-js/src/xds-bootstrap.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/grpc-js/src/xds-bootstrap.ts b/packages/grpc-js/src/xds-bootstrap.ts index b8e446b2..47e7679e 100644 --- a/packages/grpc-js/src/xds-bootstrap.ts +++ b/packages/grpc-js/src/xds-bootstrap.ts @@ -157,15 +157,6 @@ function validateNode(obj: any): Node { throw new Error(`node.id field: expected string, got ${typeof obj.id}`); } result.id = obj.id; - if (!('cluster' in obj)) { - throw new Error('cluster field missing in node element'); - } - if (typeof obj.cluster !== 'string') { - throw new Error( - `node.cluster field: expected string, got ${typeof obj.cluster}` - ); - } - result.cluster = obj.cluster; if (!('locality' in obj)) { throw new Error('locality field missing in node element'); } @@ -197,6 +188,14 @@ function validateNode(obj: any): Node { } result.locality.sub_zone = obj.locality.sub_zone; } + if ('cluster' in obj) { + if (typeof obj.cluster !== 'string') { + throw new Error( + `node.cluster field: expected string, got ${typeof obj.cluster}` + ); + } + result.cluster = obj.cluster; + } if ('metadata' in obj) { result.metadata = getStructFromJson(obj.metadata); }