Skip to content

Commit ebf3a8c

Browse files
committed
[ISSUE-35] Be more resilient against unexpected cluster specs
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`.
1 parent 389fd30 commit ebf3a8c

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/cc/store/ClustersProvider.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,22 @@ const _deserializeClustersList = function (body) {
120120
return { error: strings.clusterProvider.error.invalidClusterPayload() };
121121
}
122122

123-
try {
124-
return { data: body.items.map((item) => new Cluster(item)) };
125-
} catch (err) {
126-
// eslint-disable-next-line no-console -- OK to show errors
127-
console.error(
128-
`[${pkg.name}/ClustersProvider._deserializeClustersList()] ERROR: ${err.message}`,
129-
err
130-
);
131-
return { error: strings.clustersProvider.errors.invalidCluster() };
132-
}
123+
return {
124+
data: body.items
125+
.map((item, idx) => {
126+
try {
127+
return new Cluster(item);
128+
} catch (err) {
129+
// eslint-disable-next-line no-console -- OK to show errors
130+
console.error(
131+
`[${pkg.name}/ClustersProvider._deserializeClustersList()] ERROR with cluster ${idx}: ${err.message}`,
132+
err
133+
);
134+
return undefined;
135+
}
136+
})
137+
.filter((cl) => !!cl), // eliminate failed clusters (`undefined` items)
138+
};
133139
};
134140

135141
/**

src/strings.ts

-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ export const clustersProvider: Dict = {
160160
'Encountered at least one namespace with unexpected or missing metadata.',
161161
invalidClusterPayload: () =>
162162
'Failed to parse cluster payload: Unexpected data format.',
163-
invalidCluster: () =>
164-
'Encountered at least one cluster with unexpected or missing metadata.',
165163
},
166164
};
167165

0 commit comments

Comments
 (0)