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 afb1029
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 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,30 @@ 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
}

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

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

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L533

Added line #L533 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 541 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L540-L541

Added lines #L540 - L541 were not covered by tests
case directives.StatusSuccess:
workingPromo.Status.Phase = kargoapi.PromotionPhaseSucceeded
_ = os.RemoveAll(workDir)

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

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L544

Added line #L544 was not covered by tests
case directives.StatusFailure:
workingPromo.Status.Phase = kargoapi.PromotionPhaseFailed
_ = os.RemoveAll(workDir)

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

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L547

Added line #L547 was not covered by tests
}
if err != nil {
return nil, err
return &workingPromo.Status, err

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

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L550

Added line #L550 was not covered by tests
}
}

Expand Down

0 comments on commit afb1029

Please sign in to comment.