Documentation
¶
Index ¶
- Constants
- Variables
- func BytesSize(size float64) string
- func CustomSize(format string, size float64, base float64, _map []string) string
- func IsAllCloudsBusyErr(errs error) bool
- func RegisterConstructor(kind string, cc Constructor)
- type Cloud
- type CloudDocker
- type CloudKubernetes
- type CloudProvider
- type CloudType
- type Constructor
- type Controller
- func (cc *Controller) AddClouds(clouds ...Cloud) error
- func (cc *Controller) DeleteCloud(name string)
- func (cc *Controller) GetCloud(name string) (CloudProvider, bool)
- func (cc *Controller) LoadWorker(info WorkerInfo) (Worker, error)
- func (cc *Controller) Provision(id string, opts WorkerOptions) (Worker, error)
- func (cc *Controller) Resources() (map[string]*Resource, error)
- type DockerCloud
- func (cloud *DockerCloud) CanProvision(need Quota) (bool, error)
- func (cloud *DockerCloud) Client() *apiclient.Client
- func (cloud *DockerCloud) GetCloud() Cloud
- func (cloud *DockerCloud) Kind() string
- func (cloud *DockerCloud) LoadWorker(info WorkerInfo) (Worker, error)
- func (cloud *DockerCloud) Name() string
- func (cloud *DockerCloud) Ping() error
- func (cloud *DockerCloud) Provision(id string, wopts WorkerOptions) (Worker, error)
- func (cloud *DockerCloud) Resource() (*Resource, error)
- type DockerWorker
- type ErrCloudProvision
- type K8SCloud
- func (cloud *K8SCloud) CanProvision(quota Quota) (bool, error)
- func (cloud *K8SCloud) Client() *kubernetes.Clientset
- func (cloud *K8SCloud) GetCloud() Cloud
- func (cloud *K8SCloud) Kind() string
- func (cloud *K8SCloud) LoadWorker(info WorkerInfo) (Worker, error)
- func (cloud *K8SCloud) Name() string
- func (cloud *K8SCloud) Ping() error
- func (cloud *K8SCloud) Provision(id string, wopts WorkerOptions) (Worker, error)
- func (cloud *K8SCloud) Resource() (*Resource, error)
- type K8SPodWorker
- type Options
- type Quantity
- type Quota
- type Resource
- type Worker
- type WorkerEnvs
- type WorkerInfo
- type WorkerOptions
Constants ¶
const ( // KindDockerCloud ... KindDockerCloud = "docker" // KindK8SCloud ... KindK8SCloud = "kubernetes" )
const ( // ResourceCPU in cores. (500m = .5 cores) ResourceCPU = "cpu" // ResourceMemory in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) ResourceMemory = "memory" // ResourceRequestsCPU CPU request, in cores. (500m = .5 cores) ResourceRequestsCPU = "requests.cpu" // ResourceRequestsMemory Memory request, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) ResourceRequestsMemory = "requests.memory" // ResourceLimitsCPU CPU limit, in cores. (500m = .5 cores) ResourceLimitsCPU = "limits.cpu" // ResourceLimitsMemory Memory limit, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) ResourceLimitsMemory = "limits.memory" )
const ( // WorkerEventID is special WorkerEventID = "WORKER_EVENTID" CycloneServer = "CYCLONE_SERVER" ConsoleWebEndpoint = "CONSOLE_WEB_ENDPOINT" // CallbackURL ... CallbackURL = "CALLBACK_URL" RegistryLocation = "REGISTRY_LOCATION" RegistryUsername = "REGISTRY_USERNAME" RegistryPassword = "REGISTRY_PASSWORD" WorkerImage = "WORKER_IMAGE" GithubClient = "GITHUB_CLIENT" GithubSecret = "GITHUB_SECRET" GitlabURL = "GITLAB_URL" GitlabClient = "GITLAB_CLIENT" GitlabSecret = "GITLAB_SECRET" LogServer = "LOG_SERVER" LimitMemory = "LIMIT_MEMORY" LimitCPU = "LIMIT_CPU" RequestMemory = "REQUEST_MEMORY" RequestCPU = "REQUEST_CPU" WorkingDir = "/root/code" )
env
const ( // WorkerTimeout ... WorkerTimeout = 2 * time.Hour )
Variables ¶
var ( // Debug ... Debug = false // CloudFactory ... CloudFactory = register.NewRegister() )
var ( // ZeroQuantity ... ZeroQuantity = NewDecimalQuantity(0) // ZeroQuota ... ZeroQuota = Quota{ ResourceLimitsCPU: ZeroQuantity, ResourceLimitsMemory: ZeroQuantity, } // DefaultLimitCPU 1000m = 1 core = 1000 * 100 * 100 DefaultLimitCPU = MustParseCPU(1) // DefaultLimitMemory 1G = 1024MiB = 1024 * 1024 * 1024 DefaultLimitMemory = NewBinaryQuantity(1024 * 1024 * 1024) // DefaultRequestCPU 500m = 0.5 core = 500 * 100 * 100 DefaultRequestCPU = MustParseCPU(0.5) // DefaultRequestMemory 500Mi = 500MiB = 500 * 1024 * 1024 DefaultRequestMemory = NewBinaryQuantity(500 * 1024 * 1024) // DefaultQuota ... DefaultQuota = Quota{ ResourceLimitsCPU: DefaultLimitCPU, ResourceLimitsMemory: DefaultLimitMemory, ResourceRequestsCPU: DefaultRequestCPU, ResourceRequestsMemory: DefaultRequestMemory, } )
var ( // DefaultCloudPingTimeout ... DefaultCloudPingTimeout = time.Duration(5 * time.Second) )
var ( // ErrNoEnoughResource occurs when clouds have no enough resource to provison as worker ErrNoEnoughResource = errors.New("worker required resources are out of quota limit") )
Functions ¶
func BytesSize ¶
BytesSize returns a human-readable size in bytes, kibibytes, mebibytes, gibibytes, or tebibytes (eg. "44kiB", "17MiB").
func CustomSize ¶
CustomSize returns a human-readable approximation of a size using custom format.
func IsAllCloudsBusyErr ¶
IsAllCloudsBusyErr check whether all cloud is too busy to provision a worker
func RegisterConstructor ¶
func RegisterConstructor(kind string, cc Constructor)
RegisterConstructor ...
Types ¶
type Cloud ¶
type Cloud struct {
ID string `bson:"_id,omitempty" json:"id,omitempty"`
Type CloudType `bson:"type,omitempty" json:"type,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
Insecure bool `json:"insecure,omitempty" bson:"insecure,omitempty"`
Docker *CloudDocker `json:"docker,omitempty" bson:"docker,omitempty"`
Kubernetes *CloudKubernetes `json:"kubernetes,omitempty" bson:"kubernetes,omitempty"`
}
Cloud represents clouds for workers. TODO (robin) Move this to pkg/api
type CloudDocker ¶ added in v0.5.0
type CloudKubernetes ¶ added in v0.5.0
type CloudProvider ¶ added in v0.5.0
type CloudProvider interface {
// Name returns cloud name
Name() string
// Kind returns cloud type, such as kubernetes
Kind() string
// Ping returns nil if cloud is accessible
Ping() error
// Resource returns the limit and used quotas of the cloud
Resource() (*Resource, error)
// CanProvision returns true if the cloud can provision a worker meetting the quota
CanProvision(need Quota) (bool, error)
// Provision returns a worker if the cloud can provison,
// but worker is not running. you should call worker.Do() to do the work
// Provision should call ConProvision firstly
Provision(id string, opts WorkerOptions) (Worker, error)
// LoadWorker rebuilds a worker from worker info
LoadWorker(WorkerInfo) (Worker, error)
//
GetCloud() Cloud
}
CloudProvider defines a cloud provider which provision workers for cyclone
func NewDockerCloud ¶
func NewDockerCloud(opts Options) (CloudProvider, error)
NewDockerCloud returns a new Cloud from CloudOption
func NewK8SCloudInCluster ¶
func NewK8SCloudInCluster(opts Options) (CloudProvider, error)
NewK8SCloudInCluster returns a cloud object which uses the service account kubernetes gives to pods
type CloudType ¶ added in v0.5.0
type CloudType string
CloudType represents cloud type, supports Docker and Kubernetes.
type Controller ¶
type Controller struct {
Clouds map[string]CloudProvider
// contains filtered or unexported fields
}
Controller ... TODO cloud controller sync all cloud infomation
func (*Controller) AddClouds ¶
func (cc *Controller) AddClouds(clouds ...Cloud) error
AddClouds creates clouds from CloudOptions and cache it
func (*Controller) DeleteCloud ¶
func (cc *Controller) DeleteCloud(name string)
DeleteCloud returns a cloud by cloud name
func (*Controller) GetCloud ¶
func (cc *Controller) GetCloud(name string) (CloudProvider, bool)
GetCloud returns a cloud by cloud name
func (*Controller) LoadWorker ¶
func (cc *Controller) LoadWorker(info WorkerInfo) (Worker, error)
LoadWorker ...
func (*Controller) Provision ¶
func (cc *Controller) Provision(id string, opts WorkerOptions) (Worker, error)
Provision asks all Clouds in CloudController to provision a worker you should compute needed quota by yourself,
type DockerCloud ¶
type DockerCloud struct {
// contains filtered or unexported fields
}
DockerCloud is a docker cloud
func (*DockerCloud) CanProvision ¶
func (cloud *DockerCloud) CanProvision(need Quota) (bool, error)
CanProvision returns true if the cloud can provision a worker meetting the quota
func (*DockerCloud) Client ¶
func (cloud *DockerCloud) Client() *apiclient.Client
Client returns docker client
func (*DockerCloud) GetCloud ¶ added in v0.5.0
func (cloud *DockerCloud) GetCloud() Cloud
GetCloud ...
func (*DockerCloud) LoadWorker ¶
func (cloud *DockerCloud) LoadWorker(info WorkerInfo) (Worker, error)
LoadWorker rebuilds a worker from worker info
func (*DockerCloud) Ping ¶
func (cloud *DockerCloud) Ping() error
Ping returns nil if cloud is accessible
func (*DockerCloud) Provision ¶
func (cloud *DockerCloud) Provision(id string, wopts WorkerOptions) (Worker, error)
Provision returns a worker if the cloud can provison
func (*DockerCloud) Resource ¶
func (cloud *DockerCloud) Resource() (*Resource, error)
Resource returns the limit and used quotas of the cloud
type DockerWorker ¶
type DockerWorker struct {
// contains filtered or unexported fields
}
DockerWorker ...
func (*DockerWorker) Do ¶
func (worker *DockerWorker) Do() error
Do starts the worker and do the work
func (*DockerWorker) GetWorkerInfo ¶
func (worker *DockerWorker) GetWorkerInfo() WorkerInfo
GetWorkerInfo returns worker's infomation
func (*DockerWorker) IsTimeout ¶
func (worker *DockerWorker) IsTimeout() (bool, time.Duration)
IsTimeout returns true if worker is timeout and returns the time left until it is due
func (*DockerWorker) Terminate ¶
func (worker *DockerWorker) Terminate() error
Terminate terminates the worker and destroy it
type ErrCloudProvision ¶
type ErrCloudProvision struct {
// contains filtered or unexported fields
}
ErrCloudProvision contains all clouds provision errors
func NewErrCloudProvision ¶
func NewErrCloudProvision() *ErrCloudProvision
NewErrCloudProvision return a new CloudProvisionErr
func (*ErrCloudProvision) Add ¶
func (cpe *ErrCloudProvision) Add(name string, err error)
Add adds an error to CloudProvisionErr
func (*ErrCloudProvision) Err ¶
func (cpe *ErrCloudProvision) Err() error
Err returns nil if CloudProvisionErr contains 0 error
func (*ErrCloudProvision) Error ¶
func (cpe *ErrCloudProvision) Error() string
type K8SCloud ¶
type K8SCloud struct {
// contains filtered or unexported fields
}
K8SCloud ...
func (*K8SCloud) CanProvision ¶
CanProvision returns true if the cloud can provision a worker meetting the quota
func (*K8SCloud) Client ¶
func (cloud *K8SCloud) Client() *kubernetes.Clientset
Client returns k8s clientset
func (*K8SCloud) LoadWorker ¶
func (cloud *K8SCloud) LoadWorker(info WorkerInfo) (Worker, error)
LoadWorker rebuilds a worker from worker info
type K8SPodWorker ¶
type K8SPodWorker struct {
*K8SCloud
// contains filtered or unexported fields
}
K8SPodWorker ...
func (*K8SPodWorker) Do ¶
func (worker *K8SPodWorker) Do() error
Do starts the worker and do the work
func (*K8SPodWorker) GetWorkerInfo ¶
func (worker *K8SPodWorker) GetWorkerInfo() WorkerInfo
GetWorkerInfo returns worker's infomation
func (*K8SPodWorker) IsTimeout ¶
func (worker *K8SPodWorker) IsTimeout() (bool, time.Duration)
IsTimeout returns true if worker is timeout and returns the time left until it is due
func (*K8SPodWorker) Terminate ¶
func (worker *K8SPodWorker) Terminate() error
Terminate terminates the worker and destroy it
type Options ¶
type Options struct {
// mongodb id
ID string `bson:"_id,omitempty" json:"-"`
// common options
Kind string `json:"kind,omitempty" bson:"kind,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
Host string `json:"host,omitempty" bson:"host,omitempty"`
Insecure bool `json:"insecure,omitempty" bson:"insecure,omitempty"`
// docker cloud
DockerCertPath string `json:"dockerCertPath,omitempty" bson:"dockerCertPath,omitempty"`
// k8s cloud
K8SInCluster bool `json:"k8sInCluster,omitempty" bson:"k8sInCluster,omitempty"`
K8SNamespace string `json:"k8sNamespace,omitempty" bson:"k8sNamespace,omitempty"`
K8SBearerToken string `json:"k8sBearerToken,omitempty" bson:"k8sBearerToken,omitempty"`
}
Options is options for all kinds of clouds
type Quantity ¶
Quantity warps resource.Quantity to implement cli.Generic interface
func MustParseCPU ¶
MustParseCPU turns the given float(in cores, such as 1.5 cores) into a quantity or panics; for tests or others cases where you know the value is valid.
func MustParseMemory ¶
MustParseMemory turns the given float(in Bytes, such as 500*1024*1024 bytes) into a quantity or panics; for tests or others cases where you know the value is valid.
func NewBinaryQuantity ¶
NewBinaryQuantity creates a new Quantity with resource.BinarySI Format
func NewDecimalQuantity ¶
NewDecimalQuantity creates a new Quantity with resource.DecimalSI Format
func NewQuantity ¶
NewQuantity creates a new Quantity
func NewQuantityFor ¶
NewQuantityFor reates a new Quantity from resource.Quantity
func (Quantity) DeepCopy ¶
DeepCopy returns a deep-copy of the Quantity value. Note that the method receiver is a value, so we can mutate it in-place and return it.
type Quota ¶
Quota ...
func (Quota) ToDockerQuota ¶
ToDockerQuota converts Quota to docker resource quota type
func (Quota) ToK8SQuota ¶
func (q Quota) ToK8SQuota() apiv1.ResourceRequirements
ToK8SQuota converts Quota to k8s resource quota type
type Resource ¶
type Resource struct {
Limit Quota `json:"limit,omitempty" bson:"limit,omitempty"`
Used Quota `json:"used,omitempty" bson:"used,omitempty"`
}
Resource describes cloud resource include limit and used quota
type Worker ¶
type Worker interface {
// Do starts the worker and does the work
Do() error
// GetWorkerInfo returns worker's infomation
GetWorkerInfo() WorkerInfo
// IsTimeout returns true if worker is timeout
// and returns the time left until it is due
IsTimeout() (bool, time.Duration)
// Terminate terminates the worker and destroy it
Terminate() error
}
Worker is the truly excutor to deal with build jobs
type WorkerEnvs ¶
type WorkerEnvs struct {
// for worker env
CycloneServer string
ConsoleWebEndpoint string
// Registry
RegistryLocation string `json:"registryLocation,omitempty"`
RegistryUsername string `json:"registryUsername,omitempty"`
RegistryPassword string `json:"registryPassword,omitempty"`
// github
GithubClient string
GithubSecret string
// gitlab
GitlabURL string
GitlabClient string
GitlabSecret string
LogServer string
WorkerImage string
}
WorkerEnvs ...
func (*WorkerEnvs) AddFlags ¶
func (env *WorkerEnvs) AddFlags(app *cli.App)
AddFlags adds flags for a specific APIServer to the specified cli.app
type WorkerInfo ¶
type WorkerInfo struct {
CloudName string `json:"cloudName,omitempty" bson:"cloudName,omitempty"`
CloudKind string `json:"cloudKind,omitempty" bson:"cloudKind,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
CreateTime time.Time `json:"createTime,omitempty" bson:"createTime,omitempty"`
DueTime time.Time `json:"dueTime,omitempty" bson:"dueTime,omitempty"`
// for k8s
PodName string `json:"podName,omitempty" bson:"podName,omitempty"`
Namespace string `json:"namespace,omitempty" bson:"namespace,omitempty"`
// for docker
ContainerID string `json:"containerID,omitempty" bson:"containerID,omitempty"`
}
WorkerInfo ...
type WorkerOptions ¶
type WorkerOptions struct {
WorkerEnvs *WorkerEnvs
Quota Quota
// Namespace represents the k8s namespace where to create worker, only works for k8s cloud provider.
Namespace string
// CacheVolume represents the volume to cache dependency for worker.
CacheVolume string
// MountPath represents the mount path for the cache volume.
MountPath string
}
WorkerOptions contains the options for workers creation
func NewWorkerOptions ¶
func NewWorkerOptions() *WorkerOptions
NewWorkerOptions creates a new WorkerOptions with default value
func (*WorkerOptions) AddFlags ¶
func (opts *WorkerOptions) AddFlags(app *cli.App)
AddFlags adds flags for a specific APIServer to the specified cli.app
func (WorkerOptions) DeepCopy ¶
func (opts WorkerOptions) DeepCopy() WorkerOptions
DeepCopy returns a deep-copy of the WorkerOptions value. Note that the method receiver is a value, so we can mutate it in-place and return it.