-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3984b21
commit 53eae91
Showing
21 changed files
with
659 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,38 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1" | ||
"github.com/padok-team/burrito/internal/annotations" | ||
"github.com/padok-team/burrito/internal/server/utils" | ||
log "github.com/sirupsen/logrus" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func (a *API) SyncLayerHandler(c echo.Context) error { | ||
layer := &configv1alpha1.TerraformLayer{} | ||
err := a.Client.Get(context.Background(), client.ObjectKey{ | ||
Namespace: c.Param("namespace"), | ||
Name: c.Param("layer"), | ||
}, layer) | ||
if err != nil { | ||
log.Errorf("could not get terraform layer: %s", err) | ||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "An error occurred while getting the layer"}) | ||
} | ||
syncStatus := utils.GetManualSyncStatus(*layer) | ||
if syncStatus == utils.ManualSyncAnnotated || syncStatus == utils.ManualSyncPending { | ||
return c.JSON(http.StatusConflict, map[string]string{"error": "Layer sync already triggered"}) | ||
} | ||
|
||
err = annotations.Add(context.Background(), a.Client, layer, map[string]string{ | ||
annotations.SyncNow: "true", | ||
}) | ||
if err != nil { | ||
log.Errorf("could not update terraform layer annotations: %s", err) | ||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "An error occurred while updating the layer annotations"}) | ||
} | ||
return c.JSON(http.StatusOK, map[string]string{"status": "Layer sync triggered"}) | ||
} |
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
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,27 @@ | ||
package utils | ||
|
||
import ( | ||
configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1" | ||
"github.com/padok-team/burrito/internal/annotations" | ||
) | ||
|
||
type ManualSyncStatus string | ||
|
||
const ( | ||
ManualSyncNone ManualSyncStatus = "none" | ||
ManualSyncAnnotated ManualSyncStatus = "annotated" | ||
ManualSyncPending ManualSyncStatus = "pending" | ||
) | ||
|
||
func GetManualSyncStatus(layer configv1alpha1.TerraformLayer) ManualSyncStatus { | ||
if layer.Annotations[annotations.SyncNow] == "true" { | ||
return ManualSyncAnnotated | ||
} | ||
// check the IsSyncScheduled condition on layer | ||
for _, c := range layer.Status.Conditions { | ||
if c.Type == "IsSyncScheduled" && c.Status == "True" { | ||
return ManualSyncPending | ||
} | ||
} | ||
return ManualSyncNone | ||
} |
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
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
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
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,54 @@ | ||
import React from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
import { Tooltip } from "react-tooltip"; | ||
export interface GenericIconButtonProps { | ||
className?: string; | ||
variant?: "light" | "dark"; | ||
disabled?: boolean; | ||
tooltip?: string; | ||
width?: number; | ||
height?: number; | ||
onClick?: () => void; | ||
Icon: React.FC<React.SVGProps<SVGSVGElement>>; | ||
} | ||
|
||
|
||
const GenericIconButton: React.FC<GenericIconButtonProps> = ({ | ||
className, | ||
variant, | ||
disabled, | ||
tooltip, | ||
onClick, | ||
width = 40, | ||
height = 40, | ||
Icon | ||
}) => { | ||
const hoverClass = !disabled ? (variant === "light" ? "hover:bg-primary-300" : "hover:bg-nuances-black") : ""; | ||
return ( | ||
<div style={{ width: `${width}px`, height: `${height}px` }}> | ||
<Tooltip | ||
opacity={1} | ||
id="generic-button-tooltip" | ||
variant={variant === "light" ? "dark" : "light"} | ||
/> | ||
<button | ||
onClick={disabled ? undefined : onClick} | ||
disabled={disabled} | ||
className={twMerge( | ||
`${hoverClass} | ||
disabled:opacity-50 | ||
disabled:cursor-default | ||
rounded-full | ||
cursor-pointer | ||
transition-colors | ||
duration-300`, | ||
className | ||
)} | ||
> | ||
<Icon data-tooltip-id="generic-button-tooltip" data-tooltip-content={tooltip} className="p-2 fill-blue-500" width={width} height={height} /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GenericIconButton; |
Oops, something went wrong.