Skip to content

Commit

Permalink
♻️ add button for manual reconciliation (cyclops-ui#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-cvit authored Aug 16, 2024
1 parent 830e0e5 commit 6e5360b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cyclops-ctrl/internal/controller/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/gin-gonic/gin"

Expand Down Expand Up @@ -314,6 +315,39 @@ func (m *Modules) UpdateModule(ctx *gin.Context) {
ctx.Status(http.StatusOK)
}

func (m *Modules) ReconcileModule(ctx *gin.Context) {
ctx.Header("Access-Control-Allow-Origin", "*")

moduleName := ctx.Param("name")

module, err := m.kubernetesClient.GetModule(moduleName)
if err != nil {
fmt.Println(err)
ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching module", err.Error()))
return
}

annotations := module.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}

annotations["cyclops/reconciled-at"] = time.Now().Format(time.RFC3339)
module.SetAnnotations(annotations)

module.Kind = "Module"
module.APIVersion = "cyclops-ui.com/v1alpha1"

err = m.kubernetesClient.UpdateModule(module)
if err != nil {
fmt.Println(err)
ctx.JSON(http.StatusInternalServerError, dto.NewError("Error updating module", err.Error()))
return
}

ctx.Status(http.StatusAccepted)
}

func (m *Modules) ResourcesForModule(ctx *gin.Context) {
ctx.Header("Access-Control-Allow-Origin", "*")

Expand Down
1 change: 1 addition & 0 deletions cyclops-ctrl/internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (h *Handler) Start() error {
h.router.DELETE("/modules/:name", modulesController.DeleteModule)
h.router.POST("/modules/new", modulesController.CreateModule)
h.router.POST("/modules/update", modulesController.UpdateModule)
h.router.POST("/modules/:name/reconcile", modulesController.ReconcileModule)
h.router.GET("/modules/:name/history", modulesController.GetModuleHistory)
h.router.POST("/modules/:name/manifest", modulesController.Manifest)
h.router.GET("/modules/:name/currentManifest", modulesController.CurrentManifest)
Expand Down
35 changes: 35 additions & 0 deletions cyclops-ui/src/components/pages/ModuleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ import "ace-builds/src-noconflict/ace";
import { useParams } from "react-router-dom";
import axios from "axios";
import {
BookOutlined,
CaretRightOutlined,
CheckCircleTwoTone,
CloseSquareTwoTone,
CopyOutlined,
DeleteOutlined,
EditOutlined,
FileTextOutlined,
SearchOutlined,
UndoOutlined,
WarningTwoTone,
} from "@ant-design/icons";
import "./custom.css";
Expand Down Expand Up @@ -119,6 +124,8 @@ const ModuleDetails = () => {
const [loading, setLoading] = useState(false);
const [loadModule, setLoadModule] = useState(false);
const [loadResources, setLoadResources] = useState(false);
const [loadingReconciliation, setLoadingReconciliation] = useState(false);

const [deleteName, setDeleteName] = useState("");
const [deleteResourceVerify, setDeleteResourceVerify] = useState("");
const [resources, setResources] = useState([]);
Expand Down Expand Up @@ -809,6 +816,20 @@ const ModuleDetails = () => {
});
};

const submitReconcileModule = () => {
setLoadingReconciliation(true);

axios
.post(`/api/modules/` + moduleName + `/reconcile`)
.then((res) => {
setLoadingReconciliation(false);
})
.catch((error) => {
setError(mapResponseError(error));
setLoadingReconciliation(false);
});
};

const renderedManifestModalContent = () => {
if (loadingRenderedManifest) {
return <Spin />;
Expand Down Expand Up @@ -875,21 +896,34 @@ const ModuleDetails = () => {
}}
block
>
<EditOutlined />
Edit
</Button>
</Col>
<Col>
<Button
onClick={submitReconcileModule}
block
loading={loadingReconciliation}
>
<UndoOutlined />
Reconcile
</Button>
</Col>
<Col>
<Button
onClick={function () {
window.location.href = "/modules/" + moduleName + "/rollback";
}}
block
>
<BookOutlined />
Rollback
</Button>
</Col>
<Col>
<Button onClick={handleViewRenderedManifest} block>
<FileTextOutlined />
View Manifest
</Button>
</Col>
Expand All @@ -902,6 +936,7 @@ const ModuleDetails = () => {
block
loading={loading}
>
<DeleteOutlined />
Delete
</Button>
</Col>
Expand Down

0 comments on commit 6e5360b

Please sign in to comment.