github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/cluster/cluster.go (about)

     1  package cluster
     2  
     3  import (
     4  	"context"
     5  
     6  	enginetypes "github.com/projecteru2/core/engine/types"
     7  	"github.com/projecteru2/core/types"
     8  )
     9  
    10  const (
    11  	// Gitlab for gitlab
    12  	Gitlab = "gitlab"
    13  	// Github for github
    14  	Github = "github"
    15  	// CPUPeriodBase for cpu period base
    16  	CPUPeriodBase = 100000
    17  	// ERUMark mark workload controlled by eru
    18  	ERUMark = "ERU"
    19  	// LabelMeta store publish and health things
    20  	LabelMeta = "ERU_META"
    21  	// LabelCoreID is used to label a container with its identifier
    22  	LabelCoreID = "eru.coreid"
    23  	// LabelNodeName is used to label a container with the nodename
    24  	LabelNodeName = "eru.nodename"
    25  	// WorkloadStop for stop workload
    26  	WorkloadStop = "stop"
    27  	// WorkloadStart for start workload
    28  	WorkloadStart = "start"
    29  	// WorkloadRestart for restart workload
    30  	WorkloadRestart = "restart"
    31  	// WorkloadSuspend for suspending workload
    32  	WorkloadSuspend = "suspend"
    33  	// WorkloadResume for resuming workload
    34  	WorkloadResume = "resume"
    35  	// WorkloadLock for lock workload
    36  	WorkloadLock = "clock_%s"
    37  	// PodLock for lock pod
    38  	PodLock = "plock_%s"
    39  	// NodeOperationLock for lock node operation
    40  	NodeOperationLock = "cnode_op_%s_%s"
    41  )
    42  
    43  // Cluster define all interface
    44  type Cluster interface {
    45  	// meta service
    46  	WatchServiceStatus(context.Context) (<-chan types.ServiceStatus, error)
    47  	// meta networks
    48  	ListNetworks(ctx context.Context, podname string, driver string) ([]*enginetypes.Network, error)
    49  	ConnectNetwork(ctx context.Context, network, target, ipv4, ipv6 string) ([]string, error)
    50  	DisconnectNetwork(ctx context.Context, network, target string, force bool) error
    51  	// meta pod
    52  	AddPod(ctx context.Context, podname, desc string) (*types.Pod, error)
    53  	RemovePod(ctx context.Context, podname string) error
    54  	GetPod(ctx context.Context, podname string) (*types.Pod, error)
    55  	ListPods(ctx context.Context) ([]*types.Pod, error)
    56  	// pod resource
    57  	PodResource(ctx context.Context, podname string) (chan *types.NodeResourceInfo, error)
    58  	// meta node
    59  	AddNode(context.Context, *types.AddNodeOptions) (*types.Node, error)
    60  	RemoveNode(ctx context.Context, nodename string) error
    61  	ListPodNodes(context.Context, *types.ListNodesOptions) (<-chan *types.Node, error)
    62  	GetNode(ctx context.Context, nodename string) (*types.Node, error)
    63  	GetNodeEngineInfo(ctx context.Context, nodename string) (*enginetypes.Info, error)
    64  	SetNode(ctx context.Context, opts *types.SetNodeOptions) (*types.Node, error)
    65  	SetNodeStatus(ctx context.Context, nodename string, ttl int64) error
    66  	GetNodeStatus(ctx context.Context, nodename string) (*types.NodeStatus, error)
    67  	NodeStatusStream(ctx context.Context) chan *types.NodeStatus
    68  	// node resource
    69  	NodeResource(ctx context.Context, nodename string, fix bool) (*types.NodeResourceInfo, error)
    70  	// calculate capacity
    71  	CalculateCapacity(context.Context, *types.DeployOptions) (*types.CapacityMessage, error)
    72  	// meta workloads
    73  	GetWorkload(ctx context.Context, id string) (*types.Workload, error)
    74  	GetWorkloads(ctx context.Context, IDs []string) ([]*types.Workload, error)
    75  	ListWorkloads(ctx context.Context, opts *types.ListWorkloadsOptions) ([]*types.Workload, error)
    76  	ListNodeWorkloads(ctx context.Context, nodename string, labels map[string]string) ([]*types.Workload, error)
    77  	GetWorkloadsStatus(ctx context.Context, IDs []string) ([]*types.StatusMeta, error)
    78  	SetWorkloadsStatus(ctx context.Context, status []*types.StatusMeta, ttls map[string]int64) ([]*types.StatusMeta, error)
    79  	WorkloadStatusStream(ctx context.Context, appname, entrypoint, nodename string, labels map[string]string) chan *types.WorkloadStatus
    80  	// file methods
    81  	Copy(ctx context.Context, opts *types.CopyOptions) (chan *types.CopyMessage, error)
    82  	Send(ctx context.Context, opts *types.SendOptions) (chan *types.SendMessage, error)
    83  	SendLargeFile(ctx context.Context, opts chan *types.SendLargeFileOptions) chan *types.SendMessage
    84  	// image methods
    85  	BuildImage(ctx context.Context, opts *types.BuildOptions) (chan *types.BuildImageMessage, error)
    86  	CacheImage(ctx context.Context, opts *types.ImageOptions) (chan *types.CacheImageMessage, error)
    87  	RemoveImage(ctx context.Context, opts *types.ImageOptions) (chan *types.RemoveImageMessage, error)
    88  	ListImage(ctx context.Context, opts *types.ImageOptions) (chan *types.ListImageMessage, error)
    89  	// workload methods
    90  	CreateWorkload(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateWorkloadMessage, error)
    91  	ReplaceWorkload(ctx context.Context, opts *types.ReplaceOptions) (chan *types.ReplaceWorkloadMessage, error)
    92  	RemoveWorkload(ctx context.Context, IDs []string, force bool) (chan *types.RemoveWorkloadMessage, error)
    93  	RemoveWorkloadSync(ctx context.Context, IDs []string) error
    94  	DissociateWorkload(ctx context.Context, IDs []string) (chan *types.DissociateWorkloadMessage, error)
    95  	ControlWorkload(ctx context.Context, IDs []string, t string, force bool) (chan *types.ControlWorkloadMessage, error)
    96  	ExecuteWorkload(ctx context.Context, opts *types.ExecuteWorkloadOptions, inCh <-chan []byte) chan *types.AttachWorkloadMessage
    97  	ReallocResource(ctx context.Context, opts *types.ReallocOptions) error
    98  	LogStream(ctx context.Context, opts *types.LogStreamOptions) (chan *types.LogStreamMessage, error)
    99  	RunAndWait(ctx context.Context, opts *types.DeployOptions, inCh <-chan []byte) ([]string, <-chan *types.AttachWorkloadMessage, error)
   100  	RawEngine(ctx context.Context, opts *types.RawEngineOptions) (*types.RawEngineMessage, error)
   101  	// finalizer
   102  	Finalizer()
   103  
   104  	// GetIdentifier returns the identifier for this cluster
   105  	// identifier will be used to label a container, to announce the container belongs to this cluster
   106  	GetIdentifier() string
   107  }