Skip to content

Commit

Permalink
add annotation check
Browse files Browse the repository at this point in the history
this helps with configurability of the plugins
so that the plugins only show for the components
with the right set of annotations on them
  • Loading branch information
nimakaviani committed Aug 17, 2023
1 parent ddc975a commit f0c8da6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const serviceEntityPage = (

...

<EntityLayout.Route path="/apache-spark" title="Spark">
<EntityLayout.Route path="/apache-spark" title="Spark" if={isApacheSparkAvailable}>
<ApacheSparkPage />
</EntityLayout.Route>

Expand All @@ -57,16 +57,11 @@ const serviceEntityPage = (
```

#### Annotations
- `apache-spark.cnoe.io/label-selector`: Required. This value corresponds to the label on
the Pod running the Spark job.
- `backstage.io/kubernetes-namespace`: Optional. Defaults to the `default` namespace.
- `apache-spark.cnoe.io/label-selector`: This value takes precedent over the one above.
- `apache-spark.cnoe.io/cluster-name`: Optional. Specifies the name of Kubernetes cluster to retrieve information from.

you can also use the `backstage.io/kubernetes-label-selector`, to select the
relevant spark jobs. However , `backstage.io/kubernetes-label-selector` is a
generic label selector used more widely by the Kubernetes plugin which could
pull other less relevant data pulled into your backstage deployment as well. We
recommend using `apache-spark.cnoe.io/label-selector` when using this plugin.

### Authentication

This plugin uses the Kubernetes plugin for authentication.
Expand Down
9 changes: 2 additions & 7 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Entity } from '@backstage/catalog-model';
import {Entity} from '@backstage/catalog-model';
import {
APACHE_SPARK_LABEL_SELECTOR_ANNOTATION,
CLUSTER_NAME_ANNOTATION,
K8S_LABEL_SELECTOR_ANNOTATION,
K8S_NAMESPACE_ANNOTATION,
} from '../consts';

Expand All @@ -18,11 +17,7 @@ export function getAnnotationValues(entity: Entity): getAnnotationValuesOutput {
? entity.metadata.annotations?.[K8S_NAMESPACE_ANNOTATION]
: 'default';
const clusterName = entity.metadata.annotations?.[CLUSTER_NAME_ANNOTATION];
const labelSelector =
entity.metadata?.annotations?.[APACHE_SPARK_LABEL_SELECTOR_ANNOTATION] !==
undefined
? entity.metadata?.annotations?.[APACHE_SPARK_LABEL_SELECTOR_ANNOTATION]
: entity.metadata.annotations?.[K8S_LABEL_SELECTOR_ANNOTATION];
const labelSelector = entity.metadata?.annotations?.[APACHE_SPARK_LABEL_SELECTOR_ANNOTATION]
return {
ns: ns,
clusterName: clusterName,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { apacheSparkPlugin, ApacheSparkPage } from './plugin';
export {apacheSparkPlugin, ApacheSparkPage, isApacheSparkAvailable} from './plugin';
16 changes: 12 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import {
createRoutableExtension,
} from '@backstage/core-plugin-api';

import { rootRouteRef } from './routes';
import { apacheSparkApiRef, ApacheSparkClient } from './api';
import { kubernetesApiRef } from '@backstage/plugin-kubernetes';
import {rootRouteRef} from './routes';
import {apacheSparkApiRef, ApacheSparkClient} from './api';
import {kubernetesApiRef} from '@backstage/plugin-kubernetes';
import {Entity} from '@backstage/catalog-model';

import {
APACHE_SPARK_LABEL_SELECTOR_ANNOTATION,
} from './consts';

export const isApacheSparkAvailable = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[APACHE_SPARK_LABEL_SELECTOR_ANNOTATION]);

export const apacheSparkPlugin = createPlugin({
id: 'apache-spark',
Expand All @@ -19,7 +27,7 @@ export const apacheSparkPlugin = createPlugin({
deps: {
kubernetesApi: kubernetesApiRef,
},
factory: ({ kubernetesApi }) => new ApacheSparkClient(kubernetesApi),
factory: ({kubernetesApi}) => new ApacheSparkClient(kubernetesApi),
}),
],
});
Expand Down

0 comments on commit f0c8da6

Please sign in to comment.