Skip to content

Commit

Permalink
Delete pod in CD (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Dec 29, 2023
1 parent caa985b commit 655195b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
66 changes: 47 additions & 19 deletions assets/src/components/cluster/pods/PodsList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { A, Div, Flex, Span } from 'honorable'
import { Link, useNavigate } from 'react-router-dom'
import { Row, createColumnHelper } from '@tanstack/react-table'
import { ComponentProps, memo, useMemo, useState } from 'react'
import {
ComponentProps,
createContext,
memo,
useContext,
useMemo,
useState,
} from 'react'
import { filesize } from 'filesize'

import type { Application, Maybe, Pod } from 'generated/graphql'
Expand Down Expand Up @@ -34,11 +41,21 @@ import { ContainerStatuses } from '../ContainerStatuses'

import { getPodResources } from './getPodResources'

function DeletePod({ name, namespace, refetch }) {
function DeletePod({
name,
namespace,
refetch,
serviceId,
}: {
name: string
namespace: string
refetch: any
serviceId?: string | null
}) {
const [confirm, setConfirm] = useState(false)

const [mutation, { loading }] = useMutation(DELETE_POD, {
variables: { name, namespace },
variables: { name, namespace, serviceId },
onCompleted: () => {
setConfirm(false)
refetch()
Expand Down Expand Up @@ -260,13 +277,18 @@ export const ColActions = (refetch) =>
export const ColDelete = (refetch) =>
columnHelper.accessor((row) => row.name, {
id: 'delete',
cell: ({ row: { original } }) => (
<DeletePod
name={original.name}
namespace={original.namespace}
refetch={refetch}
/>
),
cell: ({ row: { original } }) => {
const ctx = useContext(PodsListContext)

Check failure on line 281 in assets/src/components/cluster/pods/PodsList.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook "useContext" is called in function "cell" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"

return (
<DeletePod
name={original.name || ''}
namespace={original.namespace || ''}
refetch={refetch}
serviceId={ctx?.serviceId}
/>
)
},
header: '',
})

Expand All @@ -278,6 +300,7 @@ type PodListProps = Omit<ComponentProps<typeof Table>, 'data'> & {
applications?: Maybe<Maybe<Application>[]>
columns: any[]
linkBasePath?: string
serviceId?: string | null
}

function getRestarts(status: Pod['status']) {
Expand All @@ -304,11 +327,14 @@ function getPodImages(spec: Pod['spec']) {
]
}

const PodsListContext = createContext<any>({})

export const PodsList = memo(
({
pods,
applications,
columns,
serviceId,
linkBasePath = `/pods`,
...props
}: PodListProps) => {
Expand Down Expand Up @@ -356,15 +382,17 @@ export const PodsList = memo(
}

return (
<Table
data={tableData}
columns={columns}
virtualizeRows
{...props}
onRowClick={(_e, { original }: Row<PodTableRow>) =>
navigate(`${linkBasePath}/${original.namespace}/${original.name}`)
}
/>
<PodsListContext.Provider value={{ serviceId }}>

Check failure on line 385 in assets/src/components/cluster/pods/PodsList.tsx

View workflow job for this annotation

GitHub Actions / Lint

The object passed as the value prop to the Context provider (at line 385) changes every render. To fix this consider wrapping it in a useMemo hook
<Table
data={tableData}
columns={columns}
virtualizeRows
{...props}
onRowClick={(_e, { original }: Row<PodTableRow>) =>
navigate(`${linkBasePath}/${original.namespace}/${original.name}`)
}
/>
</PodsListContext.Provider>
)
}
)
4 changes: 2 additions & 2 deletions assets/src/components/cluster/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from 'components/graphql/kubernetes'

export const DELETE_POD = gql`
mutation DeletePod($name: String!, $namespace: String!) {
deletePod(name: $name, namespace: $namespace) {
mutation DeletePod($name: String!, $namespace: String!, $serviceId: ID) {
deletePod(name: $name, namespace: $namespace, serviceId: $serviceId) {
...PodFragment
}
}
Expand Down
3 changes: 2 additions & 1 deletion assets/src/components/component/info/Pods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { InfoSectionH2 } from './common'

export default function Pods({ pods }) {
const clusterId = useParams()[SERVICE_PARAM_CLUSTER_ID]
const { refetch } = useOutletContext<any>()
const { refetch, ...rest } = useOutletContext<any>()
const theme = useTheme()
const columns = useMemo(
() => [
Expand Down Expand Up @@ -55,6 +55,7 @@ export default function Pods({ pods }) {
<PodsList
pods={pods}
columns={columns}
serviceId={rest?.serviceId}
{...(clusterId
? {
linkBasePath: getPodDetailsPath({ clusterId }),
Expand Down
2 changes: 1 addition & 1 deletion charts/console/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: >-
deploys the plural console and additional dependencies, for use in
bring-your-own-kube setups
appVersion: 0.7.7
version: 0.1.14
version: 0.1.15
dependencies:
- name: kas
version: 0.0.3
Expand Down
3 changes: 2 additions & 1 deletion charts/console/templates/migration.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apiVersion: batch/v1
kind: Job
metadata:
name: console-migration-{{ .Values.image.tag | default .Chart.AppVersion | sha256sum | trunc 8 }}
name: console-migration-v2-{{ .Values.image.tag | default .Chart.AppVersion | sha256sum | trunc 8 }}
labels:
platform.plural.sh/ignore: 'true'
{{ include "console.labels" . | nindent 4 }}
spec:
template:
spec:
serviceAccountName: console
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 6 }}
Expand Down

0 comments on commit 655195b

Please sign in to comment.