Skip to content

Commit

Permalink
feat: trigger on deploy status and periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
msvticket committed Jul 28, 2023
1 parent 89d6f29 commit f98d820
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 0 additions & 2 deletions pkg/config/job/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package job
type Periodic struct {
Base
Reporter
// The branch to build
Branch string `json:"branch"`
// Cron representation of job trigger time
Cron string `json:"cron"`
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/plugins/trigger/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (p PeriodicAgent) UpdatePeriodics(org string, repo string, agent plugins.Ag
// Probably better then to just create CronJobs that create LighthouseJobs/PipelineRuns using kubectl/tkn.
// Possibly with the Pipeline stored as separate resource and then either have the LighthouseJob refer to it or do tkn pipeline start.
// With proper labels these CronJobs/Pipelines could be handled fairly efficiently
// So with LighthouseJobs it could be rendered and put in a configmap which is mounted in the cronjob.
// Then kubectl apply -f to create the job and then to set the status kubectl patch LighthouseJob myresource --type=merge --subresource status --patch 'status: {state: triggered}'
// Would really only need to run StartPeriodics when in a new cluster. How do I know when it is needed? I would
// need to store in cluster when StartPeriodics has been run.
repoPeriodics := maps.Clone(p.Periodics[fullName])
if repoPeriodics == nil {
repoPeriodics = make(map[string]PeriodicExec)
Expand Down Expand Up @@ -87,9 +91,8 @@ func (p *PeriodicExec) Run() {
labels[k] = v
}
refs := v1alpha1.Refs{
Org: p.Owner,
Repo: p.Repo,
BaseRef: p.Branch,
Org: p.Owner,
Repo: p.Repo,
}
l := logrus.WithField(scmprovider.RepoLogField, p.Repo).WithField(scmprovider.OrgLogField, p.Owner)

Expand Down
7 changes: 6 additions & 1 deletion pkg/webhook/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/url"
"regexp"
"strconv"
"strings"
"sync"

lru "github.com/hashicorp/golang-lru"
Expand Down Expand Up @@ -218,7 +219,11 @@ func (s *Server) handlePushEvent(l *logrus.Entry, pe *scm.PushHook) {
}(p, h.PushEventHandler)
}
}
s.PeriodicAgent.UpdatePeriodics(repo.Namespace, repo.Name, agent, pe)
// Update periodics from the default branch
refBranch := strings.TrimPrefix(pe.Ref, "refs/heads/")
if refBranch == pe.Repository().Branch {
s.PeriodicAgent.UpdatePeriodics(repo.Namespace, repo.Name, agent, pe)
}
l.WithField("count", strconv.Itoa(c)).Info("number of push handlers")
}()
}
Expand Down

0 comments on commit f98d820

Please sign in to comment.