Skip to content

Commit

Permalink
Signal when pruning should kick in
Browse files Browse the repository at this point in the history
Without sending on the channel, pruning will never happen.

Fixes #557.
  • Loading branch information
michaelsauter committed Jun 9, 2022
1 parent 49e0934 commit 17d3509
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ listed in the changelog.

## [Unreleased]

### Fixed
- Pipeline runs are not pruned ([#557](https://github.com/opendevstack/ods-pipeline/issues/557))

## [0.5.0] - 2022-06-09

Expand Down
1 change: 1 addition & 0 deletions cmd/pipeline-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func serve() error {

s := &manager.Scheduler{
TriggeredPipelines: triggeredPipelinesChan,
TriggeredRepos: triggeredReposChan,
PendingRunRepos: pendingRunReposChan,
TektonClient: tClient,
KubernetesClient: kClient,
Expand Down
6 changes: 5 additions & 1 deletion internal/manager/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type StorageConfig struct {
type Scheduler struct {
// Channel to read newly received runs from
TriggeredPipelines chan PipelineConfig
// Channel to send pending runs on
// Channel to send triggered repos on (signalling to start pruning)
TriggeredRepos chan string
// Channel to send pending runs on (singalling to start watching)
PendingRunRepos chan string
TektonClient tektonClient.ClientInterface
KubernetesClient kubernetesClient.ClientInterface
Expand Down Expand Up @@ -98,6 +100,8 @@ func (s *Scheduler) schedule(ctx context.Context, pData PipelineConfig) bool {
s.Logger.Errorf(err.Error())
return false
}
// Trigger pruning
s.TriggeredRepos <- pData.Repository
return needQueueing
}

Expand Down
9 changes: 7 additions & 2 deletions internal/manager/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func TestSchedule(t *testing.T) {

cfg := PipelineConfig{
PipelineInfo: PipelineInfo{
Name: "pipeline",
Name: "pipeline",
Repository: "repo",
},
PVC: "pvc",
}
Expand Down Expand Up @@ -87,7 +88,8 @@ func TestSchedule(t *testing.T) {
ClassName: "class",
Size: "1Gi",
},
Logger: &logging.LeveledLogger{Level: logging.LevelNull},
Logger: &logging.LeveledLogger{Level: logging.LevelNull},
TriggeredRepos: make(chan string, 100),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -105,6 +107,9 @@ func TestSchedule(t *testing.T) {
if len(tc.tektonClient.CreatedPipelineRuns) != 1 {
t.Fatal("one pipeline run should have been created")
}
if gotTriggered := <-s.TriggeredRepos; gotTriggered != "repo" {
t.Fatal("channel should have received the repository name")
}
if tc.wantQueuedRun != gotQueued {
t.Fatalf("want queued: %v, got: %v", tc.wantQueuedRun, gotQueued)
}
Expand Down

0 comments on commit 17d3509

Please sign in to comment.