Skip to content

Commit

Permalink
feat(controller): configure work dir for promotion
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed Sep 19, 2024
1 parent bbec37d commit a091d7d
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)

Check warning on line 529 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L527-L529

Added lines #L527 - L529 were not covered by tests
}
defer func() {
if workingPromo.Status.Phase.IsTerminal() {
if err := os.RemoveAll(workDir); err != nil {
logger.Error(err, "could not remove working directory")

Check warning on line 534 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L531-L534

Added lines #L531 - L534 were not covered by tests
}
}
}()

status, err := r.directivesEngine.Execute(ctx, directives.PromotionContext{
WorkDir: workDir,

Check warning on line 540 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L540

Added line #L540 was not covered by tests
Project: stageNamespace,
Stage: stageName,
FreightRequests: stage.Spec.RequestedFreight,
Freight: *workingPromo.Status.FreightCollection.DeepCopy(),
}, steps)
switch status {
case directives.StatusPending:
workingPromo.Status.Phase = kargoapi.PromotionPhaseRunning

Check warning on line 548 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L547-L548

Added lines #L547 - L548 were not covered by tests
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

Check warning on line 555 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L555

Added line #L555 was not covered by tests
}
}

Expand Down

0 comments on commit a091d7d

Please sign in to comment.