load k8s info with only label selector query

[Docs](https://backstage.io/docs/features/kubernetes/configuration#surfacing-your-kubernetes-components-as-part-of-an-entity)
say `label selector takes precedence over the annotation/service id.`
but ```
annotations:
  'backstage.io/kubernetes-id': dice-roller
```
is always required.
updated logic to allow for only label selector
(without backstage.io/kubernetes-id)
This commit is contained in:
Fidel Coria
2021-02-19 17:05:18 -06:00
parent 6f0ed05c2c
commit 272d960550
2 changed files with 19 additions and 12 deletions
+18 -10
View File
@@ -23,6 +23,8 @@ import { KubernetesContent } from './components/KubernetesContent';
import { MissingAnnotationEmptyState } from '@backstage/core';
const KUBERNETES_ANNOTATION = 'backstage.io/kubernetes-id';
const KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION =
'backstage.io/kubernetes-label-selector';
type Props = {
/** @deprecated The entity is now grabbed from context instead */
@@ -35,16 +37,22 @@ export const Router = (_props: Props) => {
const kubernetesAnnotationValue =
entity.metadata.annotations?.[KUBERNETES_ANNOTATION];
if (!kubernetesAnnotationValue) {
return <MissingAnnotationEmptyState annotation={KUBERNETES_ANNOTATION} />;
const kubernetesLabelSelectorQueryAnnotationValue =
entity.metadata.annotations?.[KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION];
if (
kubernetesAnnotationValue ||
kubernetesLabelSelectorQueryAnnotationValue
) {
return (
<Routes>
<Route
path={`/${rootCatalogKubernetesRouteRef.path}`}
element={<KubernetesContent entity={entity} />}
/>
</Routes>
);
}
return (
<Routes>
<Route
path={`/${rootCatalogKubernetesRouteRef.path}`}
element={<KubernetesContent entity={entity} />}
/>
</Routes>
);
return <MissingAnnotationEmptyState annotation={KUBERNETES_ANNOTATION} />;
};