workflow

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2021 License: Apache-2.0 Imports: 64 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterStorageEP = "nfs-server"
)
View Source
const (
	NameSpaceRegexString = "[^a-z0-9.-]"
)
View Source
const SplitSymbol = "&"

Variables

View Source
var SubtaskOrder = map[config.TaskType]int{
	config.TaskType("jira"):            1,
	config.TaskType("pipeline"):        2,
	config.TaskType("buildv2"):         3,
	config.TaskType("jenkins_build"):   4,
	config.TaskType("docker_build"):    5,
	config.TaskType("archive"):         6,
	config.TaskType("artifact"):        7,
	config.TaskType("deploy"):          8,
	config.TaskType("testingv2"):       9,
	config.TaskType("security"):        10,
	config.TaskType("distribute2kodo"): 11,
	config.TaskType("release_image"):   12,
	config.TaskType("reset_image"):     13,
}

Functions

func AddDataToArgs

func AddDataToArgs(args *commonmodels.WorkflowTaskArgs, log *zap.SugaredLogger) error

func AddJiraSubTask

func AddJiraSubTask(moduleName, version, target, serviceName, productName string, log *zap.SugaredLogger) (map[string]interface{}, error)

func AddPipelineJiraSubTask

func AddPipelineJiraSubTask(pipeline *commonmodels.Pipeline, log *zap.SugaredLogger) (map[string]interface{}, error)

func AddSubtaskToStage

func AddSubtaskToStage(stages *[]*commonmodels.Stage, subTask map[string]interface{}, target string)

func BlockedTaskQueue

func BlockedTaskQueue() ([]*task.Task, error)

func BuildModuleToSubTasks

func BuildModuleToSubTasks(moduleName, version, target, serviceName, productName string, envs []*commonmodels.KeyVal, pro *commonmodels.Product, log *zap.SugaredLogger) ([]map[string]interface{}, error)

func Clean

func Clean(task *task.Task)

func ConvertQueueToTask

func ConvertQueueToTask(queueTask *commonmodels.Queue) *task.Task

func ConvertTaskToQueue

func ConvertTaskToQueue(task *task.Task) *commonmodels.Queue

func CopyPipeline added in v1.2.0

func CopyPipeline(oldPipelineName, newPipelineName, username string, log *zap.SugaredLogger) error

func CopyWorkflow

func CopyWorkflow(oldWorkflowName, newWorkflowName, username string, log *zap.SugaredLogger) error

func CreateFavoritePipeline

func CreateFavoritePipeline(args *commonmodels.Favorite, log *zap.SugaredLogger) error

func CreateGerritWebhook

func CreateGerritWebhook(workflow *commonmodels.Workflow, log *zap.SugaredLogger) error

func CreateTask

func CreateTask(t *task.Task) error

CreateTask 接受create task请求, 保存task到数据库, 发送task到queue

func CreateWorkflow

func CreateWorkflow(workflow *commonmodels.Workflow, log *zap.SugaredLogger) error

func DeleteCronjob

func DeleteCronjob(parentName, parentType string) error

func DeleteFavoritePipeline

func DeleteFavoritePipeline(args *commonrepo.FavoriteArgs) error

func DeleteGerritWebhook

func DeleteGerritWebhook(workflow *commonmodels.Workflow, log *zap.SugaredLogger) error

DeleteGerritWebhook 删除gerrit webhook

func EnsureBuildResp

func EnsureBuildResp(mb *commonmodels.Build)

func EnsureSubTasksResp

func EnsureSubTasksResp(subTasks []map[string]interface{})

EnsureSubTasksResp 确保SubTask中敏感信息和其他不必要信息不返回给前端

func EnsureTaskResp

func EnsureTaskResp(mt *commonmodels.Testing)

func EnsureTestingResp

func EnsureTestingResp(mt *commonmodels.Testing)

func FindWorkflow

func FindWorkflow(workflowName string, log *zap.SugaredLogger) (*commonmodels.Workflow, error)

func FmtBuilds

func FmtBuilds(builds []*types.Repository, log *zap.SugaredLogger)

replace gitInfo with codehostID

func GePackageFileContent added in v1.2.0

func GePackageFileContent(pipelineName string, taskID int64, log *zap.SugaredLogger) ([]byte, string, error)

func GetArtifactFileContent

func GetArtifactFileContent(pipelineName string, taskID int64, log *zap.SugaredLogger) ([]byte, error)

func GetImage

func GetImage(registry *commonmodels.RegistryNamespace, serviceName, suffix string) string

GetImage suffix 可以是 branch name 或者 pr number

func GetLink(p *task.Task, baseURI string, taskType config.PipelineType) string

func GetPackageFile

func GetPackageFile(serviceName, suffix string) string

GetPackageFile suffix 可以是 branch name 或者 pr number

func GetPipeline added in v1.2.0

func GetPipeline(userID int, pipelineName string, log *zap.SugaredLogger) (*commonmodels.Pipeline, error)

func GetPipelineTaskV2

func GetPipelineTaskV2(taskID int64, pipelineName string, typeString config.PipelineType, log *zap.SugaredLogger) (*task.Task, error)

func GetRaw

func GetRaw(name, productName string, log *zap.SugaredLogger) (*commonmodels.Testing, error)

GetRaw find the testing module with secret env not masked

func GetS3RelStorage

func GetS3RelStorage(logger *zap.SugaredLogger) (*commonmodels.S3Storage, error)

GetS3RelStorage find the default s3storage

func GetS3Storage

func GetS3Storage(id string, logger *zap.SugaredLogger) (*commonmodels.S3Storage, error)

func GetServiceNames

func GetServiceNames(p *commonmodels.Product) []string

func GetTestArtifactInfo

func GetTestArtifactInfo(pipelineName, dir string, taskID int64, log *zap.SugaredLogger) (*s3.S3, []string, error)

func GetTesting

func GetTesting(name, productName string, log *zap.SugaredLogger) (*commonmodels.Testing, error)

func HandleCronjob

func HandleCronjob(workflow *commonmodels.Workflow, log *zap.SugaredLogger) error

func HandlerWebhookTask

func HandlerWebhookTask(currentTask *task.Task) bool

HandlerWebhookTask 处理webhook逻辑

func HasPermission

func HasPermission(productName, envName string, args *commonmodels.WorkflowTaskArgs, userID int, superUser bool, log *zap.SugaredLogger) bool

func InitPipelineController

func InitPipelineController()

func InitQueue

func InitQueue() error

func IsFavoriteWorkflow

func IsFavoriteWorkflow(workflow *commonmodels.Workflow, favorites []*commonmodels.Favorite) bool

func IsProductAuthed

func IsProductAuthed(username, productOwner, productName string, perm config.ProductPermission, log *zap.SugaredLogger) bool

IsProductAuthed 查询指定产品是否授权给用户, 或者用户所在的组 TODO: REVERT Auth is diabled

func JenkinsBuildModuleToSubTasks

func JenkinsBuildModuleToSubTasks(jenkinsBuildOption *JenkinsBuildOption, log *zap.SugaredLogger) ([]map[string]interface{}, error)

func ListAllWorkflows

func ListAllWorkflows(testName string, userID int, superUser bool, log *zap.SugaredLogger) ([]*commonmodels.Workflow, error)

func ListBuildDetail

func ListBuildDetail(name, version, targets string, log *zap.SugaredLogger) ([]*commonmodels.Build, error)

func ListFavoritePipelines

func ListFavoritePipelines(args *commonrepo.FavoriteArgs) ([]*commonmodels.Favorite, error)

func ListPipelines added in v1.2.0

func ListPipelines(log *zap.SugaredLogger) ([]*commonmodels.Pipeline, error)

func ListTasks

func ListTasks() []*task.Task

func ListWorkflows

func ListWorkflows(queryType string, userID int, log *zap.SugaredLogger) ([]*commonmodels.Workflow, error)

func NextWaitingTask

func NextWaitingTask() (*task.Task, error)

NextWaitingTask 查询下一个等待的task

func ParallelRunningAndQueuedTasks

func ParallelRunningAndQueuedTasks(currentTask *task.Task) bool

func PendingPipelineTasks

func PendingPipelineTasks() []*task.Task

func PendingTasks

func PendingTasks() []*task.Task

func PipelineTaskSender

func PipelineTaskSender()

PipelineTaskSender 监控warpdrive空闲情况, 如果有空闲, 则发现下一个waiting task给warpdrive 并将task状态设置为queued

func PresetWorkflowArgs

func PresetWorkflowArgs(namespace, workflowName string, log *zap.SugaredLogger) (*commonmodels.WorkflowTaskArgs, error)

PresetWorkflowArgs 返回工作流详细信息

func Push

func Push(pt *task.Task) error

func RenamePipeline added in v1.2.0

func RenamePipeline(oldName, newName string, log *zap.SugaredLogger) error

func RestartPipelineTaskV2

func RestartPipelineTaskV2(userName string, taskID int64, pipelineName string, typeString config.PipelineType, log *zap.SugaredLogger) error

func RunningAndQueuedTasks

func RunningAndQueuedTasks() []*task.Task

func RunningPipelineTasks

func RunningPipelineTasks() []*task.Task

func RunningTasks

func RunningTasks() []*task.Task

func SetCandidateRegistry

func SetCandidateRegistry(payload *commonmodels.ConfigPayload, log *zap.SugaredLogger) error

func SetTriggerBuilds

func SetTriggerBuilds(builds []*types.Repository, buildArgs []*types.Repository, log *zap.SugaredLogger) error

外部触发任务设置build参数

func SubScribeNSQ

func SubScribeNSQ() error

func TestArgsToTestSubtask

func TestArgsToTestSubtask(args *commonmodels.TestTaskArgs, pt *task.Task, log *zap.SugaredLogger) (*task.Testing, error)

func UIType

func UIType(pipelineType config.PipelineType) string

func UpdateCronjob

func UpdateCronjob(parentName, parentType, productName string, schedule *commonmodels.ScheduleCtrl, log *zap.SugaredLogger) (deleteList []string, err error)

func UpdateGerritWebhook

func UpdateGerritWebhook(currentWorkflow *commonmodels.Workflow, log *zap.SugaredLogger) error

UpdateGerritWebhook 更新gerrit webhook

func UpdateQueue

func UpdateQueue(task *task.Task) bool

func UpdateTask

func UpdateTask(t *task.Task) error

func UpdateTaskAgent

func UpdateTaskAgent(taskID int64, pipelineName string, createTime int64, agentID string) error

func UpdateWorkflow

func UpdateWorkflow(workflow *commonmodels.Workflow, log *zap.SugaredLogger) error

func UpsertPipeline added in v1.2.0

func UpsertPipeline(args *commonmodels.Pipeline, log *zap.SugaredLogger) error

Types

type ByStageKind

type ByStageKind []*commonmodels.Stage

func (ByStageKind) Len

func (a ByStageKind) Len() int

func (ByStageKind) Less

func (a ByStageKind) Less(i, j int) bool

func (ByStageKind) Swap

func (a ByStageKind) Swap(i, j int)

type ByTaskKind

type ByTaskKind []map[string]interface{}

func (ByTaskKind) Len

func (a ByTaskKind) Len() int

func (ByTaskKind) Less

func (a ByTaskKind) Less(i, j int) bool

func (ByTaskKind) Swap

func (a ByTaskKind) Swap(i, j int)

type CancelMessage

type CancelMessage struct {
	Revoker      string `json:"revoker"`
	PipelineName string `json:"pipeline_name"`
	TaskID       int64  `json:"task_id"`
	ReqID        string `json:"req_id"`
}

type ContainerNotFound

type ContainerNotFound struct {
	ServiceName string
	Container   string
	EnvName     string
	ProductName string
}

func (*ContainerNotFound) Error

func (c *ContainerNotFound) Error() string

type CreateTaskResp

type CreateTaskResp struct {
	PipelineName string `json:"pipeline_name"`
	TaskID       int64  `json:"task_id"`
}

func CreateArtifactWorkflowTask

func CreateArtifactWorkflowTask(args *commonmodels.WorkflowTaskArgs, taskCreator string, userID int, superUser bool, log *zap.SugaredLogger) (*CreateTaskResp, error)

func CreatePipelineTask

func CreatePipelineTask(args *commonmodels.TaskArgs, log *zap.SugaredLogger) (*CreateTaskResp, error)

func CreateServiceTask added in v1.2.0

func CreateServiceTask(args *commonmodels.ServiceTaskArgs, log *zap.SugaredLogger) ([]*CreateTaskResp, error)

func CreateWorkflowTask

func CreateWorkflowTask(args *commonmodels.WorkflowTaskArgs, taskCreator string, userID int, superUser bool, log *zap.SugaredLogger) (*CreateTaskResp, error)

type CronjobWorkflowArgs

type CronjobWorkflowArgs struct {
	Target []*commonmodels.TargetArgs `bson:"targets"                      json:"targets"`
}

func GetWorkflowArgs

func GetWorkflowArgs(productName, namespace string, log *zap.SugaredLogger) (*CronjobWorkflowArgs, error)

GetWorkflowArgs 返回工作流详细信息

type DeployEnv

type DeployEnv struct {
	Env         string `json:"env"`
	Type        string `json:"type"`
	ProductName string `json:"product_name,omitempty"`
}

type EnvStatus

type EnvStatus struct {
	EnvName    string `json:"env_name,omitempty"`
	Status     string `json:"status"`
	ErrMessage string `json:"err_message"`
}

func AutoCreateWorkflow

func AutoCreateWorkflow(productName string, log *zap.SugaredLogger) *EnvStatus

type GoCacheManager

type GoCacheManager struct{}

GoCacheManager is deprecated

func NewGoCacheManager

func NewGoCacheManager() *GoCacheManager

func (*GoCacheManager) Archive

func (gcm *GoCacheManager) Archive(source, dest string) error

type ImageIllegal

type ImageIllegal struct {
}

func (*ImageIllegal) Error

func (c *ImageIllegal) Error() string

type ItReportHandler

type ItReportHandler struct {
	// contains filtered or unexported fields
}

func (*ItReportHandler) HandleMessage

func (h *ItReportHandler) HandleMessage(message *nsq.Message) error

type JenkinsBuildOption

type JenkinsBuildOption struct {
	Version          string
	Target           string
	ServiceName      string
	ProductName      string
	JenkinsBuildArgs *commonmodels.JenkinsBuildArgs
}

type PRCommit

type PRCommit struct {
	ID          string     `json:"id"`
	Title       string     `json:"title"`
	AuthorName  string     `json:"author_name"`
	CreatedAt   *time.Time `json:"created_at"`
	CheckoutRef string     `json:"checkout_ref"`
}

func GetLatestPRCommitList

func GetLatestPRCommitList(cli *gitlab.Client, projectID string, pr int) (*PRCommit, error)

func GetLatestPrCommit

func GetLatestPrCommit(codehostID, pr int, namespace, projectName string, log *zap.SugaredLogger) (*PRCommit, error)

type PipelinePreview added in v1.2.0

type PipelinePreview struct {
	ProductName     string                   `bson:"product_name"               json:"product_name"`
	Name            string                   `bson:"name"                       json:"name"`
	TeamName        string                   `bson:"team_name"                  json:"team_name"`
	SubTasks        []map[string]interface{} `bson:"sub_tasks"                  json:"sub_tasks"`
	Types           []string                 `bson:"-"                          json:"types"`
	UpdateBy        string                   `bson:"update_by"                  json:"update_by,omitempty"`
	UpdateTime      int64                    `bson:"update_time"                json:"update_time,omitempty"`
	IsFavorite      bool                     `bson:"is_favorite"                json:"is_favorite"`
	LastestTask     *commonmodels.TaskInfo   `bson:"-"                          json:"lastest_task"`
	LastSucessTask  *commonmodels.TaskInfo   `bson:"-"                          json:"last_task_success"`
	LastFailureTask *commonmodels.TaskInfo   `bson:"-"                          json:"last_task_failure"`
	TotalDuration   int64                    `bson:"-"                          json:"total_duration"`
	TotalNum        int                      `bson:"-"                          json:"total_num"`
	TotalSuccess    int                      `bson:"-"                          json:"total_success"`
}

func ListPipelinesPreview added in v1.2.0

func ListPipelinesPreview(userID int, log *zap.SugaredLogger) ([]*PipelinePreview, error)

type PreSetResp

type PreSetResp struct {
	Target          *commonmodels.ServiceModuleTarget `json:"target"`
	BuildModuleVers []string                          `json:"build_module_vers"`
	Deploy          []DeployEnv                       `json:"deploy"`
	Repos           []*types.Repository               `json:"repos"`
}

func PreSetWorkflow

func PreSetWorkflow(productName string, log *zap.SugaredLogger) ([]*PreSetResp, error)

type Preview

type Preview struct {
	Name         string              `json:"name"`
	WorkflowType config.PipelineType `json:"workflow_type"`
}

type ProductNameWithType

type ProductNameWithType struct {
	Name      string `json:"name"`
	Type      string `json:"type"`
	Namespace string `json:"namespace"`
}

func ListOldEnvsByServiceName

func ListOldEnvsByServiceName(serviceName string, log *zap.SugaredLogger) []ProductNameWithType

func ListPipelineUpdatableProductNames added in v1.2.0

func ListPipelineUpdatableProductNames(userName, pipelineName string, log *zap.SugaredLogger) ([]ProductNameWithType, error)

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func NewPipelineQueue

func NewPipelineQueue(log *zap.SugaredLogger) *Queue

func (*Queue) BlockedTaskQueue

func (q *Queue) BlockedTaskQueue() ([]*task.Task, error)

BlockedTaskQueue ...

func (*Queue) List

func (q *Queue) List() []*task.Task

func (*Queue) NextWaitingTask

func (q *Queue) NextWaitingTask() (*task.Task, error)

NextWaitingTask 查询下一个等待的task

func (*Queue) Push

func (q *Queue) Push(pt *task.Task) error

Push task queue, 如果已经存在相同的 pipeline 并且 multi=false情况 设置新的 pipeline 为 blocked 默认task状态为 created

func (*Queue) Remove

func (q *Queue) Remove(task *task.Task) error

Remove ...

func (*Queue) Update

func (q *Queue) Update(task *task.Task) bool

Update ...

func (*Queue) UpdateAgent

func (q *Queue) UpdateAgent(taskID int64, pipelineName string, createTime int64, agentID string) error

UpdateAgent ...

type RepoCommit

type RepoCommit struct {
	ID         string     `json:"id"`
	Title      string     `json:"title"`
	AuthorName string     `json:"author_name"`
	CreatedAt  *time.Time `json:"created_at"`
	Message    string     `json:"message"`
}

RepoCommit : Repository commit struct

func QueryByBranch

func QueryByBranch(id int, owner, name, branch string, log *zap.SugaredLogger) (*RepoCommit, error)

func QueryByTag

func QueryByTag(id int, owner, name, tag string, log *zap.SugaredLogger) (*RepoCommit, error)

type ServiceTaskPreview

type ServiceTaskPreview struct {
	Workflows []*Preview                         `json:"workflows"`
	Targets   []commonmodels.ServiceModuleTarget `json:"targets"`
}

func ListServiceWorkflows

func ListServiceWorkflows(productName, envName, serviceName, serviceType string, log *zap.SugaredLogger) (*ServiceTaskPreview, error)

type TaskAckHandler

type TaskAckHandler struct {
	TestTaskStatColl *commonrepo.TestTaskStatColl
	PoetryClient     *poetry.Client
	// contains filtered or unexported fields
}

func NewTaskAckHandler

func NewTaskAckHandler(poetryServer, poetryRootKey string, maxInFlight int, log *zap.SugaredLogger) *TaskAckHandler

func (*TaskAckHandler) HandleMessage

func (h *TaskAckHandler) HandleMessage(message *nsq.Message) error

HandleMessage 接收 warpdrive 回传 pipeline task 消息 1. 更新 queue pipeline task 2. 更新 数据库 pipeline task 3. 如果 pipeline task 完成, 检查是否有 blocked pipeline task, 检查是否可以unblock, 从queue中移除task

  • pipeline 完成状态包括:passed, failed, timeout

4. 更新 数据库 proudct 5. 更新历史piplinetask的状态为archived(默认只留下最近的一百个task)

type TaskNotificationHandler

type TaskNotificationHandler struct {
	// contains filtered or unexported fields
}

TaskNotificationHandler ...

func (*TaskNotificationHandler) HandleMessage

func (h *TaskNotificationHandler) HandleMessage(message *nsq.Message) error

HandleMessage ...

type TaskResult

type TaskResult struct {
	Data      []*commonrepo.TaskPreview `bson:"data"             json:"data"`
	StartAt   int                       `bson:"start_at"         json:"start_at"`
	MaxResult int                       `bson:"max_result"       json:"max_result"`
	Total     int                       `bson:"total"            json:"total"`
}

TaskResult ...

func ListPipelineTasksV2Result

func ListPipelineTasksV2Result(name string, typeString config.PipelineType, maxResult, startAt int, log *zap.SugaredLogger) (*TaskResult, error)

ListPipelineTasksV2Result 工作流任务分页信息

type TaskV2Info

type TaskV2Info struct {
	TaskID     int64  `json:"task_id"`
	Status     string `json:"status"`
	CreateTime int64  `json:"create_time"`
	StartTime  int64  `json:"start_time"`
	EndTime    int64  `json:"end_time"`
	URL        string `json:"url"`
}

func FindTasks

func FindTasks(commitID string, log *zap.SugaredLogger) ([]*TaskV2Info, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL