var ErrDiffID = cerr.FromErr(errors.New("different IsID"))
var ErrNotFoundID = cerr.NotFound("ID")
var ErrNotFoundSysID = cerr.NotFoundType[SysPID]()
var ErrNotFoundTaskID = cerr.NotFound("TaskID")
var ErrNotFoundTypeTaskConfig = cerr.NotFoundType[TaskConfig]()
var ErrNotPodContainerName = cerr.NotType[PodContainerName]()
var ErrNotTypeSysID = cerr.NotType[SysPID]()
var ErrPodProcessMapNotInit = cerr.NotInit[map[PodContainerName]SysPID]().WrapName("PodContainerNameProcessMap").Err()
var ErrTaskConfigMapNotInit = cerr.NotInit[map[TaskID]TaskConfig]().WrapName("TaskConfigMap").Err()
Assign change some of an Injectable task with its own values. We use it in a case that we use TaskConfig.Data to update an Injectable task.
type Assign interface { Assign(Injectable) error }
ChaosOnPOD stand for the inner process injector for container.
type ChaosOnPOD interface { Injectable Recoverable }
ChaosOnProcessGroup is used for inject a chaos on a linux process group. Fork is used for create a new chaos on child process. Assign is used for update a chaos on child process.
type ChaosOnProcessGroup interface { Fork() (ChaosOnProcessGroup, error) Assign Injectable Recoverable }
Creator init an Injectable with values. We use it in a case that TaskConfig.Data init an Injectable task here.
type Creator interface { New(values interface{}) (Injectable, error) }
Injectable stand for the base behavior of task : inject a process with IsID.
type Injectable interface { Inject(pid IsID) error }
type IsID interface { ToID() string }
type LockMap[K comparable] struct { sync.Map }
func NewLockMap[K comparable]() LockMap[K]
func (l *LockMap[K]) Del(key K)
Del :TODO: Fix bug on deleting a using value
func (l *LockMap[K]) Lock(key K) func()
Mergeable introduces the data gathering ability.
type Mergeable interface { Merge(a Mergeable) error }
Object ensure the outer config change will not change the data inside the TaskManager.
type Object interface { DeepCopy() Object }
type PodContainerName string
func (p PodContainerName) ToID() string
type PodContainerNameProcessMap struct {
// contains filtered or unexported fields
}
func NewPodProcessMap() PodContainerNameProcessMap
func (p *PodContainerNameProcessMap) Delete(podPID PodContainerName)
func (p *PodContainerNameProcessMap) Read(PodContainerName PodContainerName) (SysPID, error)
func (p *PodContainerNameProcessMap) Write(PodContainerName PodContainerName, sysPID SysPID)
PodHandler implements injecting & recovering on a kubernetes POD.
type PodHandler struct { PodProcessMap *PodContainerNameProcessMap SubProcess ChaosOnPOD Logger logr.Logger }
func NewPodHandler(podProcessMap *PodContainerNameProcessMap, sub ChaosOnPOD, logger logr.Logger) PodHandler
func (p *PodHandler) Inject(id IsID) error
Inject get the container process IsID and Inject it with major injector. Be careful about the error handling here.
func (p *PodHandler) Recover(id IsID) error
Recover get the container process IsID and Recover it with major injector. Be careful about the error handling here.
ProcessGroupHandler implements injecting & recovering on a linux process group.
type ProcessGroupHandler struct { LeaderProcess ChaosOnProcessGroup Logger logr.Logger // contains filtered or unexported fields }
func NewProcessGroupHandler(logger logr.Logger, leader ChaosOnProcessGroup) ProcessGroupHandler
func (gp *ProcessGroupHandler) Inject(pid IsID) error
Inject try to inject the leader process and then try to inject child process. If something wrong in injecting a child process, Inject will just log error & continue.
func (gp *ProcessGroupHandler) Recover(pid IsID) error
Recover try to recover the leader process and then try to recover child process.
Recoverable introduce the task recovering ability. Used in Recover.
type Recoverable interface { Recover(pid IsID) error }
type SysPID uint32
func (s SysPID) ToID() string
TaskConfig defines a composite of flexible config with an immutable target. TaskConfig.Id is the ID of task. TaskConfig.Data is the config provided by developer.
type TaskConfig struct { Id IsID Data Object }
func NewTaskConfig(id IsID, data Object) TaskConfig
TaskConfigManager provides some basic methods on TaskConfig. If developers wants to use MergeTaskConfig, they must implement Mergeable for the TaskConfig.
type TaskConfigManager struct { TaskConfigMap map[TaskID]TaskConfig }
func NewTaskConfigManager() TaskConfigManager
func (m TaskConfigManager) AddTaskConfig(id TaskID, task TaskConfig) error
func (m TaskConfigManager) CheckTask(uid TaskID, pid IsID) error
func (m TaskConfigManager) DeleteTaskConfig(id TaskID) error
DeleteTaskConfig Delete task inside the TaskConfigManager
func (m TaskConfigManager) GetConfigWithUID(id TaskID) (TaskConfig, error)
func (m TaskConfigManager) GetUIDsWithPID(id IsID) []TaskID
func (m TaskConfigManager) MergeTaskConfig(uid TaskID) (TaskConfig, error)
MergeTaskConfig will sum the TaskConfig with a same TaskConfig.Id. If developers want to use it with type T, they must implement Mergeable for *T. IMPORTANT: Just here , we do not assume A.Merge(B) == B.Merge(A). What MergeTaskConfig do : A := new(TaskConfig), A.Merge(B).Merge(C).Merge(D)... , A marked as uid.
func (m TaskConfigManager) UpdateTaskConfig(id TaskID, task TaskConfig) (TaskConfig, error)
TaskExecutor indicate that the type can be used for execute task here as a task config. Mergeable means we can sum many task config in to one for apply. Creator means we can use the task config to create a running task which can Inject on IsID. Assign means we can use the task config to update an existing running task.
type TaskExecutor interface { Object Mergeable Creator Assign }
type TaskID = string
TaskManager is a Manager for chaos tasks. A task base on a target marked with its IsID. We assume task should implement Injectable. We use TaskConfig.Data which implement TaskExecutor to:
Sum task configs on same IsID into one. Create task. Assign or update task.
SO if developers wants to use functions in TaskManager , their imported TaskConfig need to implement interface TaskExecutor. If developers wants to recover task successfully, the task must implement Recoverable. If not implement , the Recover function will return a ErrNotImplement("Recoverable") error. IMPORTANT: We assume task config obey that TaskConfig.Data A,B. A.Merge(B) is approximately equal to B.Merge(A)
type TaskManager struct {
// contains filtered or unexported fields
}
func NewTaskManager(logger logr.Logger) TaskManager
func (cm TaskManager) Apply(uid TaskID, pid IsID, config TaskExecutor) error
Apply the task when the target pid of task is already be Created. If it comes a TaskID injected , Apply will return ChaosErr.ErrDuplicateEntity. If the Process has not been Created , Apply will return ChaosErr.NotFound("IsID").
func (cm TaskManager) CheckTasks(uid TaskID, pid IsID) error
func (cm TaskManager) ClearTask(pid IsID, ignoreRecoverErr bool) error
ClearTask clear the task totally. IMPORTANT: Developer should only use this function when want to force clear task with ignoreRecoverErr==true.
func (cm TaskManager) CopyTaskConfigManager() TaskConfigManager
func (cm TaskManager) CopyTaskMap() map[IsID]Injectable
func (cm TaskManager) Create(uid TaskID, pid IsID, config TaskExecutor, values interface{}) error
Create the first task, the New function of TaskExecutor:Creator will only be used here. values is only the import parameter of New function in TaskExecutor:Creator. If it comes a task are already be injected on the IsID, Create will return ChaosErr.ErrDuplicateEntity.
func (cm TaskManager) GetConfigWithUID(id TaskID) (TaskConfig, error)
func (cm TaskManager) GetTaskWithPID(pid IsID) (Injectable, error)
func (cm TaskManager) GetUIDsWithPID(pid IsID) []TaskID
func (cm TaskManager) Recover(uid TaskID, pid IsID) error
Recover the task when there is no task config on IsID or recovering the task with last task config on IsID. Recover in Recoverable will be used here, if it runs failed it will just return the error. If Recover is failed but developer wants to clear it, just run : TaskManager.ClearTask(pid, true). If IsID is already recovered successfully, Recover will return ChaosErr.NotFound("IsID"). If TaskID is not Applied or Created or the target IsID of TaskID is not the import pid, Recover will return ChaosErr.NotFound("TaskID").
func (cm TaskManager) Update(uid TaskID, pid IsID, config TaskExecutor) error
Update the task with a same TaskID, IsID and new task config. If it comes a TaskID not injected , Update will return ChaosErr.NotFound("TaskID"). If it comes the import IsID of task do not equal to the last one, Update will return ErrDiffID.