Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argo workflow namespace annotation #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kind: Component
metadata:
name: backstage
annotations:
backstage.io/kubernetes-namespace: default
argo-workflows.cnoe.io/namespace: default
argo-workflows.cnoe.io/label-selector: env=dev,my=label
spec:
type: service
Expand Down Expand Up @@ -172,20 +172,37 @@ kubernetes:
caData: LS0t
```

For this configuration, the `argo-workflows/cluster-name` annotaton value must be `my-cluster-1`
For this configuration, the `argo-workflows.cnoe.io/cluster-name` annotaton value must be `my-cluster-1`

```yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: backstage
annotations:
backstage.io/kubernetes-namespace: default
argo-workflows.cnoe.io/namespace: default
argo-workflows.cnoe.io/label-selector: env=dev,my=label
argo-workflows/cluster-name: my-cluster-1
argo-workflows.cnoe.io/cluster-name: my-cluster-1
spec:
type: service
lifecycle: experimental
owner: user1
system: system1
```

If we remove the `argo-workflows.cnoe.io/namespace` annotation, it will show all label matched workflows across all namespaces.

```yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: backstage
annotations:
argo-workflows.cnoe.io/label-selector: env=dev,my=label
argo-workflows.cnoe.io/cluster-name: my-cluster-1
spec:
type: service
lifecycle: experimental
owner: user1
system: system1
```
7 changes: 2 additions & 5 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Entity} from "@backstage/catalog-model";
import {
ARGO_WORKFLOWS_LABEL_SELECTOR_ANNOTATION,
CLUSTER_NAME_ANNOTATION,
K8S_NAMESPACE_ANNOTATION,
ARGO_WORKFLOWS_NAMESPACE_ANNOTATION,
} from "../plugin";

export function trimBaseUrl(argoWorkflowsBaseUrl: string | undefined) {
Expand All @@ -19,10 +19,7 @@ export type getAnnotationValuesOutput = {
};

export function getAnnotationValues(entity: Entity): getAnnotationValuesOutput {
const ns =
entity.metadata.annotations?.[K8S_NAMESPACE_ANNOTATION] !== undefined
? entity.metadata.annotations?.[K8S_NAMESPACE_ANNOTATION]
: "default";
const ns = entity.metadata.annotations?.[ARGO_WORKFLOWS_NAMESPACE_ANNOTATION];
const clusterName = entity.metadata.annotations?.[CLUSTER_NAME_ANNOTATION];
const labelSelector = entity.metadata?.annotations?.[ARGO_WORKFLOWS_LABEL_SELECTOR_ANNOTATION]
return {
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ArgoWorkflows, argoWorkflowsApiRef} from "./api";
import {kubernetesApiRef} from "@backstage/plugin-kubernetes";

export const CLUSTER_NAME_ANNOTATION = "argo-workflows.cnoe.io/cluster-name";
export const K8S_NAMESPACE_ANNOTATION = "backstage.io/kubernetes-namespace";
export const ARGO_WORKFLOWS_NAMESPACE_ANNOTATION = "argo-workflows.cnoe.io/namespace";
export const ARGO_WORKFLOWS_LABEL_SELECTOR_ANNOTATION =
"argo-workflows.cnoe.io/label-selector";

Expand Down