Skip to content

Commit 1f416e1

Browse files
authored
Improve Labels for Resources (#64)
This commit improves the labels for resources shown in the select menu. This was done to make it easier for users to identify the correct resource they want to display. Which is required because different CRDs can have the same kind but different API groups.
1 parent 8c5f899 commit 1f416e1

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

src/datasource/datasource.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,53 @@ export class DataSource extends DataSourceWithBackend<
214214
// the kind is used as text.
215215
if (query.queryType === 'kubernetes-resourceids') {
216216
return response
217-
? (response.data[0] as DataFrame).fields[0].values.map((_, index) => ({
218-
value: _.toString(),
219-
text: (response.data[0] as DataFrame).fields[1].values[
217+
? (response.data[0] as DataFrame).fields[0].values.map((_, index) => {
218+
const kind = (response.data[0] as DataFrame).fields[1].values[
220219
index
221-
].toString(),
222-
}))
220+
].toString();
221+
222+
let apiVersion = '';
223+
const parts = (response.data[0] as DataFrame).fields[2].values[
224+
index
225+
]
226+
.toString()
227+
.split('/');
228+
if (
229+
parts.length === 2 &&
230+
![
231+
'admissionregistration.k8s.io',
232+
'apiextensions.k8s.io',
233+
'apiregistration.k8s.io',
234+
'apps',
235+
'authentication.k8s.io',
236+
'authorization.k8s.io',
237+
'autoscaling',
238+
'autoscaling.k8s.io',
239+
'batch',
240+
'certificates.k8s.io',
241+
'coordination.k8s.io',
242+
'discovery.k8s.io',
243+
'flowcontrol.apiserver.k8s.io',
244+
'gateway.networking.k8s.io',
245+
'metrics.k8s.io',
246+
'networking.k8s.io',
247+
'node.k8s.io',
248+
'policy',
249+
'rbac.authorization.k8s.io',
250+
'resource.k8s.io',
251+
'scheduling.k8s.io',
252+
'snapshot.storage.k8s.io',
253+
'storage.k8s.io',
254+
].includes(parts[0])
255+
) {
256+
apiVersion = parts[0];
257+
}
258+
259+
return {
260+
value: _.toString(),
261+
text: `${kind}${apiVersion ? ` (${apiVersion})` : ''}`,
262+
};
263+
})
223264
: [];
224265
}
225266

0 commit comments

Comments
 (0)