Skip to content

Commit 1c198eb

Browse files
authored
Merge pull request #184 from guardian/an/optional-newstyle-role-detection
improve master-eligible node detection to handle missing roles array
2 parents ca23f0b + e33d3ef commit 1c198eb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/elasticsearch/elasticsearch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export class Elasticsearch {
3737
return this.execute(`/_nodes/${instance.privateIp}`).then((json: any) => {
3838
if (json._nodes.total === 1) {
3939
const nodeId: string = Object.keys(json.nodes)[0];
40-
const isMasterEligible: boolean = json.nodes[nodeId].settings.node.master == 'true' || json.nodes[nodeId].settings.node.roles.includes('master');
40+
const isMasterEligible: boolean = json.nodes[nodeId].settings.node.master == 'true'
41+
|| json.nodes[nodeId].settings.node.roles?.includes('master')
42+
|| false;
4143
return new ElasticsearchNode(instance, nodeId, isMasterEligible);
4244
} else {
4345
throw `expected information about a single node, but got: ${JSON.stringify(json)}`;

0 commit comments

Comments
 (0)