Skip to content

Commit

Permalink
[ISSUE-35] Be more resilient against unexpected cluster specs
Browse files Browse the repository at this point in the history
Fixes #35

When deserializing clusters discovered in the MCC instance, try
each one independently rather than in bulk, and keep the ones
that succeed instead of throwing them all out if just one fails.

Also, this implicitly ignores clusters that do not yet have any
nodes, presumably because they have just been provisioned and
nodes haven't been created yet. This is because those clusters
will not have a `providerStatus` object which contains information
required to generate kubeconfig files, such as the
`apiServerCertificate`.
  • Loading branch information
stefcameron committed Dec 15, 2020
1 parent 389fd30 commit ebf3a8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/cc/store/ClustersProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,22 @@ const _deserializeClustersList = function (body) {
return { error: strings.clusterProvider.error.invalidClusterPayload() };
}

try {
return { data: body.items.map((item) => new Cluster(item)) };
} catch (err) {
// eslint-disable-next-line no-console -- OK to show errors
console.error(
`[${pkg.name}/ClustersProvider._deserializeClustersList()] ERROR: ${err.message}`,
err
);
return { error: strings.clustersProvider.errors.invalidCluster() };
}
return {
data: body.items
.map((item, idx) => {
try {
return new Cluster(item);
} catch (err) {
// eslint-disable-next-line no-console -- OK to show errors
console.error(
`[${pkg.name}/ClustersProvider._deserializeClustersList()] ERROR with cluster ${idx}: ${err.message}`,
err
);
return undefined;
}
})
.filter((cl) => !!cl), // eliminate failed clusters (`undefined` items)
};
};

/**
Expand Down
2 changes: 0 additions & 2 deletions src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ export const clustersProvider: Dict = {
'Encountered at least one namespace with unexpected or missing metadata.',
invalidClusterPayload: () =>
'Failed to parse cluster payload: Unexpected data format.',
invalidCluster: () =>
'Encountered at least one cluster with unexpected or missing metadata.',
},
};

Expand Down

0 comments on commit ebf3a8c

Please sign in to comment.