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

App Topology: Add filter resources by cluster functionality in Topology view #121

Closed
4 tasks done
Tracked by #58
divyanshiGupta opened this issue Feb 14, 2023 · 1 comment
Closed
4 tasks done
Tracked by #58
Assignees

Comments

@divyanshiGupta
Copy link
Collaborator

divyanshiGupta commented Feb 14, 2023

Description:
Currently only the first cluster resources are being visualised in topology but as a user I would like to be able to filter resources by cluster in case of multiple clusters.

Acceptance Criteria:

  • Add a dropdown cluster filter in the toolbar
  • On selecting a cluster from the filter only the resources of that cluster should be shown
  • Add a toolbar in topology view
  • Show error (if any while fetching clusters/resources) similar to k8s plugin
@divyanshiGupta divyanshiGupta changed the title Add filter resources by cluster functionality in Topology view App Topology: Add filter resources by cluster functionality in Topology view Feb 14, 2023
@divyanshiGupta divyanshiGupta self-assigned this Feb 14, 2023
invincibleJai pushed a commit that referenced this issue Mar 20, 2023
…logy plugin (#146)

**Story:** #121

**Description:**
This PR adds a toolbar in topology view consisting of a filter by
cluster dropdown which lists all the available clusters and the user can
select the cluster they want to see the resources for. It also shows any
errors while fetching the resources in the topology view.


https://user-images.githubusercontent.com/20724543/224062140-6bc1ee4b-794e-4455-9e16-bb24542dbd21.mov

**Test Setup:**
Install and configure kubernetes plugin by following these guides:

https://backstage.io/docs/features/kubernetes/installation
https://backstage.io/docs/features/kubernetes/configuration

Kubernetes plugin is properly configured and able to connect to the
cluster via a ServiceAccount

Following ClusterRole must be granted to ServiceAccount accessing the
cluster:
(k8s plugin by default tries to fetch the following resources and if
access is not provided an error is shown)

```
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: backstage-read-only
rules:
  - apiGroups:
      - '*'
    resources:
      - pods
      - configmaps
      - services
      - deployments
      - replicasets
      - horizontalpodautoscalers
      - ingresses
      - statefulsets
      - limitranges
      - daemonsets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - batch
    resources:
      - jobs
      - cronjobs
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - metrics.k8s.io
    resources:
      - pods
    verbs:
      - get
      - list
 ```
 
Create a service component entity - https://github.com/temp-demo-organisation/nationalparks-py/blob/master/catalog-info2.yaml

To get the resources from a k8s cluster do the following:

K8s plugin identifies if the provided entity has k8s resources and if yes from which namespace it should get the resources based on the following annotations added to the entity's catalog-info.yaml
```
annotations: 
 backstage.io/kubernetes-id: nationalparks-py
 backstage.io/kubernetes-namespace: div
```

For k8s plugin to get the desired entity's k8s resources the following label should be added to the resources `'backstage.io/kubernetes-id': nationalparks-py`

A custom label selector can also be added which will then be used by Backstage to find the resources. The label selector takes precedence over the id annotation.
`'backstage.io/kubernetes-label-selector': 'app=my-app,component=front-end`

In order to use k8s plugin to get the resources for Topology view, the above annotations/labels should be in place.

Enable additional tab on the entity view page

   ```ts
   // packages/app/src/components/catalog/EntityPage.tsx
   import { TopologyPage } from '@janus-idp/backstage-plugin-topology';

   const serviceEntityPage = (
     <EntityPageLayout>
       // ...
       <EntityLayout.Route path="/topology" title="Topology">
        <TopologyPage />
       </EntityLayout.Route>
     </EntityPageLayout>
   );
   ```

**To Do:**
- [x] Add a dropdown cluster filter in the toolbar
- [x] On selecting a cluster from the filter only the resources of that cluster should be shown
- [x] Add a toolbar in topology view
- [x] Show error (if any while fetching clusters/resources) similar to k8s plugin
@divyanshiGupta
Copy link
Collaborator Author

Closing this as associated PR - #146 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant