-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add manual layer sync #321
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
93244fa
feat(controller): handle sync-now annotation on layers
LucasMrqes 751ca31
feat(server): add api route to add sync-now annotation
LucasMrqes 132730c
feat(ui): add generic icon button
LucasMrqes 12a0800
feat(ui): add button to sync layers manually
LucasMrqes 6a73c6d
fix(controller): handle annotation removal error
LucasMrqes af35f81
feat(server): add user feedback on manual sync
LucasMrqes fc3d7a9
feat: automatically refresh the layer page after scheduling a sync
LucasMrqes 946eac3
feat(controller): add tests for manual sync condition
LucasMrqes 19b6e7b
fix(ui): make onSyncRequestComplete prop optional on layers cards and…
LucasMrqes 422a799
chore: typo in comment
LucasMrqes 49b6d3b
feat(ui): better ui feedback on sync button
LucasMrqes db1772b
feat(ui): add slider to sync multiples layer at a time
LucasMrqes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the annotation right away is causing another reconciliation right?
Does the layer end in a
NoSyncScheduled
status just a few seconds later? Does it impact the Server API in itsSyncLayerHandler
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The layer controller creates a run, and the run controller locks the layer related to a this new run until the run succeeds or fails. Since the layer is locked during the whole duration of the run, this should not cause any issue.