model

package
v0.0.0-...-eae78d9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	WorkEnvKey   string = "workenv"
	PluginEnvKey string = "pluginenv"
)

Env Key

View Source
const (
	DefaultNameSpace = "malcolm" // #todo ->param
	PodTypeJob       = "jobpod"
	PodTypeService   = "servicepod"
)

consts

View Source
const (
	TriggerTypeManual   = "manual"
	TriggerTypeCron     = "cron"
	TriggerTypeWeebhook = "webhook"
)

Trigger type

Variables

View Source
var (
	PluginTypeScm     = "scm"
	PluginTypeBuild   = "build"
	PluginTypeArchive = "archive"
	PluginTypeNotify  = "notify"

	AvailablePluginTypes = sets.NewString(PluginTypeScm, PluginTypeBuild, PluginTypeArchive, PluginTypeNotify)
)

Plugin type

View Source
var (
	TriggerManual = TriggerConfigTemplate{
		Type:   "manual",
		Schema: "",
	}
	TriggerCron = TriggerConfigTemplate{
		Type: "cron",
		Schema: `{
			"description": "webhook setting",
			"type": "object",
			"properties": {
				"schedule": {
				"type": "string"
				}
		    }
		}`,
	}
	TriggerWebHook = TriggerConfigTemplate{
		Type: "webhook",
		Schema: `{
			"description": "webhook setting",
			"type": "object",
			"properties": {
				"matchevent": {
				"type": "string"
				},
				"matchbranch": {
				"type": "string"
				}
		    }
		}`,
	}
	AvaliablesTriggerTemplate = []TriggerConfigTemplate{TriggerManual, TriggerCron, TriggerWebHook}
)

Trigger template type

View Source
var DefaultBuildConfig = &GeneralBuildingConfig{
	Project:                DefaultNameSpace,
	WorkTimeoutDefault:     60,
	StepTimeoutDefault:     60,
	ConstriantStateDefault: MatchStateSuccess,
	WorkSpace:              "/workspace",
	StorageSize:            "1Gi",
}

DefaultBuildConfig is default building config

Functions

func WarpErrors

func WarpErrors(errs ...error) error

WarpErrors wrap errors

Types

type Build

type Build struct {
	ID          bson.ObjectId             `bson:"_id"`
	PipeID      bson.ObjectId             `bson:"pipeid" index:"index"`
	Trigger     Trigger                   `bson:"trigger,omitempty"`
	Title       string                    `bson:"title,omitempty"`
	Description string                    `bson:"description,omitempty"`
	Project     string                    `bson:"project,omitempty" index:"index"`
	Status      BuildStatus               `bson:"status,omitempty" index:"index"`
	Created     time.Time                 `bson:"created"`
	Started     time.Time                 `bson:"started"`
	Finished    time.Time                 `bson:"finished"`
	Updated     time.Time                 `bson:"updated"`
	CurrentStep int                       `bson:"currentStep,omitempty"`
	Steps       []*WorkStep               `bson:"steps,omitempty"`
	Author      string                    `bson:"author,omitempty"`
	Dirty       bool                      `bson:"-" json:"-"`
	Volumn      *v1.PersistentVolumeClaim `bson:"volumn,omitempty" json:"volumn,omitempty"`
}

Build is a running/runned instance of pipeline

type BuildAction

type BuildAction string

BuildAction is trigger input

const (
	ActionStart  BuildAction = "start"
	ActionPause  BuildAction = "pause"
	ActionResume BuildAction = "resume"
	ActionStop   BuildAction = "stop"
)

BuildAction types

type BuildState

type BuildState string

BuildState is general state info of build

const (
	BuildStatePending  BuildState = "pending"
	BuildStateRunning  BuildState = "running"
	BuildStatePaused   BuildState = "paused"
	BuildStatePausing  BuildState = "pausing"
	BuildStateComplete BuildState = "complete"
)

BuildState types

type BuildStatus

type BuildStatus struct {
	State       BuildState
	StateDetail StateDetail
	Message     string
}

BuildStatus represent building status

type Config

type Config struct {
	MgoCfg   mgoutil.Config
	KubeAddr string
}

Config is server config

type Constraint

type Constraint struct {
	MatchState       `bson:"matchState"` // last step.statedetail match
	MatchEnvs        map[string]string   // step.env match val
	MatchExpressions []LabelSelectorRequirement
}

Prerequisites is tells when taskgroup should running

type CronTrigger

type CronTrigger struct {
	Schedule string
}

CronTrigger ..

type GeneralBuildingConfig

type GeneralBuildingConfig struct {
	Project                string
	WorkTimeoutDefault     int // in minute
	StepTimeoutDefault     int // in minute
	ConstriantStateDefault MatchState
	ResourceLimitDefault   Resource
	ResourceLimitRequest   Resource
	WorkSpace              string
	StorageClass           string
	StorageSize            string
}

GeneralBuildingConfig is project based building config

type LabelSelectorOperator

type LabelSelectorOperator string
const (
	LabelSelectorOpIn           LabelSelectorOperator = "In"
	LabelSelectorOpNotIn        LabelSelectorOperator = "NotIn"
	LabelSelectorOpExists       LabelSelectorOperator = "Exists"
	LabelSelectorOpDoesNotExist LabelSelectorOperator = "DoesNotExist"
)

type LabelSelectorRequirement

type LabelSelectorRequirement struct {
	Key      string
	Operator LabelSelectorOperator
	Values   []string
}

type ManualTrigger

type ManualTrigger struct {
	Author string
	Params map[string]string
}

ManualTrigger ..

type MatchState

type MatchState string

MatchState :last step status

const (
	MatchStateFail    MatchState = "Fail"
	MatchStateSuccess MatchState = "Success"
	MatchStateAlways  MatchState = "Always"
)

type MatrixEnv

type MatrixEnv map[string][]string

MatrixEnv is for matrix work

type Pipeline

type Pipeline struct {
	ID           bson.ObjectId `bson:"_id,omitempty"`
	Title        string        `bson:"title,omitempty"`
	Description  string        `bson:"description,omitempty"`
	WorkSpace    string        `bson:"workspace,omitempty"`
	StorageClass string        `bson:"storageClass,omitempty"`
	StorageSize  string        `bson:"storageSize,omitempty"`
	Trigger      TriggerConfig `bson:"trigger,omitempty"` // manual trigger default
	TaskGroups   []TaskGroup   `bson:"taskgroups,omitempty"`
	Services     []Task        `bson:"services,omitempty"`
	Matrix       MatrixEnv     `bson:"matrix,omitempty"`
	Created      time.Time     `bson:"created"`
	Updated      time.Time     `bson:"updated"`
	Timeout      int           `bson:"timeout,omitempty"` // timeout in minutes with default value
}

Pipeline represent pipeline config

func (*Pipeline) ValidAndSetDefault

func (pipe *Pipeline) ValidAndSetDefault(config *GeneralBuildingConfig) (err error)

ValidAndSetDefault check config param valid and set default

type Plugin

type Plugin struct {
	ID          bson.ObjectId `bson:"_id"`
	Type        string        `bson:"type" index:"+name,unique"`
	Name        string        `bson:"name"  index:"unique"`
	Description string        `bson:"description,omitempty"`
	Version     string        `bson:"version"`
	Path        string        `bson:"url"`
	Constraint  *Constraint   `bson:"constraint"`            // default constraint
	Schema      interface{}   `bson:"schema,omitempty"`      // for pluginConfig setting
	Credentials []string      `bson:"credentials,omitempty"` // credential needed
	Commands    bool          `bson:"commands,omitempty"`    // allow arbitrary commands
	Args        bool          `bson:"args,omitempty"`        // allow arbitrary args
	Updated     time.Time     `bson:"updated,omitempty"`
}

Plugin for build process

func (*Plugin) Valid

func (p *Plugin) Valid() (err error)

Valid Valid plugin input

func (*Plugin) ValidDoc

func (p *Plugin) ValidDoc(document interface{}) (ret bool, errDetails []string)

ValidDoc valid input document json with schema

type Resource

type Resource struct {
	CPU    string
	Memory string
}

Resource cpu/memory

type StateDetail

type StateDetail string

StateDetail is status detail of build or step state

const (
	StateCompleteDetailFailed   StateDetail = "failed"
	StateCompleteDetailCanceled StateDetail = "canceled"
	StateCompleteDetailSkipped  StateDetail = "skipped"
	StateCompleteDetailSuccess  StateDetail = "success"
)

StateDetail types

type StepState

type StepState string

StepState is state of a build step

const (
	StepStatePending  StepState = "pending"
	StepStateRunning  StepState = "running"
	StepStateComplete StepState = "complete"
)

StepState type

type StepStatus

type StepStatus struct {
	State       StepState
	StateDetail StateDetail
	Message     string
}

StepStatus represent building step status

type Task

type Task struct {
	Title       string                 `bson:"title,omitempty"`
	Plugin      string                 `bson:"plugin,omitempty"`
	Environment map[string]interface{} `bson:"environment,omitempty"` // plugin config -> environment
	Command     []string               `bson:"command,omitempty"`
	Privileged  bool                   `bson:"privileged,omitempty"`
	Args        []string               `bson:"args,omitempty"`
	PullPolicy  string                 `bson:"pullPolicy,omitempty"`
	Ports       []int                  `bson:"port,omitempty"` // for service
	// Timeout     int               `bson:"timeout,omitempty"` // timeout in minutes with default value
	// key -> path
	Credentials map[string]string `bson:"credentials,omitempty"`
}

Task -> single container

func (*Task) ValidAndSetDefault

func (w *Task) ValidAndSetDefault(config *GeneralBuildingConfig) (err error)

ValidAndSetDefault check task param valid and set default

type TaskGroup

type TaskGroup struct {
	Title      string      `bson:"title,omitempty"`
	Label      string      `bson:"label,omitempty"`
	PreTasks   []Task      `bson:"pretasks,omitempty"`
	Tasks      []Task      `bson:"tasks,omitempty"`
	Constraint *Constraint `bson:"constraint,omitempty"`
	Timeout    int         `bson:"timeout,omitempty"` // timeout in minutes with default value
}

TaskGroup -> job -> pod -> onestep

func (*TaskGroup) ValidAndSetDefault

func (g *TaskGroup) ValidAndSetDefault(config *GeneralBuildingConfig) (err error)

ValidAndSetDefault check config param valid and set default

type Trigger

type Trigger interface {
}

Trigger is trigger params in a building

type TriggerConfig

type TriggerConfig struct {
	Cron    *CronTrigger
	Mannual *ManualTrigger
	WebHook *WebhookTrigger
}

TriggerConfig is trigger config in pipeline

type TriggerConfigTemplate

type TriggerConfigTemplate struct {
	Type   string `bson:"type,omitempty"`
	Schema string `bson:"schema,omitempty"`
}

TriggerConfigTemplate is trigger setting template

type WebhookTrigger

type WebhookTrigger struct {
	Repo     string
	Event    string
	Branch   string
	CommitID string
	Comment  string
	Author   string
}

WebhookTrigger ..

type WorkEnv

type WorkEnv struct {
	Trigger    Trigger
	PrevStatus StepStatus
}

WorkEnv will be inject to step environment

type WorkStep

type WorkStep struct {
	Title    string       `bson:"title,omitempty"`
	StepNo   int          `bson:"stepno,omitempty"`
	Status   StepStatus   `bson:"status,omitempty"`
	Started  time.Time    `bson:"started"`
	Finished time.Time    `bson:"finished"`
	WorkEnv  WorkEnv      `bson:"workenv"`
	Config   *TaskGroup   `bson:"-" json:"-"`
	K8sjob   *batchv1.Job `bson:"job,omitempty" json:"job,omitempty"`
}

WorkStep is a step during a Build

Jump to

Keyboard shortcuts

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