Skip to content

Commit

Permalink
Merge pull request #193 from xuzhu-591/feat-approval
Browse files Browse the repository at this point in the history
Feat: support for pipelinerun checks
  • Loading branch information
xuzhu-591 authored Sep 22, 2023
2 parents 665168f + a5203e3 commit d09b910
Show file tree
Hide file tree
Showing 83 changed files with 3,574 additions and 471 deletions.
4 changes: 3 additions & 1 deletion core/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import (
"github.com/horizoncd/horizon/pkg/jobs/grafanasync"
"github.com/horizoncd/horizon/pkg/jobs/k8sevent"
jobwebhook "github.com/horizoncd/horizon/pkg/jobs/webhook"
prservice "github.com/horizoncd/horizon/pkg/pr/service"
"github.com/horizoncd/horizon/pkg/regioninformers"
"github.com/horizoncd/horizon/pkg/token/generator"
tokenservice "github.com/horizoncd/horizon/pkg/token/service"
Expand Down Expand Up @@ -465,6 +466,7 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
OutputGetter: outputGetter,
TektonFty: tektonFty,
ClusterGitRepo: clusterGitRepo,
PRService: prservice.NewService(manager),
GitGetter: gitGetter,
GrafanaService: grafanaService,
BuildSchema: buildSchema,
Expand Down Expand Up @@ -494,7 +496,7 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
applicationCtl = applicationctl.NewController(parameter)
envTemplateCtl = envtemplatectl.NewController(parameter)
clusterCtl = clusterctl.NewController(coreConfig, parameter)
prCtl = prctl.NewController(parameter)
prCtl = prctl.NewController(coreConfig, parameter)
templateCtl = templatectl.NewController(parameter, templateRepo)
roleCtl = roltctl.NewController(parameter)
terminalCtl = terminalctl.NewController(parameter)
Expand Down
6 changes: 6 additions & 0 deletions core/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package common

type Resource struct {
ResourceID uint `json:"resource_id" yaml:"resourceID"`
Type string `gorm:"column:resource_type" json:"resource_type" yaml:"resourceType"`
}
4 changes: 4 additions & 0 deletions core/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const (
// use the pipeline's cluster's member info
ResourcePipelinerun = "pipelineruns"

// ResourceCheckrun currently checkruns do not have direct member info, will
// use the member info of the clusters that they belong to
ResourceCheckrun = "checkruns"

// ResourceOauthApps currently oauthapp do not have direct member info, will
// use the oauthapp's groups member info
ResourceOauthApps = "oauthapps"
Expand Down
19 changes: 19 additions & 0 deletions core/common/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package common

import (
"strconv"
"strings"
)

func UnmarshalTraversalIDS(traversalIDs string) ([]uint, error) {
splitIds := strings.Split(traversalIDs, ",")
var ids = make([]uint, len(splitIds))
for i, id := range splitIds {
ii, err := strconv.Atoi(id)
if err != nil {
return nil, err
}
ids[i] = uint(ii)
}
return ids, nil
}
5 changes: 5 additions & 0 deletions core/common/pipelinerun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package common

const (
PipelineQueryByStatus = "status"
)
1 change: 1 addition & 0 deletions core/common/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
const (
UserQueryName = "filter"
UserQueryType = "userType"
UserQueryID = "id"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions core/controller/application/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import (
"github.com/horizoncd/horizon/pkg/member"
membermodels "github.com/horizoncd/horizon/pkg/member/models"
"github.com/horizoncd/horizon/pkg/param"
pipelinemanager "github.com/horizoncd/horizon/pkg/pipelinerun/pipeline/manager"
pipelinemodels "github.com/horizoncd/horizon/pkg/pipelinerun/pipeline/models"
pipelinemanager "github.com/horizoncd/horizon/pkg/pr/pipeline/manager"
pipelinemodels "github.com/horizoncd/horizon/pkg/pr/pipeline/models"
regionmodels "github.com/horizoncd/horizon/pkg/region/models"
tagmanager "github.com/horizoncd/horizon/pkg/tag/manager"
tagmodels "github.com/horizoncd/horizon/pkg/tag/models"
Expand Down
14 changes: 7 additions & 7 deletions core/controller/cloudevent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/horizoncd/horizon/pkg/cluster/tekton/factory"
perror "github.com/horizoncd/horizon/pkg/errors"
"github.com/horizoncd/horizon/pkg/param"
prmanager "github.com/horizoncd/horizon/pkg/pipelinerun/manager"
prmodels "github.com/horizoncd/horizon/pkg/pipelinerun/models"
pipelinemanager "github.com/horizoncd/horizon/pkg/pipelinerun/pipeline/manager"
prmanager "github.com/horizoncd/horizon/pkg/pr/manager"
prmodels "github.com/horizoncd/horizon/pkg/pr/models"
pipelinemanager "github.com/horizoncd/horizon/pkg/pr/pipeline/manager"
"github.com/horizoncd/horizon/pkg/server/global"
trmanager "github.com/horizoncd/horizon/pkg/templaterelease/manager"
usermanager "github.com/horizoncd/horizon/pkg/user/manager"
Expand All @@ -45,7 +45,7 @@ type Controller interface {

type controller struct {
tektonFty factory.Factory
pipelinerunMgr prmanager.Manager
prMgr *prmanager.PRManager
pipelineMgr pipelinemanager.Manager
clusterMgr clustermanager.Manager
clusterGitRepo gitrepo.ClusterGitRepo
Expand All @@ -57,7 +57,7 @@ type controller struct {
func NewController(tektonFty factory.Factory, parameter *param.Param) Controller {
return &controller{
tektonFty: tektonFty,
pipelinerunMgr: parameter.PipelinerunMgr,
prMgr: parameter.PRMgr,
pipelineMgr: parameter.PipelineMgr,
clusterMgr: parameter.ClusterMgr,
clusterGitRepo: parameter.ClusterGitRepo,
Expand Down Expand Up @@ -100,7 +100,7 @@ func (c *controller) CloudEvent(ctx context.Context, wpr *WrappedPipelineRun) (e
pipelinerunID, result.Result, result.StartTime, result.CompletionTime)

// 2. update pipelinerun in db
if err := c.pipelinerunMgr.UpdateResultByID(ctx, pipelinerunID, &prmodels.Result{
if err := c.prMgr.PipelineRun.UpdateResultByID(ctx, pipelinerunID, &prmodels.Result{
S3Bucket: result.Bucket,
LogObject: result.LogObject,
PrObject: result.PrObject,
Expand Down Expand Up @@ -180,7 +180,7 @@ func (c *controller) handleJibBuild(ctx context.Context, result *tekton.Pipeline
func (c *controller) getHorizonMetaData(ctx context.Context, wpr *WrappedPipelineRun) (
*global.HorizonMetaData, error) {
eventID := wpr.PipelineRun.Labels[common.TektonTriggersEventIDKey]
pipelinerun, err := c.pipelinerunMgr.GetByCIEventID(ctx, eventID)
pipelinerun, err := c.prMgr.PipelineRun.GetByCIEventID(ctx, eventID)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions core/controller/cloudevent/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import (
membermodels "github.com/horizoncd/horizon/pkg/member/models"
"github.com/horizoncd/horizon/pkg/param"
"github.com/horizoncd/horizon/pkg/param/managerparam"
prmodels "github.com/horizoncd/horizon/pkg/pipelinerun/models"
pipelinemodels "github.com/horizoncd/horizon/pkg/pipelinerun/pipeline/models"
prmodels "github.com/horizoncd/horizon/pkg/pr/models"
pipelinemodels "github.com/horizoncd/horizon/pkg/pr/pipeline/models"
trmodels "github.com/horizoncd/horizon/pkg/templaterelease/models"
usermodels "github.com/horizoncd/horizon/pkg/user/models"

Expand Down Expand Up @@ -267,7 +267,7 @@ func Test(t *testing.T) {
ApplicationID: application.ID,
Name: "cluster",
}, nil, nil)
pipelinerunMgr := manager.PipelinerunMgr
pipelinerunMgr := manager.PRMgr.PipelineRun
_, err := pipelinerunMgr.Create(ctx, &prmodels.Pipelinerun{
ClusterID: cluster.ID,
Action: "builddeploy",
Expand Down
13 changes: 9 additions & 4 deletions core/controller/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ import (
groupsvc "github.com/horizoncd/horizon/pkg/group/service"
"github.com/horizoncd/horizon/pkg/member"
"github.com/horizoncd/horizon/pkg/param"
prmanager "github.com/horizoncd/horizon/pkg/pipelinerun/manager"
pipelinemanager "github.com/horizoncd/horizon/pkg/pipelinerun/pipeline/manager"
prmanager "github.com/horizoncd/horizon/pkg/pr/manager"
prmodels "github.com/horizoncd/horizon/pkg/pr/models"
pipelinemanager "github.com/horizoncd/horizon/pkg/pr/pipeline/manager"
prservice "github.com/horizoncd/horizon/pkg/pr/service"
regionmanager "github.com/horizoncd/horizon/pkg/region/manager"
tagmanager "github.com/horizoncd/horizon/pkg/tag/manager"
trmanager "github.com/horizoncd/horizon/pkg/templaterelease/manager"
Expand Down Expand Up @@ -122,6 +124,7 @@ type Controller interface {
// Deprecated: for internal usage, v1 to v2
Upgrade(ctx context.Context, clusterID uint) error
ToggleLikeStatus(ctx context.Context, clusterID uint, like *WhetherLike) (err error)
CreatePipelineRun(ctx context.Context, clusterID uint, r *CreatePipelineRunRequest) (*prmodels.PipelineBasic, error)
}

type controller struct {
Expand All @@ -142,7 +145,8 @@ type controller struct {
envRegionMgr environmentregionmapper.Manager
regionMgr regionmanager.Manager
groupSvc groupsvc.Service
pipelinerunMgr prmanager.Manager
prMgr *prmanager.PRManager
prSvc *prservice.Service
pipelineMgr pipelinemanager.Manager
tektonFty factory.Factory
registryFty registryfty.RegistryGetter
Expand Down Expand Up @@ -183,7 +187,8 @@ func NewController(config *config.Config, param *param.Param) Controller {
envRegionMgr: param.EnvRegionMgr,
regionMgr: param.RegionMgr,
groupSvc: param.GroupSvc,
pipelinerunMgr: param.PipelinerunMgr,
prMgr: param.PRMgr,
prSvc: param.PRService,
pipelineMgr: param.PipelineMgr,
tektonFty: param.TektonFty,
registryFty: registryfty.Fty,
Expand Down
4 changes: 2 additions & 2 deletions core/controller/cluster/controller_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (c *controller) GetCluster(ctx context.Context, clusterID uint) (_ *GetClus
clusterFiles.PipelineJSONBlob, clusterFiles.ApplicationJSONBlob, tags...)

// 9. get latest deployed commit
latestPR, err := c.pipelinerunMgr.GetLatestSuccessByClusterID(ctx, clusterID)
latestPR, err := c.prMgr.PipelineRun.GetLatestSuccessByClusterID(ctx, clusterID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -891,7 +891,7 @@ func (c *controller) DeleteCluster(ctx context.Context, clusterID uint, hard boo
log.Errorf(newctx, "failed to delete members of cluster: %v, err: %v", cluster.Name, err)
}
// delete pipelinerun
if err := c.pipelinerunMgr.DeleteByClusterID(ctx, clusterID); err != nil {
if err := c.prMgr.PipelineRun.DeleteByClusterID(ctx, clusterID); err != nil {
log.Errorf(newctx, "failed to delete pipelineruns of cluster: %v, err: %v", cluster.Name, err)
}
// delete tag
Expand Down
Loading

0 comments on commit d09b910

Please sign in to comment.