Skip to content

Commit

Permalink
feat(controller): configure work dir for promotion (#2547)
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco authored Sep 19, 2024
1 parent bbec37d commit 85fff0a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/controller/promotions/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package promotions
import (
"context"
"fmt"
"os"
"path/filepath"
"slices"
"strconv"
"sync"
Expand Down Expand Up @@ -522,20 +524,35 @@ func (r *reconciler) promote(
})
}

workDir := filepath.Join(os.TempDir(), "promotion-"+string(workingPromo.UID))
if err := os.MkdirAll(workDir, 0o700); err != nil && !os.IsExist(err) {
return nil, fmt.Errorf("error creating working directory: %w", err)
}
defer func() {
if workingPromo.Status.Phase.IsTerminal() {
if err := os.RemoveAll(workDir); err != nil {
logger.Error(err, "could not remove working directory")
}
}
}()

status, err := r.directivesEngine.Execute(ctx, directives.PromotionContext{
WorkDir: workDir,
Project: stageNamespace,
Stage: stageName,
FreightRequests: stage.Spec.RequestedFreight,
Freight: *workingPromo.Status.FreightCollection.DeepCopy(),
}, steps)
switch status {
case directives.StatusPending:
workingPromo.Status.Phase = kargoapi.PromotionPhaseRunning
case directives.StatusSuccess:
workingPromo.Status.Phase = kargoapi.PromotionPhaseSucceeded
case directives.StatusFailure:
workingPromo.Status.Phase = kargoapi.PromotionPhaseFailed
}
if err != nil {
return nil, err
return &workingPromo.Status, err
}
}

Expand Down

0 comments on commit 85fff0a

Please sign in to comment.