Skip to content

Commit

Permalink
fix(ui): latestRuns is not sorted, use lastRun
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-pad committed Apr 30, 2024
1 parent bf49119 commit 7e21b77
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
6 changes: 3 additions & 3 deletions deploy/charts/burrito/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ config:
# -- By default, the controller will watch all namespaces
namespaces: []
timers:
driftDetection: 20m
onError: 1m
waitAction: 1m
driftDetection: 1h
onError: 30s
waitAction: 15s
failureGracePeriod: 15s
terraformMaxRetries: 5
types: ["layer", "repository", "run", "pullrequest"]
Expand Down
4 changes: 4 additions & 0 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ func (r *Runner) apply() (string, error) {
log.Errorf("error executing terraform apply: %s", err)
return "", err
}
err = r.datastore.PutPlan(r.layer.Namespace, r.layer.Name, r.run.Name, strconv.Itoa(r.run.Status.Retries), "short", []byte("Apply Successful"))
if err != nil {
log.Errorf("could not put short plan in datastore: %s", err)
}
log.Infof("terraform apply ran successfully")
return b64.StdEncoding.EncodeToString(sum[:]), nil
}
Expand Down
17 changes: 12 additions & 5 deletions internal/server/api/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ type layer struct {
Path string `json:"path"`
State string `json:"state"`
RunCount int `json:"runCount"`
LastRun Run `json:"lastRun"`
LastRunAt string `json:"lastRunAt"`
LastResult string `json:"lastResult"`
IsRunning bool `json:"isRunning"`
IsPR bool `json:"isPR"`
LatestRuns []run `json:"latestRuns"`
LatestRuns []Run `json:"latestRuns"`
}

type run struct {
type Run struct {
Name string `json:"id"`
Commit string `json:"commit"`
Date string `json:"date"`
Expand Down Expand Up @@ -66,6 +67,12 @@ func (a *API) LayersHandler(c echo.Context) error {
Path: l.Spec.Path,
State: a.getLayerState(l),
RunCount: len(l.Status.LatestRuns),
LastRun: Run{
Name: l.Status.LastRun.Name,
Commit: l.Status.LastRun.Commit,
Date: l.Status.LastRun.Date.Format(time.RFC3339),
Action: l.Status.LastRun.Action,
},
LastRunAt: l.Status.LastRun.Date.Format(time.RFC3339),
LastResult: l.Status.LastResult,
IsRunning: run.Status.State != "Succeeded" && run.Status.State != "Failed",
Expand All @@ -79,10 +86,10 @@ func (a *API) LayersHandler(c echo.Context) error {
)
}

func transformLatestRuns(runs []configv1alpha1.TerraformLayerRun) []run {
results := []run{}
func transformLatestRuns(runs []configv1alpha1.TerraformLayerRun) []Run {
results := []Run{}
for _, r := range runs {
results = append(results, run{
results = append(results, Run{
Name: r.Name,
Commit: r.Commit,
Date: r.Date.Format(time.RFC3339),
Expand Down
1 change: 1 addition & 0 deletions ui/src/clients/layers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type Layer = {
path: string;
runCount: number;
lastRunAt: string;
lastRun: Run;
latestRuns: Run[];
lastResult: string;
isRunning: boolean;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/tools/ModalLogsTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ModalLogsTerminal: React.FC<ModalLogsTerminalProps> = ({
const navigate = useNavigate();

const handleOpenInLogs = () => {
navigate(`/logs/${layer.id}/${layer.latestRuns[0].id}`);
navigate(`/logs/${layer.namespace}/${layer.name}/${layer.lastRun.id}`);
};

return (
Expand All @@ -70,7 +70,7 @@ const ModalLogsTerminal: React.FC<ModalLogsTerminalProps> = ({
>
<LogsTerminal
layer={layer}
run={layer.latestRuns[0].id}
run={layer.lastRun.id}
className="h-[70vh] w-[60vw]"
variant={variant}
/>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/pages/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ const Logs: React.FC = () => {

const handleActive = (layer: Layer, run?: string) => {
navigate({
pathname: `/logs/${layer.id}${
pathname: `/logs/${layer.namespace}/${layer.name}${
run
? `/${run}`
: layer.latestRuns.length > 0
? `/${layer.latestRuns[0].id}`
? `/${layer.lastRun}`
: ""
}`,
search: searchParams.toString(),
Expand Down

0 comments on commit 7e21b77

Please sign in to comment.