Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schedule): honor allow list for previously created schedules #998

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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