-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cluster role resource * Fix. Rule values might be undefined * Add optional "non resource url" column * remove streaming check --------- Co-authored-by: petar-cvit <[email protected]>
- Loading branch information
1 parent
c022f84
commit b360efa
Showing
2 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
156 changes: 156 additions & 0 deletions
156
cyclops-ui/src/components/k8s-resources/ClusterRole.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import React, { useCallback, useEffect, useState } from "react"; | ||
import { Col, Divider, Row, Alert, Table, Tag } from "antd"; | ||
import axios from "axios"; | ||
import { mapResponseError } from "../../utils/api/errors"; | ||
import { isStreamingEnabled } from "../../utils/api/common"; | ||
|
||
interface Props { | ||
name: string; | ||
} | ||
|
||
interface Rule { | ||
verbs?: string[]; | ||
apiGroups?: string[]; | ||
resources?: string[]; | ||
nonResourceURLs?: string[]; | ||
} | ||
|
||
interface ClusterRoleData { | ||
rules: Rule[]; | ||
} | ||
|
||
const ClusterRole = ({ name }: Props) => { | ||
const [clusterRole, setClusterRole] = useState<ClusterRoleData>({ | ||
rules: [], | ||
}); | ||
|
||
const [error, setError] = useState({ | ||
message: "", | ||
description: "", | ||
}); | ||
|
||
const fetchClusterRole = useCallback(() => { | ||
axios | ||
.get(`/api/resources`, { | ||
params: { | ||
group: `rbac.authorization.k8s.io`, | ||
version: `v1`, | ||
kind: `ClusterRole`, | ||
name: name, | ||
}, | ||
}) | ||
.then((res) => { | ||
setClusterRole({ | ||
rules: res.data.rules || [], | ||
}); | ||
}) | ||
.catch((error) => { | ||
setError(mapResponseError(error)); | ||
}); | ||
}, [name]); | ||
|
||
useEffect(() => { | ||
fetchClusterRole(); | ||
|
||
const interval = setInterval(() => fetchClusterRole(), 15000); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, [fetchClusterRole]); | ||
|
||
const columns = [ | ||
{ | ||
title: "Verbs", | ||
dataIndex: "verbs", | ||
key: "verbs", | ||
render: (verbs?: string[]) => ( | ||
<> | ||
{verbs?.map((verb) => ( | ||
<Tag key={verb} color="orange"> | ||
{verb} | ||
</Tag> | ||
))} | ||
</> | ||
), | ||
}, | ||
{ | ||
title: "API Groups", | ||
dataIndex: "apiGroups", | ||
key: "apiGroups", | ||
render: (apiGroups?: string[]) => ( | ||
<> | ||
{apiGroups?.map((group) => ( | ||
<Tag key={group} color="blue"> | ||
{group || "*"} | ||
</Tag> | ||
))} | ||
</> | ||
), | ||
}, | ||
{ | ||
title: "Resources", | ||
dataIndex: "resources", | ||
key: "resources", | ||
render: (resources?: string[]) => ( | ||
<> | ||
{resources?.map((resource) => ( | ||
<Tag key={resource} color="green"> | ||
{resource} | ||
</Tag> | ||
))} | ||
</> | ||
), | ||
}, | ||
]; | ||
|
||
if (clusterRole.rules.some((rule) => rule.nonResourceURLs)) { | ||
columns.push({ | ||
title: "Non resource URLs", | ||
dataIndex: "nonResourceURLs", | ||
key: "nonResourceURLs", | ||
render: (nonResourceURLs?: string[]) => ( | ||
<> | ||
{nonResourceURLs?.map((url) => ( | ||
<Tag key={url} color="purple"> | ||
{url} | ||
</Tag> | ||
))} | ||
</> | ||
), | ||
}); | ||
} | ||
|
||
return ( | ||
<div> | ||
{error.message.length !== 0 && ( | ||
<Alert | ||
message={error.message} | ||
description={error.description} | ||
type="error" | ||
closable | ||
afterClose={() => { | ||
setError({ | ||
message: "", | ||
description: "", | ||
}); | ||
}} | ||
style={{ marginBottom: "20px" }} | ||
/> | ||
)} | ||
<Divider | ||
style={{ fontSize: "120%" }} | ||
orientationMargin="0" | ||
orientation={"left"} | ||
> | ||
Rules | ||
</Divider> | ||
<Row> | ||
<Col span={24} style={{ overflowX: "auto" }}> | ||
<Table dataSource={clusterRole.rules} columns={columns} /> | ||
</Col> | ||
</Row> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClusterRole; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters