Skip to content

Commit

Permalink
frontend: Use selected namespaces when fetching lists in map view
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Dubenko <[email protected]>
  • Loading branch information
sniok committed Dec 4, 2024
1 parent f43ee8b commit 66d0146
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import ValidatingWebhookConfiguration from '../../../../lib/k8s/validatingWebhoo
import { GraphEdge, GraphSource } from '../../graph/graphModel';
import { getKindGroupColor, KubeIcon } from '../../kubeIcon/KubeIcon';
import { makeKubeObjectNode, makeKubeToKubeEdge } from '../GraphSources';
import { useNamespaces } from '../../../../redux/filterSlice';

const secretsSource: GraphSource = {
id: 'secrets',
label: 'Secrets',
icon: <KubeIcon kind="Secret" />,
isEnabledByDefault: false,
useData() {
const [secrets] = Secret.useList();

const [pods] = Pod.useList();
const [secrets] = Secret.useList({ namespace: useNamespaces() });
const [pods] = Pod.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!secrets || !pods) return null;
Expand Down Expand Up @@ -76,9 +76,9 @@ const configMapsSource: GraphSource = {
isEnabledByDefault: false,
icon: <KubeIcon kind="ConfigMap" />,
useData() {
const [configMaps] = ConfigMap.useList();
const [pods] = Pod.useList();
const [jobs] = Job.useList();
const [configMaps] = ConfigMap.useList({ namespace: useNamespaces() });
const [pods] = Pod.useList({ namespace: useNamespaces() });
const [jobs] = Job.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!configMaps || !pods || !jobs) return null;
Expand Down Expand Up @@ -123,8 +123,8 @@ const validatingWebhookConfigurationSource: GraphSource = {
icon: <KubeIcon kind="ConfigMap" />,
isEnabledByDefault: false,
useData() {
const [vwc] = ValidatingWebhookConfiguration.useList();
const [services] = Service.useList();
const [vwc] = ValidatingWebhookConfiguration.useList({ namespace: useNamespaces() });
const [services] = Service.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!vwc || !services) return null;
Expand Down Expand Up @@ -155,8 +155,8 @@ const mutatingWebhookConfigurationSource: GraphSource = {
icon: <KubeIcon kind="ConfigMap" />,
isEnabledByDefault: false,
useData() {
const [mwc] = MutatingWebhookConfiguration.useList();
const [services] = Service.useList();
const [mwc] = MutatingWebhookConfiguration.useList({ namespace: useNamespaces() });
const [services] = Service.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!mwc || !services) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { GraphEdge, GraphSource } from '../../graph/graphModel';
import { getKindGroupColor, KubeIcon } from '../../kubeIcon/KubeIcon';
import { makeKubeObjectNode, makeKubeToKubeEdge } from '../GraphSources';
import { matchesSelector } from './workloadSource';
import { useNamespaces } from '../../../../redux/filterSlice';

const serviceSource: GraphSource = {
id: 'services',
label: 'Services',
icon: <KubeIcon kind={'Service'} />,
useData() {
const [services] = Service.useList();
const [pods] = Pod.useList();
const [services] = Service.useList({ namespace: useNamespaces() });
const [pods] = Pod.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!services || !pods) return null;
Expand Down Expand Up @@ -46,8 +47,8 @@ const endpointsSource: GraphSource = {
label: 'Endpoints',
icon: <KubeIcon kind="Endpoint" />,
useData() {
const [endpoints] = Endpoints.useList();
const [services] = Service.useList();
const [endpoints] = Endpoints.useList({ namespace: useNamespaces() });
const [services] = Service.useList({ namespace: useNamespaces() });

return useMemo(() => {
const nodes = endpoints?.map(makeKubeObjectNode) ?? [];
Expand All @@ -71,9 +72,9 @@ const ingressListSource: GraphSource = {
label: 'Ingress',
icon: <KubeIcon kind={'Ingress'} />,
useData() {
const [ingresses] = Ingress.useList();
const [services] = Service.useList();
const [secrets] = Secret.useList();
const [ingresses] = Ingress.useList({ namespace: useNamespaces() });
const [services] = Service.useList({ namespace: useNamespaces() });
const [secrets] = Secret.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!ingresses || !services || !secrets) return null;
Expand Down Expand Up @@ -115,8 +116,8 @@ const networkPoliciesSource: GraphSource = {
label: 'Network Policies',
icon: <KubeIcon kind="NetworkPolicy" />,
useData() {
const [networkPolicies] = NetworkPolicy.useList();
const [pods] = Pod.useList();
const [networkPolicies] = NetworkPolicy.useList({ namespace: useNamespaces() });
const [pods] = Pod.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!networkPolicies || !pods) return null;
Expand Down Expand Up @@ -144,7 +145,7 @@ const ingressClassesSource: GraphSource = {
label: 'Ingress Classes',
icon: <KubeIcon kind="Ingress" />,
useData() {
const [ingressClasses] = IngressClass.useList();
const [ingressClasses] = IngressClass.useList({ namespace: useNamespaces() });

return useMemo(() => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import ServiceAccount from '../../../../lib/k8s/serviceAccount';
import { GraphEdge, GraphSource } from '../../graph/graphModel';
import { getKindGroupColor, KubeIcon } from '../../kubeIcon/KubeIcon';
import { makeKubeObjectNode, makeKubeToKubeEdge } from '../GraphSources';
import { useNamespaces } from '../../../../redux/filterSlice';

const rolesSource: GraphSource = {
id: 'roles',
label: 'Roles',
icon: <KubeIcon kind="Role" />,
useData() {
const [roles] = Role.useList();
const [roles] = Role.useList({ namespace: useNamespaces() });

return useMemo(
() =>
Expand All @@ -33,9 +34,9 @@ const roleBindingsSource: GraphSource = {
label: 'Role Bindings',
icon: <KubeIcon kind="RoleBinding" />,
useData() {
const [roleBindings] = RoleBinding.useList();
const [roles] = Role.useList();
const [serviceAccounts] = ServiceAccount.useList();
const [roleBindings] = RoleBinding.useList({ namespace: useNamespaces() });
const [roles] = Role.useList({ namespace: useNamespaces() });
const [serviceAccounts] = ServiceAccount.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!roleBindings || !roles || !serviceAccounts) return null;
Expand Down Expand Up @@ -72,9 +73,9 @@ const serviceAccountsSource: GraphSource = {
label: 'Service Accounts',
icon: <KubeIcon kind="ServiceAccount" />,
useData() {
const [serviceAccounts] = ServiceAccount.useList();
const [deployments] = Deployment.useList();
const [daemonSets] = DaemonSet.useList();
const [serviceAccounts] = ServiceAccount.useList({ namespace: useNamespaces() });
const [deployments] = Deployment.useList({ namespace: useNamespaces() });
const [daemonSets] = DaemonSet.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!serviceAccounts || !deployments || !daemonSets) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import Pod from '../../../../lib/k8s/pod';
import { GraphEdge, GraphSource } from '../../graph/graphModel';
import { getKindGroupColor, KubeIcon } from '../../kubeIcon/KubeIcon';
import { makeKubeObjectNode, makeKubeToKubeEdge } from '../GraphSources';
import { useNamespaces } from '../../../../redux/filterSlice';

const pvcSource: GraphSource = {
id: 'pvcs',
label: 'PVCs',
icon: <KubeIcon kind="PersistentVolumeClaim" />,
useData() {
const [pvcs] = PersistentVolumeClaim.useList();
const [pods] = Pod.useList();
const [pvcs] = PersistentVolumeClaim.useList({ namespace: useNamespaces() });
const [pods] = Pod.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!pvcs || !pods) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import StatefulSet from '../../../../lib/k8s/statefulSet';
import { GraphEdge, GraphSource } from '../../graph/graphModel';
import { getKindGroupColor, KubeIcon } from '../../kubeIcon/KubeIcon';
import { kubeOwnersEdges, makeKubeObjectNode, makeKubeToKubeEdge } from '../GraphSources';
import { useNamespaces } from '../../../../redux/filterSlice';

export const matchesSelector = (matchLabels: Record<string, string>) => (item: KubeObject) => {
return (
Expand All @@ -27,8 +28,8 @@ const podsSource: GraphSource = {
label: 'Pods',
icon: <KubeIcon kind="Pod" />,
useData: () => {
const [pods] = Pod.useList();
const [nodes] = Node.useList();
const [pods] = Pod.useList({ namespace: useNamespaces() });
const [nodes] = Node.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!pods || !nodes) return null;
Expand Down Expand Up @@ -77,7 +78,7 @@ const deploymentsSource: GraphSource = {
label: 'Deployments',
icon: <KubeIcon kind="Deployment" />,
useData() {
const [deployments] = Deployment.useList();
const [deployments] = Deployment.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!deployments) return null;
Expand All @@ -93,7 +94,7 @@ const cronJobSource: GraphSource = {
label: 'CronJobs',
icon: <KubeIcon kind="CronJob" />,
useData() {
const [cronJobs] = CronJob.useList();
const [cronJobs] = CronJob.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!cronJobs) return null;
Expand All @@ -110,8 +111,8 @@ const jobsSource: GraphSource = {
label: 'Jobs',
icon: <KubeIcon kind="Job" />,
useData() {
const [jobs] = Job.useList();
const [secrets] = Secret.useList();
const [jobs] = Job.useList({ namespace: useNamespaces() });
const [secrets] = Secret.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!jobs || !secrets) return null;
Expand Down Expand Up @@ -159,7 +160,7 @@ const replicaSetsSource: GraphSource = {
label: 'Replica Sets',
icon: <KubeIcon kind="ReplicaSet" />,
useData() {
const [replicaSets] = ReplicaSet.useList();
const [replicaSets] = ReplicaSet.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!replicaSets) return null;
Expand All @@ -183,7 +184,7 @@ const statefulSetSource: GraphSource = {
label: 'Stateful Sets',
icon: <KubeIcon kind="StatefulSet" />,
useData() {
const [statefulSets] = StatefulSet.useList();
const [statefulSets] = StatefulSet.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!statefulSets) return null;
Expand All @@ -199,7 +200,7 @@ const daemonSetSource: GraphSource = {
label: 'Daemon Sets',
icon: <KubeIcon kind="DaemonSet" />,
useData() {
const [daemonSets] = DaemonSet.useList();
const [daemonSets] = DaemonSet.useList({ namespace: useNamespaces() });

return useMemo(() => {
if (!daemonSets) return null;
Expand Down

0 comments on commit 66d0146

Please sign in to comment.