@backstage/plugin-kubernetes 0.9.0 → 0.9.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @backstage/plugin-kubernetes
2
2
 
3
+ ## 0.9.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - dc3cddf51ab5: Fix cyclical dependency in built output
8
+ - 4b230b97660d: Add errors to PodDrawer
9
+ - Updated dependencies
10
+ - @backstage/plugin-catalog-react@1.7.0-next.0
11
+ - @backstage/theme@0.4.0-next.0
12
+ - @backstage/config@1.0.7
13
+ - @backstage/core-components@0.13.2-next.0
14
+ - @backstage/core-plugin-api@1.5.1
15
+ - @backstage/catalog-model@1.3.0
16
+ - @backstage/errors@1.1.5
17
+ - @backstage/plugin-kubernetes-common@0.6.3
18
+
3
19
  ## 0.9.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import { V1Pod, V1ReplicaSet, V1Deployment, V1HorizontalPodAutoscaler, V1Service
8
8
  import React from 'react';
9
9
  import { IObjectMeta } from '@kubernetes-models/apimachinery/apis/meta/v1/ObjectMeta';
10
10
  import { Pod } from 'kubernetes-models/v1';
11
+ import { Pod as Pod$1 } from 'kubernetes-models/v1/Pod';
11
12
 
12
13
  declare const kubernetesPlugin: _backstage_core_plugin_api.BackstagePlugin<{
13
14
  entityContent: _backstage_core_plugin_api.RouteRef<undefined>;
@@ -335,7 +336,7 @@ declare const KubernetesDrawer: ({ open, label, drawerContentsHeader, kubernetes
335
336
  interface PodAndErrors {
336
337
  clusterName: string;
337
338
  pod: Pod;
338
- errors: any[];
339
+ errors: DetectedError[];
339
340
  }
340
341
 
341
342
  interface PodDrawerProps {
@@ -346,7 +347,7 @@ declare const PodDrawer: ({ podAndErrors, open }: PodDrawerProps) => JSX.Element
346
347
 
347
348
  type PodColumns = 'READY' | 'RESOURCE';
348
349
  type PodsTablesProps = {
349
- pods: V1Pod[];
350
+ pods: Pod$1 | V1Pod[];
350
351
  extraColumns?: PodColumns[];
351
352
  children?: React.ReactNode;
352
353
  };
package/dist/index.esm.js CHANGED
@@ -5,13 +5,12 @@ import * as React from 'react';
5
5
  import React__default, { useState, useCallback, useContext, Fragment } from 'react';
6
6
  import { useEntity } from '@backstage/plugin-catalog-react';
7
7
  import { Routes, Route } from 'react-router-dom';
8
- import { Typography, Paper, makeStyles, createStyles, Dialog, DialogTitle, IconButton, DialogContent, Button, Card, CardHeader, CardContent, Grid, CardActions, FormControlLabel, Switch, Drawer, withStyles as withStyles$1, List, ListItem, Chip, Accordion, AccordionSummary, AccordionDetails, Stepper, Step, StepLabel } from '@material-ui/core';
8
+ import { Typography, Paper, makeStyles, createStyles, Dialog, DialogTitle, IconButton, DialogContent, Button, Card, CardHeader, CardContent, Grid, CardActions, FormControlLabel, Switch, Drawer, withStyles as withStyles$1, List, ListItem, Divider, ListItemText, Chip, Accordion, AccordionSummary, AccordionDetails, Stepper, Step, StepLabel } from '@material-ui/core';
9
9
  import { WarningPanel, Table, DismissableBanner, LogViewer, StructuredMetadataTable, CodeSnippet, LinkButton, StatusError, StatusOK, StatusWarning, ItemCardGrid, SubvalueCell, StatusAborted, StatusPending, Page, Content, Progress, MissingAnnotationEmptyState } from '@backstage/core-components';
10
10
  import lodash from 'lodash';
11
11
  import { DateTime } from 'luxon';
12
12
  import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
13
13
  import { Skeleton } from '@material-ui/lab';
14
- import { kubernetesProxyApiRef as kubernetesProxyApiRef$1 } from '@backstage/plugin-kubernetes';
15
14
  import useAsync from 'react-use/lib/useAsync';
16
15
  import SubjectIcon from '@material-ui/icons/Subject';
17
16
  import CloseIcon from '@material-ui/icons/Close';
@@ -705,7 +704,7 @@ const detectErrors = (objects) => {
705
704
  };
706
705
 
707
706
  const usePodLogs = ({ podScope }) => {
708
- const kubernetesProxyApi = useApi(kubernetesProxyApiRef$1);
707
+ const kubernetesProxyApi = useApi(kubernetesProxyApiRef);
709
708
  return useAsync(async () => {
710
709
  return await kubernetesProxyApi.getPodLogs({
711
710
  podName: podScope.podName,
@@ -741,7 +740,7 @@ const PodLogs = ({ podScope }) => {
741
740
  ));
742
741
  };
743
742
 
744
- const useStyles = makeStyles(
743
+ const useStyles$1 = makeStyles(
745
744
  (theme) => createStyles({
746
745
  closeButton: {
747
746
  position: "absolute",
@@ -752,7 +751,7 @@ const useStyles = makeStyles(
752
751
  })
753
752
  );
754
753
  const PodLogsDialog = ({ podScope }) => {
755
- const classes = useStyles();
754
+ const classes = useStyles$1();
756
755
  const [open, setOpen] = useState(false);
757
756
  const openDialog = () => {
758
757
  setOpen(true);
@@ -1508,6 +1507,39 @@ const PendingPodContent = ({ pod }) => {
1508
1507
  return /* @__PURE__ */ React__default.createElement(Grid, { container: true, spacing: 2 }, /* @__PURE__ */ React__default.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React__default.createElement(Typography, { variant: "h5" }, "Pod is Pending. Conditions:"), /* @__PURE__ */ React__default.createElement(List, null, startupConditions.map((c) => /* @__PURE__ */ React__default.createElement(ListItem, { key: c.type }, /* @__PURE__ */ React__default.createElement(PodCondition, { condition: c }))))));
1509
1508
  };
1510
1509
 
1510
+ const useStyles = makeStyles(
1511
+ (_theme) => createStyles({
1512
+ root: {
1513
+ overflow: "auto"
1514
+ },
1515
+ list: {
1516
+ width: "100%"
1517
+ }
1518
+ })
1519
+ );
1520
+ const ErrorList = ({ podAndErrors }) => {
1521
+ const classes = useStyles();
1522
+ return /* @__PURE__ */ React__default.createElement(Paper, { className: classes.root }, /* @__PURE__ */ React__default.createElement(List, { className: classes.list }, podAndErrors.filter((pae) => pae.errors.length > 0).flatMap((onlyPodWithErrors) => {
1523
+ return onlyPodWithErrors.errors.map((error, i) => {
1524
+ var _a, _b, _c;
1525
+ return /* @__PURE__ */ React__default.createElement(
1526
+ React__default.Fragment,
1527
+ {
1528
+ key: `${(_b = (_a = onlyPodWithErrors.pod.metadata) == null ? void 0 : _a.name) != null ? _b : "unknown"}-eli-${i}`
1529
+ },
1530
+ i > 0 && /* @__PURE__ */ React__default.createElement(Divider, { key: `error-divider${i}` }),
1531
+ /* @__PURE__ */ React__default.createElement(ListItem, null, /* @__PURE__ */ React__default.createElement(
1532
+ ListItemText,
1533
+ {
1534
+ primary: error.message,
1535
+ secondary: (_c = onlyPodWithErrors.pod.metadata) == null ? void 0 : _c.name
1536
+ }
1537
+ ))
1538
+ );
1539
+ });
1540
+ })));
1541
+ };
1542
+
1511
1543
  const useDrawerContentStyles = makeStyles(
1512
1544
  (_theme) => createStyles({
1513
1545
  header: {
@@ -1564,7 +1596,7 @@ const PodDrawer = ({ podAndErrors, open }) => {
1564
1596
  }
1565
1597
  );
1566
1598
  }
1567
- )))))
1599
+ ))), podAndErrors.errors.length > 0 && /* @__PURE__ */ React__default.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React__default.createElement(Typography, { variant: "h5" }, "Errors:")), podAndErrors.errors.length > 0 && /* @__PURE__ */ React__default.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React__default.createElement(ErrorList, { podAndErrors: [podAndErrors] }))))
1568
1600
  );
1569
1601
  };
1570
1602
 
@@ -1683,6 +1715,22 @@ const podStatusToMemoryUtil = (podStatus) => {
1683
1715
  );
1684
1716
  };
1685
1717
 
1718
+ const DetectedErrorsContext = React__default.createContext([]);
1719
+ const useMatchingErrors = (matcher) => {
1720
+ var _a, _b, _c, _d;
1721
+ const targetRef = {
1722
+ name: (_b = (_a = matcher.metadata) == null ? void 0 : _a.name) != null ? _b : "",
1723
+ namespace: (_d = (_c = matcher.metadata) == null ? void 0 : _c.namespace) != null ? _d : "",
1724
+ kind: matcher.kind,
1725
+ apiGroup: matcher.apiVersion
1726
+ };
1727
+ const errors = useContext(DetectedErrorsContext);
1728
+ return errors.filter((e) => {
1729
+ const r = e.sourceRef;
1730
+ return targetRef.apiGroup === r.apiGroup && targetRef.kind === r.kind && targetRef.name === r.name && targetRef.namespace === r.namespace;
1731
+ });
1732
+ };
1733
+
1686
1734
  const READY_COLUMNS = "READY";
1687
1735
  const RESOURCE_COLUMNS = "RESOURCE";
1688
1736
  const READY = [
@@ -1700,23 +1748,33 @@ const READY = [
1700
1748
  width: "auto"
1701
1749
  }
1702
1750
  ];
1751
+ const PodDrawerTrigger = ({ pod }) => {
1752
+ const cluster = useContext(ClusterContext);
1753
+ const errors = useMatchingErrors({
1754
+ kind: "Pod",
1755
+ apiVersion: "v1",
1756
+ metadata: pod.metadata
1757
+ });
1758
+ return /* @__PURE__ */ React__default.createElement(
1759
+ PodDrawer,
1760
+ {
1761
+ podAndErrors: {
1762
+ pod,
1763
+ clusterName: cluster.name,
1764
+ errors
1765
+ }
1766
+ }
1767
+ );
1768
+ };
1703
1769
  const PodsTable = ({ pods, extraColumns = [] }) => {
1704
1770
  const podNamesWithMetrics = useContext(PodNamesWithMetricsContext);
1705
- const cluster = useContext(ClusterContext);
1706
1771
  const defaultColumns = [
1707
1772
  {
1708
1773
  title: "name",
1709
1774
  highlight: true,
1710
- render: (pod) => /* @__PURE__ */ React__default.createElement(
1711
- PodDrawer,
1712
- {
1713
- podAndErrors: {
1714
- pod,
1715
- clusterName: cluster.name,
1716
- errors: []
1717
- }
1718
- }
1719
- )
1775
+ render: (pod) => {
1776
+ return /* @__PURE__ */ React__default.createElement(PodDrawerTrigger, { pod });
1777
+ }
1720
1778
  },
1721
1779
  {
1722
1780
  title: "phase",
@@ -1768,15 +1826,11 @@ const PodsTable = ({ pods, extraColumns = [] }) => {
1768
1826
  minWidth: "0",
1769
1827
  width: "100%"
1770
1828
  };
1771
- const usePods = pods.map((p) => {
1772
- var _a;
1773
- return { ...p, id: (_a = p.metadata) == null ? void 0 : _a.uid };
1774
- });
1775
1829
  return /* @__PURE__ */ React__default.createElement("div", { style: tableStyle }, /* @__PURE__ */ React__default.createElement(
1776
1830
  Table,
1777
1831
  {
1778
1832
  options: { paging: true, search: false, emptyRowsWhenPaging: false },
1779
- data: usePods,
1833
+ data: pods,
1780
1834
  columns
1781
1835
  }
1782
1836
  ));
@@ -2906,7 +2960,7 @@ const KubernetesContent = ({
2906
2960
  );
2907
2961
  const clustersWithErrors = (_a = kubernetesObjects == null ? void 0 : kubernetesObjects.items.filter((r) => r.errors.length > 0)) != null ? _a : [];
2908
2962
  const detectedErrors = kubernetesObjects !== void 0 ? detectErrors(kubernetesObjects) : /* @__PURE__ */ new Map();
2909
- return /* @__PURE__ */ React__default.createElement(Page, { themeId: "tool" }, /* @__PURE__ */ React__default.createElement(Content, null, kubernetesObjects === void 0 && error === void 0 && /* @__PURE__ */ React__default.createElement(Progress, null), clustersWithErrors.length > 0 && /* @__PURE__ */ React__default.createElement(Grid, { container: true, spacing: 3, direction: "column" }, /* @__PURE__ */ React__default.createElement(Grid, { item: true }, /* @__PURE__ */ React__default.createElement(
2963
+ return /* @__PURE__ */ React__default.createElement(DetectedErrorsContext.Provider, { value: [...detectedErrors.values()].flat() }, /* @__PURE__ */ React__default.createElement(Page, { themeId: "tool" }, /* @__PURE__ */ React__default.createElement(Content, null, kubernetesObjects === void 0 && error === void 0 && /* @__PURE__ */ React__default.createElement(Progress, null), clustersWithErrors.length > 0 && /* @__PURE__ */ React__default.createElement(Grid, { container: true, spacing: 3, direction: "column" }, /* @__PURE__ */ React__default.createElement(Grid, { item: true }, /* @__PURE__ */ React__default.createElement(
2910
2964
  ErrorPanel,
2911
2965
  {
2912
2966
  entityName: entity.metadata.name,
@@ -2948,7 +3002,7 @@ const KubernetesContent = ({
2948
3002
  podsWithErrors
2949
3003
  }
2950
3004
  ));
2951
- }))))));
3005
+ })))))));
2952
3006
  };
2953
3007
 
2954
3008
  const KUBERNETES_ANNOTATION = "backstage.io/kubernetes-id";