Skip to content

Commit

Permalink
Added filter function of k8s page
Browse files Browse the repository at this point in the history
  • Loading branch information
yongsikgi committed Dec 1, 2021
1 parent c1a45d9 commit 81ecb40
Show file tree
Hide file tree
Showing 8 changed files with 737 additions and 188 deletions.
28 changes: 28 additions & 0 deletions frontend/src/hosts/actions/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getLocalK8sRoleBindings,
getLocalK8sPersistentVolumes,
getLocalK8sPersistentVolumeClaims,
getLocalK8sDetail,
} from 'src/shared/apis/saltStack'

// Types
Expand Down Expand Up @@ -52,6 +53,7 @@ export enum ActionTypes {
RoleBindings = 'GET_ROLEBINDINGS',
PersistentVolumes = 'GET_PERSISTENTVOLUMES',
PersistentVolumeClaims = 'GET_PERSISTENTVOLUMECLAIMS',
K8sDetail = 'GET_K8S_DETAIL',
}

interface NamespacesAction {
Expand Down Expand Up @@ -138,6 +140,10 @@ interface PersistentVolumeClaimsAction {
type: ActionTypes.PersistentVolumeClaims
}

interface K8sDetailAction {
type: ActionTypes.K8sDetail
}

export type Action =
| NamespacesAction
| NodesAction
Expand All @@ -160,6 +166,7 @@ export type Action =
| RoleBindingsAction
| PersistentVolumesAction
| PersistentVolumeClaimsAction
| K8sDetailAction

export const loadNamespaces = (): NamespacesAction => ({
type: ActionTypes.Namespaces,
Expand Down Expand Up @@ -245,6 +252,10 @@ export const loadPersistentVolumeClaims = (): PersistentVolumeClaimsAction => ({
type: ActionTypes.PersistentVolumeClaims,
})

export const loadK8sDetail = (): K8sDetailAction => ({
type: ActionTypes.K8sDetail,
})

export const getLocalK8sNamespacesAsync = (
pUrl: string,
pToken: string,
Expand Down Expand Up @@ -671,3 +682,20 @@ export const getLocalK8sPersistentVolumeClaimsAsync = (
dispatch(errorThrown(error))
}
}

export const getLocalK8sDetailAsync = (
pUrl: string,
pToken: string,
pMinionId: string,
pParam?: SaltStack
) => async (dispatch: Dispatch<Action>) => {
try {
const k8sDetail = await getLocalK8sDetail(pUrl, pToken, pMinionId, pParam)

dispatch(loadK8sDetail())
return k8sDetail
} catch (error) {
console.error(error)
dispatch(errorThrown(error))
}
}
25 changes: 2 additions & 23 deletions frontend/src/hosts/components/KubernetesContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {Source, TimeRange, Cell, Template, RemoteDataState} from 'src/types'
interface Props {
handleOnSetActiveEditorTab: (tab: string) => void
handleOnClickPodName: () => void
handleOnClickVisualizePod: (target: SVGSVGElement) => void
handleOnClickVisualizePod: (data: any) => void
handleDBClick: (data: any) => void
handleResize: (proportions: number[]) => void
handleOpenTooltip: (target: any) => void
Expand Down Expand Up @@ -231,28 +231,7 @@ class KubernetesContents extends PureComponent<Props, State> {
</div>
</>
</TableBody>
<div className={'kubernetes-radio-btn--container'}>
<Radio shape={ButtonShape.StretchToFit}>
<Radio.Button
id="hostspage-tab-Basic"
titleText="Basic"
value="Basic"
active={activeTab === 'Basic'}
onClick={handleOnSetActiveEditorTab}
>
Basic
</Radio.Button>
<Radio.Button
id="hostspage-tab-Detail"
titleText="Detail"
value="Detail"
active={activeTab === 'Detail'}
onClick={handleOnSetActiveEditorTab}
>
Raw Data
</Radio.Button>
</Radio>
</div>
<div className={'kubernetes-detail-title'}>Raw Data</div>
{activeTab === 'Basic' ? (
<KubernetesBasicsTable />
) : (
Expand Down
126 changes: 70 additions & 56 deletions frontend/src/hosts/components/KubernetesHexagon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {RemoteDataState} from 'src/types'

interface Props {
handleOnClickPodName: () => void
handleOnClickVisualizePod: (target: SVGSVGElement) => void
handleOnClickVisualizePod: (data: any) => void
handleDBClick: (data: any) => void
handleResize: (proportions: number[]) => void
handleOpenTooltip: (target: any) => void
Expand Down Expand Up @@ -209,7 +209,7 @@ class KubernetesHexagon extends PureComponent<Props, State> {
.on('mouseleave', function () {
onMouseLeave(this)
})
.on('click', function () {
.on('click', function (data) {
onMouseClick(this, data)
})
.on('mousedown', function () {
Expand Down Expand Up @@ -347,56 +347,70 @@ class KubernetesHexagon extends PureComponent<Props, State> {

_.forEach(kubernetesObject, m => {
if (m['type'] === 'Node') {
const cpuUsage =
(parseFloat(m['cpu']) /
parseFloat(
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-limit-cpu')
)) *
100
const memoryUsage =
(parseFloat(m['memory']) /
parseFloat(
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-limit-memory')
)) *
100
const pick = cpuUsage > memoryUsage ? cpuUsage : memoryUsage
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-cpu', `${cpuUsage}`)
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-memory', `${memoryUsage}`)
.attr('fill', kubernetesStatusColor(pick / 100))
if (
_.find(
node.select(`circle[data-type=${'Node'}]`).data(),
nodeData => nodeData.data.label === m['name']
)
) {
const cpuUsage =
(parseFloat(m['cpu']) /
parseFloat(
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-limit-cpu')
)) *
100
const memoryUsage =
(parseFloat(m['memory']) /
parseFloat(
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-limit-memory')
)) *
100
const pick = cpuUsage > memoryUsage ? cpuUsage : memoryUsage
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-cpu', `${cpuUsage}`)
node
.select(`circle[data-label=${m['name']}]`)
.attr('data-memory', `${memoryUsage}`)
.attr('fill', kubernetesStatusColor(pick / 100))
}
} else {
const cpuUsage =
(parseFloat(m['cpu']) /
parseFloat(
node
.select(`path[data-label=${m['name']}]`)
.attr('data-limit-cpu')
)) *
100
const memoryUsage =
(parseFloat(m['memory']) /
parseFloat(
node
.select(`path[data-label=${m['name']}]`)
.attr('data-limit-memory')
)) *
100

const pick = cpuUsage > memoryUsage ? cpuUsage : memoryUsage
node
.select(`path[data-label=${m['name']}]`)
.attr('data-cpu', `${cpuUsage}`)
node
.select(`path[data-label=${m['name']}]`)
.attr('data-memory', `${memoryUsage}`)
.attr('fill', kubernetesStatusColor(pick / 100))
if (
_.find(
node.select(`path[data-type=${'Pod'}]`).data(),
podData => podData.data.label === m['name']
)
) {
const cpuUsage =
(parseFloat(m['cpu']) /
parseFloat(
node
.select(`path[data-label=${m['name']}]`)
.attr('data-limit-cpu')
)) *
100
const memoryUsage =
(parseFloat(m['memory']) /
parseFloat(
node
.select(`path[data-label=${m['name']}]`)
.attr('data-limit-memory')
)) *
100

const pick = cpuUsage > memoryUsage ? cpuUsage : memoryUsage
node
.select(`path[data-label=${m['name']}]`)
.attr('data-cpu', `${cpuUsage}`)
node
.select(`path[data-label=${m['name']}]`)
.attr('data-memory', `${memoryUsage}`)
.attr('fill', kubernetesStatusColor(pick / 100))
}
}
})

Expand All @@ -410,13 +424,13 @@ class KubernetesHexagon extends PureComponent<Props, State> {
return this.ref.current.append(svg.attr('viewBox', `${autoBox()}`).node())
}

private runOnSingleClick = (target: SVGSVGElement) => {
this.props.handleOnClickVisualizePod(target)
private runOnSingleClick = (data: any) => {
this.props.handleOnClickVisualizePod(data)
this.clickedOnce = false
this.clickedTarget = null
}

private runOnDBClick = (target: SVGSVGElement, data) => {
private runOnDBClick = (target: SVGSVGElement, data: any) => {
this.clickedOnce = false
this.clickedTarget = null
clearTimeout(this.timeout)
Expand All @@ -431,7 +445,7 @@ class KubernetesHexagon extends PureComponent<Props, State> {
(this.clickedTarget !== target && this.clickedOnce)
) {
this.timeout = setTimeout(() => {
this.runOnSingleClick(target)
this.runOnSingleClick(data)
}, this.dbClickJudgementTimer)

this.clickedTarget = target
Expand All @@ -441,7 +455,7 @@ class KubernetesHexagon extends PureComponent<Props, State> {

private onMouseDBClick = (target: SVGSVGElement, data: any) => {
this.props.handleDBClick(data)
this.props.handleOnClickVisualizePod(target)
this.props.handleOnClickVisualizePod(data)
}

private onMouseOver = (target: SVGSVGElement) => {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/hosts/components/host.scss
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@
}
}

.kubernetes-detail-title {
height: 40px;
font-size: 15px;
font-weight: 600;
color: #bec2cc;
padding: 10px 5px 0 5px;
}

.devider--bar {
background-color: $g2-kevlar;
color: white;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hosts/containers/Infrastructure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Infrastructure extends PureComponent<Props, State> {
const isUsingKubernetes = !_.isEmpty(
_.find(addons, addon => {
const {name, url} = addon
return name === 'kubernetes' && url === 'on'
return name === 'k8s' && url === 'on'
})
)

Expand Down
Loading

0 comments on commit 81ecb40

Please sign in to comment.