diff --git a/.changeset/famous-loops-tickle.md b/.changeset/famous-loops-tickle.md new file mode 100644 index 0000000000..ae8c9d80ee --- /dev/null +++ b/.changeset/famous-loops-tickle.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-kubernetes-react': patch +--- + +The configmaps added to be rendered diff --git a/plugins/kubernetes-react/src/__fixtures__/1-configmaps.json b/plugins/kubernetes-react/src/__fixtures__/1-configmaps.json new file mode 100644 index 0000000000..ab0518e87d --- /dev/null +++ b/plugins/kubernetes-react/src/__fixtures__/1-configmaps.json @@ -0,0 +1,26 @@ +{ + "configMaps": [ + { + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "app-config", + "namespace": "default", + "uid": "1ea073bc-7a4b-4b99-8321-0305bce85568", + "resourceVersion": "1362732552", + "creationTimestamp": "2021-07-16T22:39:58Z", + "labels": { + "backstage.io/kubernetes-id": "dice-roller", + "app": "dice-roller" + }, + "annotations": {} + }, + "data": { + "database.host": "localhost", + "database.port": "5432", + "app.name": "dice-roller", + "app.version": "1.0.0" + } + } + ] +} diff --git a/plugins/kubernetes-react/src/__fixtures__/2-configmaps.json b/plugins/kubernetes-react/src/__fixtures__/2-configmaps.json new file mode 100644 index 0000000000..2c0c7f8121 --- /dev/null +++ b/plugins/kubernetes-react/src/__fixtures__/2-configmaps.json @@ -0,0 +1,47 @@ +{ + "configMaps": [ + { + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "app-config", + "namespace": "default", + "uid": "1ea073bc-7a4b-4b99-8321-0305bce85568", + "resourceVersion": "1362732552", + "creationTimestamp": "2021-07-16T22:39:58Z", + "labels": { + "backstage.io/kubernetes-id": "dice-roller", + "app": "dice-roller" + }, + "annotations": {} + }, + "data": { + "database.host": "localhost", + "database.port": "5432", + "app.name": "dice-roller", + "app.version": "1.0.0" + } + }, + { + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "redis-config", + "namespace": "default", + "uid": "2ea073bc-7a4b-4b99-8321-0305bce85568", + "resourceVersion": "1362732553", + "creationTimestamp": "2021-07-16T22:40:58Z", + "labels": { + "backstage.io/kubernetes-id": "dice-roller", + "app": "redis" + }, + "annotations": {} + }, + "data": { + "redis.conf": "# Redis configuration\nmaxmemory 256mb\nmaxmemory-policy allkeys-lru", + "redis.host": "redis-service", + "redis.port": "6379" + } + } + ] +} diff --git a/plugins/kubernetes-react/src/components/Cluster/Cluster.tsx b/plugins/kubernetes-react/src/components/Cluster/Cluster.tsx index 642ed642a4..4e8c4a1947 100644 --- a/plugins/kubernetes-react/src/components/Cluster/Cluster.tsx +++ b/plugins/kubernetes-react/src/components/Cluster/Cluster.tsx @@ -30,6 +30,7 @@ import { DeploymentsAccordions } from '../DeploymentsAccordions'; import { StatefulSetsAccordions } from '../StatefulSetsAccordions'; import { IngressesAccordions } from '../IngressesAccordions'; import { ServicesAccordions } from '../ServicesAccordions'; +import { ConfigmapsAccordions } from '../ConfigmapsAccordions'; import { CronJobsAccordions } from '../CronJobsAccordions'; import { CustomResources } from '../CustomResources'; import { DaemonSetsAccordions } from '../DaemonSetsAccordions'; @@ -170,6 +171,11 @@ export const Cluster = ({ clusterObjects, podsWithErrors }: ClusterProps) => { ) : undefined} + {groupedResponses.configMaps.length > 0 ? ( + + + + ) : undefined} {groupedResponses.cronJobs.length > 0 ? ( diff --git a/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsAccordions.test.tsx b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsAccordions.test.tsx new file mode 100644 index 0000000000..d819a01cd9 --- /dev/null +++ b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsAccordions.test.tsx @@ -0,0 +1,54 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { screen } from '@testing-library/react'; +import { ConfigmapsAccordions } from './ConfigmapsAccordions'; +import * as oneConfigmapsFixture from '../../__fixtures__/1-configmaps.json'; +import * as twoConfigmapsFixture from '../../__fixtures__/2-configmaps.json'; +import { renderInTestApp } from '@backstage/test-utils'; +import { kubernetesProviders } from '../../hooks/test-utils'; + +describe('ConfigmapsAccordions', () => { + it('should render 1 configmap', async () => { + const wrapper = kubernetesProviders( + oneConfigmapsFixture, + new Set(), + ); + + await renderInTestApp(wrapper()); + + expect(screen.getByText('app-config')).toBeInTheDocument(); + expect(screen.getByText('ConfigMap')).toBeInTheDocument(); + expect(screen.getByText('namespace: default')).toBeInTheDocument(); + expect(screen.getByText('Data Count: 4')).toBeInTheDocument(); + }); + + it('should render 2 configmaps', async () => { + const wrapper = kubernetesProviders( + twoConfigmapsFixture, + new Set(), + ); + + await renderInTestApp(wrapper()); + + expect(screen.getByText('app-config')).toBeInTheDocument(); + expect(screen.getByText('redis-config')).toBeInTheDocument(); + expect(screen.getAllByText('ConfigMap')).toHaveLength(2); + expect(screen.getAllByText('namespace: default')).toHaveLength(2); + expect(screen.getByText('Data Count: 4')).toBeInTheDocument(); + expect(screen.getByText('Data Count: 3')).toBeInTheDocument(); + }); +}); diff --git a/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsAccordions.tsx b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsAccordions.tsx new file mode 100644 index 0000000000..bdb5b10d35 --- /dev/null +++ b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsAccordions.tsx @@ -0,0 +1,108 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { useContext } from 'react'; +import Accordion from '@material-ui/core/Accordion'; +import AccordionDetails from '@material-ui/core/AccordionDetails'; +import AccordionSummary from '@material-ui/core/AccordionSummary'; +import Grid from '@material-ui/core/Grid'; +import Typography from '@material-ui/core/Typography'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import type { V1ConfigMap } from '@kubernetes/client-node'; +import { ConfigmapsDrawer } from './ConfigmapsDrawer.tsx'; +import { GroupedResponsesContext } from '../../hooks'; +import { StructuredMetadataTable } from '@backstage/core-components'; + +type ConfigmapSummaryProps = { + configmap: V1ConfigMap; +}; + +const ConfigmapSummary = ({ configmap }: ConfigmapSummaryProps) => { + return ( + + + + + + + + Data Count: {configmap.data ? Object.keys(configmap.data).length : 0} + + + + ); +}; + +type ConfigmapsCardProps = { + configmap: V1ConfigMap; +}; + +const ConfigmapCard = ({ configmap }: ConfigmapsCardProps) => { + const metadata: any = {}; + + metadata.data = configmap.data; + + return ( + + ); +}; + +export type ConfigmapsAccordionsProps = {}; + +type ConfigmapsAccordionProps = { + configmap: V1ConfigMap; +}; + +const ConfigmapsAccordion = ({ configmap }: ConfigmapsAccordionProps) => { + return ( + + }> + + + + + + + ); +}; + +export const ConfigmapsAccordions = ({}: ConfigmapsAccordionsProps) => { + const groupedResponses = useContext(GroupedResponsesContext); + return ( + + {groupedResponses.configMaps.map((configmap, i) => ( + + + + ))} + + ); +}; diff --git a/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsDrawer.test.tsx b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsDrawer.test.tsx new file mode 100644 index 0000000000..cde7265cab --- /dev/null +++ b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsDrawer.test.tsx @@ -0,0 +1,37 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as oneConfigmapsFixture from '../../__fixtures__/1-configmaps.json'; +import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; +import { ConfigmapsDrawer } from './ConfigmapsDrawer'; +import { kubernetesClusterLinkFormatterApiRef } from '../../api'; + +describe('ConfigmapsDrawer', () => { + it('should render configmap drawer', async () => { + const { getByText, getAllByText } = await renderInTestApp( + + + , + ); + + expect(getAllByText('app-config')).toHaveLength(3); + expect(getAllByText('ConfigMap')).toHaveLength(3); + expect(getByText('YAML')).toBeInTheDocument(); + expect(getByText('namespace: default')).toBeInTheDocument(); + }); +}); diff --git a/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsDrawer.tsx b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsDrawer.tsx new file mode 100644 index 0000000000..97e8aab723 --- /dev/null +++ b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/ConfigmapsDrawer.tsx @@ -0,0 +1,64 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { KubernetesStructuredMetadataTableDrawer } from '../KubernetesDrawer'; +import Typography from '@material-ui/core/Typography'; +import Grid from '@material-ui/core/Grid'; +import Chip from '@material-ui/core/Chip'; +import type { V1ConfigMap } from '@kubernetes/client-node'; + +export const ConfigmapsDrawer = ({ + configmap, + expanded, +}: { + configmap: V1ConfigMap; + expanded?: boolean; +}) => { + const namespace = configmap.metadata?.namespace; + return ( + { + return configmapObject || {}; + }} + > + + + + {configmap.metadata?.name ?? 'unknown object'} + + + + + ConfigMap + + + {namespace && ( + + + + )} + + + ); +}; diff --git a/plugins/kubernetes-react/src/components/ConfigmapsAccordions/index.ts b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/index.ts new file mode 100644 index 0000000000..25a1578a79 --- /dev/null +++ b/plugins/kubernetes-react/src/components/ConfigmapsAccordions/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export * from './ConfigmapsAccordions.tsx';