...

Package core

import "github.com/chaos-mesh/chaos-mesh/pkg/dashboard/core"
Overview
Index

Overview ▾

Index ▾

func WorkflowEntity2WorkflowCR(entity *WorkflowEntity) (*v1alpha1.Workflow, error)
type ConditionalBranch
type Event
type EventStore
type Experiment
type ExperimentMeta
type ExperimentStore
type Filter
    func (f *Filter) ConstructQueryArgs() (string, []interface{})
type KubeObjectDesc
type KubeObjectMeta
type KubeWorkflowRepository
    func NewKubeWorkflowRepository(kubeclient client.Client) *KubeWorkflowRepository
    func (it *KubeWorkflowRepository) Create(ctx context.Context, workflow v1alpha1.Workflow) (WorkflowDetail, error)
    func (it *KubeWorkflowRepository) Delete(ctx context.Context, namespace, name string) error
    func (it *KubeWorkflowRepository) Get(ctx context.Context, namespace, name string) (WorkflowDetail, error)
    func (it *KubeWorkflowRepository) List(ctx context.Context) ([]WorkflowMeta, error)
    func (it *KubeWorkflowRepository) ListByNamespace(ctx context.Context, namespace string) ([]WorkflowMeta, error)
    func (it *KubeWorkflowRepository) Update(ctx context.Context, namespace, name string, workflow v1alpha1.Workflow) (WorkflowDetail, error)
type Node
type NodeNameWithTemplate
type NodeState
type NodeType
type ObjectBase
type Schedule
type ScheduleMeta
type ScheduleStore
type Topology
type WorkflowDetail
    func WorkflowEntity2WorkflowDetail(entity *WorkflowEntity) (*WorkflowDetail, error)
type WorkflowEntity
    func WorkflowCR2WorkflowEntity(workflow *v1alpha1.Workflow) (*WorkflowEntity, error)
type WorkflowMeta
type WorkflowRepository
type WorkflowStatus
type WorkflowStore

Package files

common.go event.go experiment.go schedule.go workflow.go

func WorkflowEntity2WorkflowCR

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

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    `gorm:"type:text;size:32768" json:"message"`
}

type EventStore

EventStore defines operations for working with events.

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
}

type Experiment

Experiment represents an experiment instance. Use in db.

type Experiment struct {
    ExperimentMeta
    Experiment string `gorm:"type:text;size:32768"` // JSON string
}

type ExperimentMeta

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

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"`
}

type ExperimentStore

ExperimentStore defines operations for working with experiments.

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
}

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

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

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

type KubeObjectMeta

KubeObjectMetadata extracts the required fields from metav1.ObjectMeta.

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"`
}

type KubeWorkflowRepository

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

func NewKubeWorkflowRepository

func NewKubeWorkflowRepository(kubeclient client.Client) *KubeWorkflowRepository

func (*KubeWorkflowRepository) Create

func (it *KubeWorkflowRepository) Create(ctx context.Context, workflow v1alpha1.Workflow) (WorkflowDetail, error)

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 (it *KubeWorkflowRepository) List(ctx context.Context) ([]WorkflowMeta, error)

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

Node defines a single step of a workflow.

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"`
}

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

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.

type NodeType string
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

Schedule represents a schedule instance. Use in db.

type Schedule struct {
    ScheduleMeta
    Schedule string `gorm:"type:text;size:32768"` // JSON string
}

type ScheduleMeta

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

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"`
}

type ScheduleStore

ScheduleStore defines operations for working with schedules.

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
}

type Topology

Topology describes the process of a workflow.

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

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

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

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

func WorkflowCR2WorkflowEntity

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

type WorkflowMeta

WorkflowMeta defines the root structure of a workflow.

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:"-"`
}

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

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

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
}