From 604d898b5a0fc31deac3014dbae5ec61e1d1c700 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste WATENBERG Date: Thu, 24 Dec 2020 16:29:01 +0100 Subject: [PATCH] ui: add pods reducer typing Refs: https://github.com/scality/metalk8s/issues/2999 --- ui/src/ducks/app/pods.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/ui/src/ducks/app/pods.js b/ui/src/ducks/app/pods.js index bf67a98f0d..55de6bbd51 100644 --- a/ui/src/ducks/app/pods.js +++ b/ui/src/ducks/app/pods.js @@ -1,3 +1,5 @@ +//@flow +import { V1ContainerStatus, V1Pod, V1PodList } from '@kubernetes/client-node/dist/gen/model/models'; import { call, put, takeLatest } from 'redux-saga/effects'; import * as CoreApi from '../../services/k8s/core'; @@ -10,7 +12,25 @@ const defaultState = { list: [], }; -export default function reducer(state = defaultState, action = {}) { +export type Pod = { + name: string, + namespace: string, + nodeName: string, + status: string, + startTime: string, + restartCount: number, + volumes: { + name: string, + persistentVolumeClaim: string, + }[], + containerStatuses: V1ContainerStatus[], +} + +export type PodsState = { + list: Pod[] +} + +export default function reducer(state: PodsState = defaultState, action: any = {}) { switch (action.type) { case SET_PODS: return { ...state, list: action.payload }; @@ -24,17 +44,17 @@ export const fetchPodsAction = () => { return { type: FETCH_PODS }; }; -export const setPodsAction = (payload) => { +export const setPodsAction = (payload: Pod[]) => { return { type: SET_PODS, payload }; }; // Sagas -export function* fetchPods() { +export function* fetchPods(): Generator { const result = yield call(CoreApi.getPods); if (!result.error) { yield put( setPodsAction( - result.body.items.map((pod) => ({ + result.body.items.map((pod: V1Pod) => ({ name: pod.metadata.name, namespace: pod.metadata.namespace, nodeName: pod.spec.nodeName, @@ -44,7 +64,7 @@ export function* fetchPods() { pod.status.containerStatuses && pod.status.containerStatuses.length ? pod.status.containerStatuses[0].restartCount : 0, - volumes: pod?.spec?.volumes?.map((volume) => ({ + volumes: (pod?.spec?.volumes || []).map((volume) => ({ name: volume.name, persistentVolumeClaim: volume?.persistentVolumeClaim?.claimName, })), @@ -55,6 +75,6 @@ export function* fetchPods() { } } -export function* podsSaga() { +export function* podsSaga(): Generator { yield takeLatest(FETCH_PODS, fetchPods); }