Skip to content

Commit

Permalink
📝 added checkbox for toggled managedFields (cyclops-ui#395)
Browse files Browse the repository at this point in the history
* added checkbox for toggled managedFields

* update branch

* Update requested changes

Signed-off-by: Wasiim105 <[email protected]>

* update the requested changes

Signed-off-by: Wasiim105 <[email protected]>

---------

Signed-off-by: Wasiim105 <[email protected]>
  • Loading branch information
Wasiim105 authored Jul 11, 2024
1 parent a83c8b2 commit f05c412
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 18 deletions.
6 changes: 5 additions & 1 deletion cyclops-ctrl/internal/cluster/k8sclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (k *KubernetesClient) GetStatefulSetsLogs(namespace, container, name string
return logs, nil
}

func (k *KubernetesClient) GetManifest(group, version, kind, name, namespace string) (string, error) {
func (k *KubernetesClient) GetManifest(group, version, kind, name, namespace string, includeManagedFields bool) (string, error) {
apiResourceName, err := k.GVKtoAPIResourceName(schema.GroupVersion{Group: group, Version: version}, kind)
if err != nil {
return "", err
Expand All @@ -261,6 +261,10 @@ func (k *KubernetesClient) GetManifest(group, version, kind, name, namespace str
return "", err
}

if (!includeManagedFields) {
resource.SetManagedFields(nil)
}

data, err := yaml.Marshal(resource.Object)
if err != nil {
return "", err
Expand Down
3 changes: 2 additions & 1 deletion cyclops-ctrl/internal/controller/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ func (m *Modules) GetManifest(ctx *gin.Context) {
kind := ctx.Query("kind")
name := ctx.Query("name")
namespace := ctx.Query("namespace")
includeManagedFields := ctx.Query("includeManagedFields") == "true"

manifest, err := m.kubernetesClient.GetManifest(group, version, kind, name, namespace)
manifest, err := m.kubernetesClient.GetManifest(group, version, kind, name, namespace,includeManagedFields)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{
"error": "Failed to fetch resource manifest",
Expand Down
74 changes: 58 additions & 16 deletions cyclops-ui/src/components/pages/ModuleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import { gvkString } from "../../utils/k8s/gvk";
import { mapResponseError } from "../../utils/api/errors";
import Secret from "../k8s-resources/Secret";
import { CheckboxChangeEvent } from "antd/es/checkbox";
const languages = [
"javascript",
"java",
Expand Down Expand Up @@ -104,6 +105,13 @@ interface resourceRef {
const ModuleDetails = () => {
const [manifestModal, setManifestModal] = useState({
on: false,
resource: {
group: "",
version: "",
kind: "",
name: "",
namespace: "",
},
manifest: "",
});
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -144,12 +152,49 @@ const ModuleDetails = () => {

let { moduleName } = useParams();

const [showManagedFields, setShowManagedFields] = useState(false);

const handleCheckboxChange = (e: CheckboxChangeEvent) => {
setShowManagedFields(e.target.checked);
fetchManifest(
manifestModal.resource.group,
manifestModal.resource.version,
manifestModal.resource.kind,
manifestModal.resource.namespace,
manifestModal.resource.name,
e.target.checked,
);
};

const handleManifestClick = (resource: any) => {
setManifestModal({
on: true,
resource: {
group: resource.group,
version: resource.version,
kind: resource.kind,
name: resource.name,
namespace: resource.namespace,
},
manifest: "",
});
fetchManifest(
resource.group,
resource.version,
resource.kind,
resource.namespace,
resource.name,
showManagedFields,
);
};

function fetchManifest(
group: string,
version: string,
kind: string,
namespace: string,
name: string,
showManagedFields: boolean,
) {
axios
.get(`/api/manifest`, {
Expand All @@ -159,13 +204,14 @@ const ModuleDetails = () => {
kind: kind,
name: name,
namespace: namespace,
includeManagedFields: showManagedFields,
},
})
.then((res) => {
setManifestModal({
on: true,
setManifestModal((prev) => ({
...prev,
manifest: res.data,
});
}));
})
.catch((error) => {
setLoading(false);
Expand Down Expand Up @@ -243,8 +289,8 @@ const ModuleDetails = () => {

const handleCancelManifest = () => {
setManifestModal({
...manifestModal,
on: false,
manifest: "",
});
};

Expand Down Expand Up @@ -510,18 +556,7 @@ const ModuleDetails = () => {
</Row>
<Row>
<Col style={{ float: "right" }}>
<Button
onClick={function () {
fetchManifest(
resource.group,
resource.version,
resource.kind,
resource.namespace,
resource.name,
);
}}
block
>
<Button onClick={() => handleManifestClick(resource)} block>
View Manifest
</Button>
</Col>
Expand Down Expand Up @@ -862,6 +897,13 @@ const ModuleDetails = () => {
cancelButtonProps={{ style: { display: "none" } }}
width={"40%"}
>
<div>
<Checkbox onChange={handleCheckboxChange} checked={showManagedFields}>
Include Managed Fields
</Checkbox>
<Divider style={{ marginTop: "12px", marginBottom: "12px" }} />
</div>

<ReactAce
style={{ width: "100%" }}
mode={"sass"}
Expand Down

0 comments on commit f05c412

Please sign in to comment.