Skip to content

Commit

Permalink
fix(schedule): honor allow list for previously created schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Nov 2, 2023
1 parent 6708cea commit 6ab28f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions cmd/vela-server/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-vela/server/database"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
"github.com/go-vela/types"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
Expand All @@ -29,7 +30,7 @@ const (
scheduleWait = "waiting to trigger build for schedule"
)

func processSchedules(ctx context.Context, start time.Time, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service) error {
func processSchedules(ctx context.Context, start time.Time, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service, allowList []string) error {
logrus.Infof("processing active schedules to create builds")

// send API call to capture the list of active schedules
Expand Down Expand Up @@ -122,7 +123,7 @@ func processSchedules(ctx context.Context, start time.Time, compiler compiler.En
}

// process the schedule and trigger a new build
err = processSchedule(ctx, schedule, compiler, database, metadata, queue, scm)
err = processSchedule(ctx, schedule, compiler, database, metadata, queue, scm, allowList)
if err != nil {
logrus.WithError(err).Warnf("%s %s", scheduleErr, schedule.GetName())

Expand All @@ -134,13 +135,18 @@ func processSchedules(ctx context.Context, start time.Time, compiler compiler.En
}

//nolint:funlen // ignore function length and number of statements
func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service) error {
func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service, allowList []string) error {
// send API call to capture the repo for the schedule
r, err := database.GetRepo(ctx, s.GetRepoID())
if err != nil {
return fmt.Errorf("unable to fetch repo: %w", err)
}

// ensure repo has not been removed from allow list
if !util.CheckAllowlist(r, allowList) {
return fmt.Errorf("skipping schedule: repo %s no longer on allow list", r.GetFullName())
}

logrus.Tracef("processing schedule %s/%s", r.GetFullName(), s.GetName())

// check if the repo is active
Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func server(c *cli.Context) error {
// sleep for a duration of time before processing schedules
time.Sleep(jitter)

err = processSchedules(ctx, start, compiler, database, metadata, queue, scm)
err = processSchedules(ctx, start, compiler, database, metadata, queue, scm, c.StringSlice("vela-schedule-allowlist"))
if err != nil {
logrus.WithError(err).Warn("unable to process schedules")
} else {
Expand Down

0 comments on commit 6ab28f7

Please sign in to comment.