utils

package
v0.0.0-...-13f8c59 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SideCarEnabled = "sidecar/enabled"
	SideCarPrefix  = "SIDECAR"
)
View Source
const (
	// ExperimentDependencyCheckReason contains the reason for the dependency check event
	ExperimentDependencyCheckReason string = "ExperimentDependencyCheck"
	// ExperimentJobCreateReason contains the reason for the job creation event
	ExperimentJobCreateReason string = "ExperimentJobCreate"
	// ExperimentJobCleanUpReason contains the reason for the job cleanup event
	ExperimentJobCleanUpReason string = "ExperimentJobCleanUp"
	// ExperimentSkippedReason contains the reason for the experiment skip event
	ExperimentSkippedReason string = "ExperimentSkipped"
	// ExperimentEnvParseErrorReason contains the reason for the env-parse-error event
	ExperimentEnvParseErrorReason string = "EnvParseError"
	// ExperimentNotFoundErrorReason contains the reason for the experiment-not-found event
	ExperimentNotFoundErrorReason string = "ExperimentNotFound"
	// ExperimentJobCreationErrorReason contains the reason for the job-creation-error event
	ExperimentJobCreationErrorReason string = "JobCreationError"
	// ExperimentChaosContainerWatchErrorReason contains the reason for the watch-job-error event
	ExperimentChaosContainerWatchErrorReason string = "ChaosContainerWatchNotPermitted"
	// ChaosResourceNotFoundReason contains the reason for the chaos-resources-not-found event
	ChaosResourceNotFoundReason string = "ChaosResourceNotFound"
	// ExperimentSideCarPatchErrorReason contains the reason for the side-car-patch-error event
	ExperimentSideCarPatchErrorReason string = "SideCarPatchError"
)

Variables

View Source
var (
	// DefaultExpImagePullPolicy contains the defaults value (Always) of imagePullPolicy for exp container
	DefaultExpImagePullPolicy v1.PullPolicy = "Always"
)

Functions

func BuildingAndLaunchJob

func BuildingAndLaunchJob(experiment *ExperimentDetails, clients ClientSets) error

BuildingAndLaunchJob builds Job, and then launch it.

func GetChaosContainerStatus

func GetChaosContainerStatus(experimentDetails *ExperimentDetails, clients ClientSets) (bool, error)

GetChaosContainerStatus gets status of the chaos container

func GetChaosPod

func GetChaosPod(expDetails *ExperimentDetails, clients ClientSets) (*corev1.Pod, error)

GetChaosPod gets the chaos experiment pod object launched by the runner

func GetResultName

func GetResultName(engineName, experimentName, instanceID string) string

GetResultName returns the resultName using the experimentName and engine Name

func InitialPatchEngine

func InitialPatchEngine(engineDetails EngineDetails, clients ClientSets, experimentList []ExperimentDetails) error

InitialPatchEngine patches the chaosEngine with the initial ExperimentStatuses

func RandomString

func RandomString(length int) string

RandomString will generate a random string of length 6

Types

type ClientSets

type ClientSets struct {
	KubeClient   kubernetes.Interface
	LitmusClient clientV1alpha1.Interface
}

ClientSets is a collection of clientSets needed

func (*ClientSets) GenerateClientSetFromKubeConfig

func (clientSets *ClientSets) GenerateClientSetFromKubeConfig() error

GenerateClientSetFromKubeConfig will generation both ClientSets (k8s, and Litmus)

func (ClientSets) ValidatePresenceOfConfigMapResourceInCluster

func (clientSets ClientSets) ValidatePresenceOfConfigMapResourceInCluster(configMapName, namespace string) error

ValidatePresenceOfConfigMapResourceInCluster validates the configMap, before checking or creating them.

func (ClientSets) ValidatePresenceOfSecretResourceInCluster

func (clientSets ClientSets) ValidatePresenceOfSecretResourceInCluster(secretName, namespace string) error

ValidatePresenceOfSecretResourceInCluster validates the secret in Chaos Namespace

type EngineDetails

type EngineDetails struct {
	Name             string
	Experiments      []string
	Targets          string
	SvcAccount       string
	ClientUUID       string
	AuxiliaryAppInfo string
	UID              string
	EngineNamespace  string
}

EngineDetails struct is for collecting all the engine-related details

func (EngineDetails) CreateEvents

func (engineDetails EngineDetails) CreateEvents(eventAttributes *EventAttributes, clients ClientSets) error

CreateEvents create the events in the desired resource

func (*EngineDetails) CreateExperimentList

func (engineDetails *EngineDetails) CreateExperimentList() []ExperimentDetails

CreateExperimentList make the list of all experiment, provided inside chaosengine

func (EngineDetails) DeleteJobAccordingToJobCleanUpPolicy

func (engineDetails EngineDetails) DeleteJobAccordingToJobCleanUpPolicy(experiment *ExperimentDetails, clients ClientSets) (v1alpha1.CleanUpPolicy, error)

DeleteJobAccordingToJobCleanUpPolicy deletes the chaosExperiment Job according to jobCleanUpPolicy

func (EngineDetails) ExperimentNotFoundPatchEngine

func (engineDetails EngineDetails) ExperimentNotFoundPatchEngine(experiment *ExperimentDetails, clients ClientSets) error

ExperimentNotFoundPatchEngine patches the chaosEngine when ChaosExperiment is not Found

func (EngineDetails) ExperimentSkippedPatchEngine

func (engineDetails EngineDetails) ExperimentSkippedPatchEngine(experiment *ExperimentDetails, clients ClientSets)

ExperimentSkippedPatchEngine patches the chaosEngine with skipped status

func (EngineDetails) GenerateEvents

func (engineDetails EngineDetails) GenerateEvents(eventAttributes *EventAttributes, clients ClientSets) error

GenerateEvents update the events and increase the count by 1, if already present else it will create a new event

func (EngineDetails) GetChaosEngine

func (engineDetails EngineDetails) GetChaosEngine(clients ClientSets) (*v1alpha1.ChaosEngine, error)

GetChaosEngine returns chaosEngine Object

func (*EngineDetails) NewExperimentDetails

func (engineDetails *EngineDetails) NewExperimentDetails(i int) ExperimentDetails

NewExperimentDetails create and initialize the experimentDetails

func (*EngineDetails) SetEngineDetails

func (engineDetails *EngineDetails) SetEngineDetails() *EngineDetails

SetEngineDetails adds the ENV's to EngineDetails

func (*EngineDetails) SetEngineUID

func (engineDetails *EngineDetails) SetEngineUID(clients ClientSets) error

SetEngineUID set the chaosengine UID

func (EngineDetails) UpdateEngineWithResult

func (engineDetails EngineDetails) UpdateEngineWithResult(experiment *ExperimentDetails, clients ClientSets) error

UpdateEngineWithResult will update the result in chaosEngine And will delete job if jobCleanUpPolicy is set to "delete"

func (EngineDetails) WatchChaosContainerForCompletion

func (engineDetails EngineDetails) WatchChaosContainerForCompletion(experiment *ExperimentDetails, clients ClientSets) error

WatchChaosContainerForCompletion watches the chaos container for completion

type EventAttributes

type EventAttributes struct {
	Reason  string
	Message string
	Type    string
	Name    string
}

EventAttributes is for collecting all the events-related details

func (*EventAttributes) SetEventAttributes

func (event *EventAttributes) SetEventAttributes(reason, eventType, msg string)

SetEventAttributes set the event attributes for each

type ExperimentDetails

type ExperimentDetails struct {
	Name string

	ExpLabels          map[string]string
	ExpImage           string
	ExpImagePullPolicy v1.PullPolicy
	ExpArgs            []string
	ExpCommand         []string
	JobName            string
	Namespace          string
	ConfigMaps         []v1alpha1.ConfigMap
	Secrets            []v1alpha1.Secret
	HostFileVolumes    []v1alpha1.HostFile
	VolumeOpts         VolumeOpts
	SvcAccount         string
	Annotations        map[string]string
	NodeSelector       map[string]string
	Tolerations        []v1.Toleration
	SecurityContext    v1alpha1.SecurityContext
	HostPID            bool
	// InstanceID is passed as env inside chaosengine
	// It is separately specified here because this attribute is common for all experiment.
	InstanceID                    string
	ResourceRequirements          v1.ResourceRequirements
	ImagePullSecrets              []v1.LocalObjectReference
	StatusCheckTimeout            int
	TerminationGracePeriodSeconds int64
	DefaultHealthCheck            string
	SideCars                      []SideCar
	// contains filtered or unexported fields
}

ExperimentDetails is for collecting all the experiment-related details

func (ExperimentDetails) ExperimentDependencyCheck

func (expDetails ExperimentDetails) ExperimentDependencyCheck(engineDetails EngineDetails, clients ClientSets)

ExperimentDependencyCheck is an standard event spawned just after validating experiment dependent resources such as ChaosExperiment, ConfigMaps and Secrets.

func (ExperimentDetails) ExperimentJobCleanUp

func (expDetails ExperimentDetails) ExperimentJobCleanUp(jobCleanUpPolicy string, engineDetails EngineDetails, clients ClientSets)

ExperimentJobCleanUp is an standard event spawned just after deleting ChaosExperiment Job

func (ExperimentDetails) ExperimentJobCreate

func (expDetails ExperimentDetails) ExperimentJobCreate(engineDetails EngineDetails, clients ClientSets)

ExperimentJobCreate is an standard event spawned just after starting ChaosExperiment Job

func (ExperimentDetails) ExperimentSkipped

func (expDetails ExperimentDetails) ExperimentSkipped(reason string, engineDetails EngineDetails, clients ClientSets)

ExperimentSkipped is an standard event spawned just after a ChaosExperiment is skipped

func (*ExperimentDetails) GetChaosResult

func (expDetails *ExperimentDetails) GetChaosResult(engineDetails EngineDetails, clients ClientSets) (*v1alpha1.ChaosResult, error)

GetChaosResult returns ChaosResult object.

func (*ExperimentDetails) HandleChaosExperimentExistence

func (expDetails *ExperimentDetails) HandleChaosExperimentExistence(engineDetails EngineDetails, clients ClientSets) error

HandleChaosExperimentExistence will check the experiment in the app namespace

func (*ExperimentDetails) PatchConfigMaps

func (expDetails *ExperimentDetails) PatchConfigMaps(clients ClientSets, engineDetails EngineDetails) error

PatchConfigMaps patches configmaps in experimentDetails struct.

func (*ExperimentDetails) PatchHostFileVolumes

func (expDetails *ExperimentDetails) PatchHostFileVolumes(clients ClientSets, engineDetails EngineDetails) error

PatchHostFileVolumes patches hostFileVolume in experimentDetails struct.

func (*ExperimentDetails) PatchResources

func (expDetails *ExperimentDetails) PatchResources(engineDetails EngineDetails, clients ClientSets) error

PatchResources function patches chaos Experiment Job with different Kubernetes Resources.

func (*ExperimentDetails) PatchSecrets

func (expDetails *ExperimentDetails) PatchSecrets(clients ClientSets, engineDetails EngineDetails) error

PatchSecrets patches secrets in experimentDetails.

func (*ExperimentDetails) SetArgs

func (expDetails *ExperimentDetails) SetArgs(experimentSpec *litmuschaosv1alpha1.ChaosExperiment) *ExperimentDetails

SetArgs sets the Experiment Image, in Experiment Structure

func (*ExperimentDetails) SetCommand

func (expDetails *ExperimentDetails) SetCommand(experimentSpec *litmuschaosv1alpha1.ChaosExperiment) *ExperimentDetails

SetCommand to execute inside the experiment image.

func (*ExperimentDetails) SetConfigMaps

func (expDetails *ExperimentDetails) SetConfigMaps(clients ClientSets, engineDetails EngineDetails) error

SetConfigMaps sets the value of configMaps in Experiment Structure

func (*ExperimentDetails) SetDefaultAttributeValuesFromChaosExperiment

func (expDetails *ExperimentDetails) SetDefaultAttributeValuesFromChaosExperiment(clients ClientSets, engine *EngineDetails) error

SetDefaultAttributeValuesFromChaosExperiment sets value in experimentDetails struct from chaosExperiment

func (*ExperimentDetails) SetDefaultEnvFromChaosExperiment

func (expDetails *ExperimentDetails) SetDefaultEnvFromChaosExperiment(clients ClientSets) error

SetDefaultEnvFromChaosExperiment sets the Env's in Experiment Structure

func (*ExperimentDetails) SetDefaultHealthCheck

func (expDetails *ExperimentDetails) SetDefaultHealthCheck(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetDefaultHealthCheck sets th default health checks provided inside the chaosEngine

func (*ExperimentDetails) SetENV

func (expDetails *ExperimentDetails) SetENV(engineDetails EngineDetails, clients ClientSets) error

SetENV sets ENV values in experimentDetails struct.

func (*ExperimentDetails) SetEngineLabels

func (expDetails *ExperimentDetails) SetEngineLabels(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetEngineLabels sets the engine labels

func (*ExperimentDetails) SetExpAnnotationFromEngine

func (expDetails *ExperimentDetails) SetExpAnnotationFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetExpAnnotationFromEngine override the default exp annotation with the one provided in the chaosEngine

func (*ExperimentDetails) SetExpImageFromEngine

func (expDetails *ExperimentDetails) SetExpImageFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetExpImageFromEngine will override the default exp image with the one provided in the chaosEngine

func (*ExperimentDetails) SetExpNodeSelectorFromEngine

func (expDetails *ExperimentDetails) SetExpNodeSelectorFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetExpNodeSelectorFromEngine add the nodeSelector attribute based on the key/value provided in the chaosEngine

func (*ExperimentDetails) SetHostFileVolumes

func (expDetails *ExperimentDetails) SetHostFileVolumes(clients ClientSets, engineDetails EngineDetails) error

SetHostFileVolumes sets the value of hostFileVolumes in Experiment Structure

func (*ExperimentDetails) SetHostPID

func (expDetails *ExperimentDetails) SetHostPID(experimentSpec *litmuschaosv1alpha1.ChaosExperiment) *ExperimentDetails

SetHostPID sets the hostPID, in Experiment Structure

func (*ExperimentDetails) SetImage

func (expDetails *ExperimentDetails) SetImage(experimentSpec *litmuschaosv1alpha1.ChaosExperiment) *ExperimentDetails

SetImage sets the Experiment Image, in Experiment Structure

func (*ExperimentDetails) SetImagePullPolicy

func (expDetails *ExperimentDetails) SetImagePullPolicy(experimentSpec *litmuschaosv1alpha1.ChaosExperiment) *ExperimentDetails

SetImagePullPolicy sets the Experiment ImagePullPolicy, in Experiment Structure

func (*ExperimentDetails) SetImagePullSecretsFromEngine

func (expDetails *ExperimentDetails) SetImagePullSecretsFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetImagePullSecretsFromEngine add the image pull secrets provided inside chaosengine

func (*ExperimentDetails) SetInstanceAttributeValuesFromChaosEngine

func (expDetails *ExperimentDetails) SetInstanceAttributeValuesFromChaosEngine(engine *EngineDetails, clients ClientSets) error

SetInstanceAttributeValuesFromChaosEngine set the value from the chaosengine

func (*ExperimentDetails) SetLabels

func (expDetails *ExperimentDetails) SetLabels(experimentSpec *litmuschaosv1alpha1.ChaosExperiment, engine *EngineDetails) *ExperimentDetails

SetLabels sets the Experiment Labels, in Experiment Structure

func (*ExperimentDetails) SetOverrideEnvFromChaosEngine

func (expDetails *ExperimentDetails) SetOverrideEnvFromChaosEngine(engineName string, clients ClientSets) error

SetOverrideEnvFromChaosEngine override the default envs with envs passed inside the chaosengine

func (*ExperimentDetails) SetResourceRequirementsFromEngine

func (expDetails *ExperimentDetails) SetResourceRequirementsFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetResourceRequirementsFromEngine add the resource requirements provided inside chaosengine

func (*ExperimentDetails) SetSecrets

func (expDetails *ExperimentDetails) SetSecrets(clients ClientSets, engineDetails EngineDetails) error

SetSecrets sets the value of secrets in Experiment Structure

func (*ExperimentDetails) SetSecurityContext

func (expDetails *ExperimentDetails) SetSecurityContext(experimentSpec *litmuschaosv1alpha1.ChaosExperiment) *ExperimentDetails

SetSecurityContext sets the security context, in Experiment Structure

func (*ExperimentDetails) SetSideCarDetails

func (expDetails *ExperimentDetails) SetSideCarDetails(engineName string, clients ClientSets) error

func (*ExperimentDetails) SetTerminationGracePeriodSecondsFromEngine

func (expDetails *ExperimentDetails) SetTerminationGracePeriodSecondsFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetTerminationGracePeriodSecondsFromEngine set the terminationGracePeriodSeconds for experiment pod provided in the chaosEngine

func (*ExperimentDetails) SetTolerationsFromEngine

func (expDetails *ExperimentDetails) SetTolerationsFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails

SetTolerationsFromEngine add the tolerations based on the key/operator/effect provided in the chaosEngine

func (*ExperimentDetails) SetValueFromChaosResources

func (expDetails *ExperimentDetails) SetValueFromChaosResources(engineDetails *EngineDetails, clients ClientSets) error

SetValueFromChaosResources fetches required values from various Chaos Resources

func (*ExperimentDetails) ValidateConfigMaps

func (expDetails *ExperimentDetails) ValidateConfigMaps(clients ClientSets) error

ValidateConfigMaps checks for configMaps in the Chaos Namespace

func (*ExperimentDetails) ValidateHostFileVolumes

func (expDetails *ExperimentDetails) ValidateHostFileVolumes() error

ValidateHostFileVolumes validates the hostFileVolume definition in experiment CR spec

func (*ExperimentDetails) ValidateSecrets

func (expDetails *ExperimentDetails) ValidateSecrets(clients ClientSets) error

ValidateSecrets checks for secrets in the Chaos Namespace

type ExperimentStatus

type ExperimentStatus v1alpha1.ExperimentStatuses

ExperimentStatus is wrapper for v1alpha1.ExperimentStatuses

func (*ExperimentStatus) AwaitedExperimentStatus

func (expStatus *ExperimentStatus) AwaitedExperimentStatus(expName, engineName, experimentPodName string)

AwaitedExperimentStatus fills up ExperimentStatus Structure with Running Status

func (*ExperimentStatus) CompletedExperimentStatus

func (expStatus *ExperimentStatus) CompletedExperimentStatus(chaosResult *v1alpha1.ChaosResult, engineName, experimentPodName string)

CompletedExperimentStatus fills up ExperimentStatus Structure with values chaosResult

func (*ExperimentStatus) InitialExperimentStatus

func (expStatus *ExperimentStatus) InitialExperimentStatus(expName, engineName string)

InitialExperimentStatus fills up ExperimentStatus Structure with InitialValues

func (*ExperimentStatus) NotFoundExperimentStatus

func (expStatus *ExperimentStatus) NotFoundExperimentStatus(expName, engineName string)

NotFoundExperimentStatus initilize experiment struct using the following values.

func (*ExperimentStatus) PatchChaosEngineStatus

func (expStatus *ExperimentStatus) PatchChaosEngineStatus(engineDetails EngineDetails, clients ClientSets) error

PatchChaosEngineStatus updates ChaosEngine with Experiment Status

func (*ExperimentStatus) SkippedExperimentStatus

func (expStatus *ExperimentStatus) SkippedExperimentStatus(expName, engineName string)

SkippedExperimentStatus fills up ExperimentStatus Structure with skipped value

type PodTemplateSpec

type PodTemplateSpec struct {
	Object *corev1.PodTemplateSpec
}

PodTemplateSpec is struct for creating the *core1.PodTemplateSpec

type SideCar

type SideCar struct {
	ENV             []v1.EnvVar
	Image           string
	ImagePullPolicy v1.PullPolicy
	Secrets         []v1alpha1.Secret
	EnvFrom         []v1.EnvFromSource
}

type VolumeOpts

type VolumeOpts struct {
	VolumeMounts   []v1.VolumeMount
	VolumeBuilders []*volume.Builder
}

VolumeOpts is a strcuture for all volume related operations

func (*VolumeOpts) BuildVolumeBuilderForConfigMaps

func (volumeOpts *VolumeOpts) BuildVolumeBuilderForConfigMaps(configMaps []v1alpha1.ConfigMap) *VolumeOpts

BuildVolumeBuilderForConfigMaps builds VolumeBuilders for ConfigMaps

func (*VolumeOpts) BuildVolumeBuilderForHostFileVolumes

func (volumeOpts *VolumeOpts) BuildVolumeBuilderForHostFileVolumes(hostFileVolumes []v1alpha1.HostFile) *VolumeOpts

BuildVolumeBuilderForHostFileVolumes builds VolumeBuilders for HostFileVolume

func (*VolumeOpts) BuildVolumeBuilderForSecrets

func (volumeOpts *VolumeOpts) BuildVolumeBuilderForSecrets(secrets []v1alpha1.Secret) *VolumeOpts

BuildVolumeBuilderForSecrets builds VolumeBuilders for Secrets

func (*VolumeOpts) BuildVolumeMountsForConfigMaps

func (volumeOpts *VolumeOpts) BuildVolumeMountsForConfigMaps(configMaps []v1alpha1.ConfigMap) *VolumeOpts

BuildVolumeMountsForConfigMaps builds VolumeMounts for ConfigMaps

func (*VolumeOpts) BuildVolumeMountsForHostFileVolumes

func (volumeOpts *VolumeOpts) BuildVolumeMountsForHostFileVolumes(hostFileVolumes []v1alpha1.HostFile) *VolumeOpts

BuildVolumeMountsForHostFileVolumes builds VolumeMounts for HostFileVolume

func (*VolumeOpts) BuildVolumeMountsForSecrets

func (volumeOpts *VolumeOpts) BuildVolumeMountsForSecrets(secrets []v1alpha1.Secret) *VolumeOpts

BuildVolumeMountsForSecrets builds VolumeMounts for Secrets

func (*VolumeOpts) NewVolumeBuilder

func (volumeOpts *VolumeOpts) NewVolumeBuilder() *VolumeOpts

NewVolumeBuilder initialize the volume builder

func (*VolumeOpts) NewVolumeMounts

func (volumeOpts *VolumeOpts) NewVolumeMounts() *VolumeOpts

NewVolumeMounts initialize the volume builder

func (*VolumeOpts) VolumeOperations

func (volumeOpts *VolumeOpts) VolumeOperations(experiment *ExperimentDetails)

VolumeOperations filles up VolumeOpts strucuture

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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