core

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WorkflowEntity2WorkflowCR

func WorkflowEntity2WorkflowCR(entity *WorkflowEntity) (*v1alpha1.Workflow, error)

Types

type ConditionalBranch

type ConditionalBranch struct {
	NodeNameWithTemplate `json:",inline,omitempty"`
	Expression           string `json:"expression,omitempty"`
}

type Event

type Event struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	ObjectID  string    `gorm:"index:object_id" json:"object_id"`
	CreatedAt time.Time `json:"created_at"`
	Namespace string    `json:"namespace"`
	Name      string    `json:"name"`
	Kind      string    `json:"kind"`
	Type      string    `json:"type"`
	Reason    string    `json:"reason"`
	Message   string    `json:"message"`
}

type EventStore

type EventStore interface {
	// List returns an event list from the datastore.
	List(context.Context) ([]*Event, error)

	// ListByUID returns an event list by the UID.
	ListByUID(context.Context, string) ([]*Event, error)

	// ListByUIDs returns an event list by the UID list.
	ListByUIDs(context.Context, []string) ([]*Event, error)

	// ListByExperiment returns an event list by the namespace, name, or kind.
	ListByExperiment(context context.Context, namespace string, name string, kind string) ([]*Event, error)

	ListByFilter(context.Context, Filter) ([]*Event, error)

	// Find returns an event by ID.
	Find(context.Context, uint) (*Event, error)

	// Create persists a new event to the datastore.
	Create(context.Context, *Event) error

	// DeleteByUID deletes events by the UID.
	DeleteByUID(context.Context, string) error

	// DeleteByUIDs deletes events by the UID list.
	DeleteByUIDs(context.Context, []string) error

	// DeleteByTime deletes events within the specified time interval.
	DeleteByTime(context.Context, string, string) error

	// DeleteByDuration selete events that exceed duration.
	DeleteByDuration(context.Context, time.Duration) error
}

EventStore defines operations for working with events.

type Experiment

type Experiment struct {
	ExperimentMeta
	Experiment string `gorm:"size:4096"` // JSON string
}

Experiment represents an experiment instance. Use in db.

type ExperimentMeta

type ExperimentMeta struct {
	gorm.Model
	UID        string    `gorm:"index:uid" json:"uid"`
	Kind       string    `json:"kind"`
	Name       string    `json:"name"`
	Namespace  string    `json:"namespace"`
	Action     string    `json:"action"`
	StartTime  time.Time `json:"start_time"`
	FinishTime time.Time `json:"finish_time"`
	Archived   bool      `json:"archived"`
}

ExperimentMeta defines the metadata of an experiment. Use in db.

type ExperimentStore

type ExperimentStore interface {
	// ListMeta returns experiment metadata list from the datastore.
	ListMeta(ctx context.Context, kind, namespace, name string, archived bool) ([]*ExperimentMeta, error)

	// FindByUID returns an experiment by UID.
	FindByUID(ctx context.Context, UID string) (*Experiment, error)

	// FindManagedByNamespaceName returns experiment list which are managed by schedule or workflow.
	FindManagedByNamespaceName(ctx context.Context, namespace, name string) ([]*Experiment, error)

	// FindMetaByUID returns an experiment metadata by UID.
	FindMetaByUID(context.Context, string) (*ExperimentMeta, error)

	// Set saves the experiment to datastore.
	Set(context.Context, *Experiment) error

	// Archive archives experiments which "archived" field is false.
	Archive(ctx context.Context, namespace, name string) error

	// Delete deletes the archive from the datastore.
	Delete(context.Context, *Experiment) error

	// DeleteByFinishTime deletes archives which time difference is greater than the given time from FinishTime.
	DeleteByFinishTime(context.Context, time.Duration) error

	// DeleteByUIDs deletes archives by the uid list.
	DeleteByUIDs(context.Context, []string) error

	// DeleteIncompleteExperiments deletes all incomplete experiments.
	// If the chaos-dashboard was restarted and the experiment is completed during the restart,
	// which means the experiment would never save the finish_time.
	// DeleteIncompleteExperiments can be used to delete all incomplete experiments to avoid this case.
	DeleteIncompleteExperiments(context.Context) error
}

ExperimentStore defines operations for working with experiments.

type Filter

type Filter struct {
	ObjectID  string `json:"object_id"`
	Start     string `json:"start"`
	End       string `json:"end"`
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
	Kind      string `json:"kind"`
	Limit     string `json:"limit"`
}

func (*Filter) ConstructQueryArgs

func (f *Filter) ConstructQueryArgs() (string, []interface{})

type KubeObjectDesc

type KubeObjectDesc struct {
	metav1.TypeMeta
	Meta KubeObjectMeta `json:"metadata"`
	Spec interface{}    `json:"spec"`
}

KubeObjectDesc defines a simple kube object description which uses in apiserver.

type KubeObjectMeta

type KubeObjectMeta struct {
	Namespace   string            `json:"namespace"`
	Name        string            `json:"name"`
	Labels      map[string]string `json:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

KubeObjectMetadata extracts the required fields from metav1.ObjectMeta.

type KubeWorkflowRepository

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

func NewKubeWorkflowRepository

func NewKubeWorkflowRepository(kubeclient client.Client) *KubeWorkflowRepository

func (*KubeWorkflowRepository) Create

func (*KubeWorkflowRepository) Delete

func (it *KubeWorkflowRepository) Delete(ctx context.Context, namespace, name string) error

func (*KubeWorkflowRepository) Get

func (it *KubeWorkflowRepository) Get(ctx context.Context, namespace, name string) (WorkflowDetail, error)

func (*KubeWorkflowRepository) List

func (*KubeWorkflowRepository) ListByNamespace

func (it *KubeWorkflowRepository) ListByNamespace(ctx context.Context, namespace string) ([]WorkflowMeta, error)

func (*KubeWorkflowRepository) Update

func (it *KubeWorkflowRepository) Update(ctx context.Context, namespace, name string, workflow v1alpha1.Workflow) (WorkflowDetail, error)

type Node

type Node struct {
	Name                string                 `json:"name"`
	Type                NodeType               `json:"type"`
	State               NodeState              `json:"state"`
	Serial              []NodeNameWithTemplate `json:"serial,omitempty"`
	Parallel            []NodeNameWithTemplate `json:"parallel,omitempty"`
	ConditionalBranches []ConditionalBranch    `json:"conditional_branches,omitempty"`
	Template            string                 `json:"template"`
	UID                 string                 `json:"uid"`
}

Node defines a single step of a workflow.

type NodeNameWithTemplate

type NodeNameWithTemplate struct {
	Name     string `json:"name,omitempty"`
	Template string `json:"template,omitempty"`
}

type NodeState

type NodeState string
const (
	NodeRunning NodeState = "Running"
	NodeSucceed NodeState = "Succeed"
	NodeFailed  NodeState = "Failed"
)

type NodeType

type NodeType string

NodeType represents the type of a workflow node.

There will be five types can be referred as NodeType: ChaosNode, SerialNode, ParallelNode, SuspendNode, TaskNode.

Const definitions can be found below this type.

const (
	// ChaosNode represents a node will perform a single Chaos Experiment.
	ChaosNode NodeType = "ChaosNode"

	// SerialNode represents a node that will perform continuous templates.
	SerialNode NodeType = "SerialNode"

	// ParallelNode represents a node that will perform parallel templates.
	ParallelNode NodeType = "ParallelNode"

	// SuspendNode represents a node that will perform wait operation.
	SuspendNode NodeType = "SuspendNode"

	// TaskNode represents a node that will perform user-defined task.
	TaskNode NodeType = "TaskNode"
)

type ObjectBase

type ObjectBase struct {
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
	Kind      string `json:"kind"`
	UID       string `json:"uid"`
	Created   string `json:"created_at"`
}

type Schedule

type Schedule struct {
	ScheduleMeta
	Schedule string `gorm:"size:4096"` // JSON string
}

Schedule represents a schedule instance. Use in db.

type ScheduleMeta

type ScheduleMeta struct {
	gorm.Model
	UID        string    `gorm:"index:schedule_uid" json:"uid"`
	Kind       string    `json:"kind"`
	Name       string    `json:"name"`
	Namespace  string    `json:"namespace"`
	Action     string    `json:"action"`
	StartTime  time.Time `json:"start_time"`
	FinishTime time.Time `json:"finish_time"`
	Archived   bool      `json:"archived"`
}

ScheduleMeta defines the metadata of a schedule instance. Use in db.

type ScheduleStore

type ScheduleStore interface {
	// ListMeta returns schedule metadata list from the datastore.
	ListMeta(ctx context.Context, namespace, name string, archived bool) ([]*ScheduleMeta, error)

	// FindByUID returns a schedule by UID.
	FindByUID(ctx context.Context, UID string) (*Schedule, error)

	// FindMetaByUID returns a schedule metadata by UID.
	FindMetaByUID(context.Context, string) (*ScheduleMeta, error)

	// Set saves the schedule to datastore.
	Set(context.Context, *Schedule) error

	// Archive archives schedules which "archived" field is false.
	Archive(ctx context.Context, namespace, name string) error

	// Delete deletes the archive from the datastore.
	Delete(context.Context, *Schedule) error

	// DeleteByFinishTime deletes archives which time difference is greater than the given time from FinishTime.
	DeleteByFinishTime(context.Context, time.Duration) error

	// DeleteByUIDs deletes archives by the uid list.
	DeleteByUIDs(context.Context, []string) error

	// DeleteIncompleteSchedules deletes all incomplete schedules.
	// If the chaos-dashboard was restarted and the schedule is completed during the restart,
	// which means the schedule would never save the finish_time.
	// DeleteIncompleteSchedules can be used to delete all incomplete schedules to avoid this case.
	DeleteIncompleteSchedules(context.Context) error
}

ScheduleStore defines operations for working with schedules.

type Topology

type Topology struct {
	Nodes []Node `json:"nodes"`
}

Topology describes the process of a workflow.

type WorkflowDetail

type WorkflowDetail struct {
	WorkflowMeta `json:",inline"`
	Topology     Topology       `json:"topology"`
	KubeObject   KubeObjectDesc `json:"kube_object,omitempty"`
}

func WorkflowEntity2WorkflowDetail

func WorkflowEntity2WorkflowDetail(entity *WorkflowEntity) (*WorkflowDetail, error)

type WorkflowEntity

type WorkflowEntity struct {
	WorkflowMeta
	Workflow string `gorm:"type:text;size:32768"`
}

WorkflowEntity is the gorm entity, refers to a row of data

func WorkflowCR2WorkflowEntity

func WorkflowCR2WorkflowEntity(workflow *v1alpha1.Workflow) (*WorkflowEntity, error)

type WorkflowMeta

type WorkflowMeta struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	UID       string    `gorm:"index:workflow_uid" json:"uid"`
	Namespace string    `json:"namespace"`
	Name      string    `json:"name"`
	Entry     string    `json:"entry"` // the entry node name
	CreatedAt time.Time `json:"created_at"`
	// FinishTime represents the time when the workflow was deleted from Kubernetes.
	FinishTime time.Time `json:"finish_time"`
	// EndTime represents the time when the workflow completed all steps.
	EndTime  string         `json:"end_time"`
	Status   WorkflowStatus `json:"status,omitempty"`
	Archived bool           `json:"-"`
}

WorkflowMeta defines the root structure of a workflow.

type WorkflowRepository

type WorkflowRepository interface {
	List(ctx context.Context) ([]WorkflowMeta, error)
	ListByNamespace(ctx context.Context, namespace string) ([]WorkflowMeta, error)
	Create(ctx context.Context, workflow v1alpha1.Workflow) (WorkflowDetail, error)
	Get(ctx context.Context, namespace, name string) (WorkflowDetail, error)
	Delete(ctx context.Context, namespace, name string) error
	Update(ctx context.Context, namespace, name string, workflow v1alpha1.Workflow) (WorkflowDetail, error)
}

type WorkflowStatus

type WorkflowStatus string
const (
	WorkflowRunning WorkflowStatus = "running"
	WorkflowSucceed WorkflowStatus = "finished"
	WorkflowFailed  WorkflowStatus = "failed"
	WorkflowUnknown WorkflowStatus = "unknown"
)

type WorkflowStore

type WorkflowStore interface {
	List(ctx context.Context, namespace, name string, archived bool) ([]*WorkflowEntity, error)
	ListMeta(ctx context.Context, namespace, name string, archived bool) ([]*WorkflowMeta, error)
	FindByID(ctx context.Context, ID uint) (*WorkflowEntity, error)
	FindByUID(ctx context.Context, UID string) (*WorkflowEntity, error)
	FindMetaByUID(ctx context.Context, UID string) (*WorkflowMeta, error)
	Save(ctx context.Context, entity *WorkflowEntity) error
	DeleteByUID(ctx context.Context, UID string) error
	DeleteByUIDs(ctx context.Context, UIDs []string) error
	DeleteByFinishTime(ctx context.Context, ttl time.Duration) error
	MarkAsArchived(ctx context.Context, namespace, name string) error
	MarkAsArchivedWithUID(ctx context.Context, UID string) error
}

The WorkflowStore of workflow is not so similar with others store.

Jump to

Keyboard shortcuts

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