Skip to content

Commit

Permalink
feat(probe): Adding the probe inside chaosengine (#248)
Browse files Browse the repository at this point in the history
Signed-off-by: shubhamchaudhary <[email protected]>
  • Loading branch information
ispeakc0de authored Aug 13, 2020
1 parent b106d83 commit a5d1a83
Show file tree
Hide file tree
Showing 6 changed files with 471 additions and 3 deletions.
88 changes: 88 additions & 0 deletions deploy/chaos_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,94 @@ spec:
spec:
type: object
properties:
k8sProbe:
type: array
items:
type: object
properties:
name:
type: string
inputs:
type: object
properties:
command:
type: object
properties:
group:
type: string
version:
type: string
resource:
type: string
namespace:
type: string
fieldSelector:
type: string
expectedResult:
type: string
runProperties:
type: object
properties:
probeTimeout:
type: int
interval:
type: int
retry:
type: int
mode:
type: string
cmdProbe:
type: array
items:
type: object
properties:
name:
type: string
inputs:
type: object
properties:
command:
type: string
expectedResult:
type: string
source:
type: string
runProperties:
type: object
properties:
probeTimeout:
type: int
interval:
type: int
retry:
type: int
mode:
type: string
httpProbe:
type: array
items:
type: object
properties:
name:
type: string
inputs:
type: object
properties:
url:
type: string
expectedResponseCode:
type: string
runProperties:
type: object
properties:
probeTimeout:
type: int
interval:
type: int
retry:
type: int
mode:
type: string
components:
type: object
properties:
Expand Down
88 changes: 88 additions & 0 deletions deploy/crds/chaosengine_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,94 @@ spec:
spec:
type: object
properties:
k8sProbe:
type: array
items:
type: object
properties:
name:
type: string
inputs:
type: object
properties:
command:
type: object
properties:
group:
type: string
version:
type: string
resource:
type: string
namespace:
type: string
fieldSelector:
type: string
expectedResult:
type: string
runProperties:
type: object
properties:
probeTimeout:
type: int
interval:
type: int
retry:
type: int
mode:
type: string
cmdProbe:
type: array
items:
type: object
properties:
name:
type: string
inputs:
type: object
properties:
command:
type: string
expectedResult:
type: string
source:
type: string
runProperties:
type: object
properties:
probeTimeout:
type: int
interval:
type: int
retry:
type: int
mode:
type: string
httpProbe:
type: array
items:
type: object
properties:
name:
type: string
inputs:
type: object
properties:
url:
type: string
expectedResponseCode:
type: string
runProperties:
type: object
properties:
probeTimeout:
type: int
interval:
type: int
retry:
type: int
mode:
type: string
components:
type: object
properties:
Expand Down
99 changes: 98 additions & 1 deletion pkg/apis/litmuschaos/v1alpha1/chaosengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,105 @@ type ExperimentList struct {
type ExperimentAttributes struct {
//Execution priority of the chaos experiment
Rank uint32 `json:"rank"`
//Environment Varibles to override the default values in chaos-experiments
// It contains env, configmaps, secrets, experimentImage, node selector, custom experiment annotation
// which can be provided or overridden from the chaos engine
Components ExperimentComponents `json:"components,omitempty"`
// K8sProbe contains details of k8s probe, which can be applied on the experiments
K8sProbe []K8sProbeAttributes `json:"k8sProbe,omitempty"`
// CmdProbe contains details of cmd probe, which can be applied on the experiments
CmdProbe []CmdProbeAttributes `json:"cmdProbe,omitempty"`
// HTTPProbe contains details of http probe, which can be applied on the experiments
HTTPProbe []HTTPProbeAttributes `json:"httpProbe,omitempty"`
}

// K8sProbeAttributes contains details of k8s probe, which can be applied on the experiments
type K8sProbeAttributes struct {
// Name of probe
Name string `json:"name,omitempty"`
// inputs needed for the k8s probe
Inputs K8sProbeInputs `json:"inputs,omitempty"`
// RunProperty contains timeout, retry and interval for the probe
RunProperties RunProperty `json:"runProperties,omitempty"`
// mode for k8s probe
// it can be SOT, EOT, Edge
Mode string `json:"mode,omitempty"`
}

// CmdProbeAttributes contains details of cmd probe, which can be applied on the experiments
type CmdProbeAttributes struct {
// Name of probe
Name string `json:"name,omitempty"`
// inputs needed for the cmd probe
Inputs CmdProbeInputs `json:"inputs,omitempty"`
// RunProperty contains timeout, retry and interval for the probe
RunProperties RunProperty `json:"runProperties,omitempty"`
// mode for cmd probe
// it can be SOT, EOT, Edge, Continuous
Mode string `json:"mode,omitempty"`
}

// HTTPProbeAttributes contains details of k8s probe, which can be applied on the experiments
type HTTPProbeAttributes struct {
// Name of probe
Name string `json:"name,omitempty"`
// inputs needed for the http probe
Inputs HTTPProbeInputs `json:"inputs,omitempty"`
// RunProperty contains timeout, retry and interval for the probe
RunProperties RunProperty `json:"runProperties,omitempty"`
// mode for http probe
// it can be SOT, EOT, Edge, Continuous
Mode string `json:"mode,omitempty"`
}

// K8sProbeInputs contains all the inputs required for k8s probe
type K8sProbeInputs struct {
// Command need to be executed for the probe
Command K8sCommand `json:"command,omitempty"`
// Expected output or result of the command
ExpectedResult string `json:"expectedResult,omitempty"`
}

// K8sCommand contains all the commands need for the k8sprobe
type K8sCommand struct {
// group of the resource
Group string `json:"group,omitempty"`
// apiversion of the resource
Version string `json:"version,omitempty"`
// kind of resource
Resource string `json:"resource,omitempty"`
// namespace of the resource
Namespace string `json:"namespace,omitempty"`
// fieldselector to get the details
FieldSelector string `json:"fieldSelector,omitempty"`
}

//CmdProbeInputs contains all the inputs required for cmd probe
type CmdProbeInputs struct {
// Command need to be executed for the probe
Command string `json:"command,omitempty"`
// Expected output or result of the command
ExpectedResult string `json:"expectedResult,omitempty"`
// The source where we have to run the command
// It can be a image or inline(inside experiment itself)
Source string `json:"source,omitempty"`
}

//HTTPProbeInputs contains all the inputs required for http probe
type HTTPProbeInputs struct {
// URL which needs to curl, to check the status
URL string `json:"url,omitempty"`
// Expected response code from the given url
ExpectedResponseCode string `json:"expectedResponseCode,omitempty"`
}

//RunProperty contains timeout, retry and interval for the probe
type RunProperty struct {
//ProbeTimeout contains timeout for the probe
ProbeTimeout int `json:"probeTimeout,omitempty"`
// Interval contains the inverval for the probe
Interval int `json:"interval,omitempty"`
// Retry contains the retry count for the probe
Retry int `json:"retry,omitempty"`
}

// ExperimentComponents contains ENV, Configmaps and Secrets
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/litmuschaos/v1alpha1/chaosexperiment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Secret struct {
MountPath string `json:"mountPath"`
}

// HostFile is an simpler implementation of corev1.HostPath, needed for experiments
type HostFile struct {
Name string `json:"name"`
MountPath string `json:"mountPath"`
Expand Down
16 changes: 15 additions & 1 deletion pkg/apis/litmuschaos/v1alpha1/chaosresult_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ type ChaosResultStatus struct {
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html

// Definition carries low-level chaos options
// ExperimentStatus contains the status,verdict of the experiment
ExperimentStatus TestStatus `json:"experimentstatus"`
// ProbeStatus contains the status of the probe
ProbeStatus []ProbeStatus `json:"probeStatus,omitempty"`
}

// ProbeStatus defines information about the status and result of the probes
type ProbeStatus struct {
// Name defines the name of probe
Name string `json:"name,omitempty"`
// Type defined the type of probe, supported values: K8sProbe, HttpProbe, CmdProbe
Type string `json:"type,omitempty"`
// Status defines whether a probe is pass or fail
Status map[string]string `json:"status,omitempty"`
}

// TestStatus defines information about the status and results of a chaos experiment
Expand All @@ -52,6 +64,8 @@ type TestStatus struct {
Verdict string `json:"verdict"`
// FailStep defines step where the experiments fails
FailStep string `json:"failStep,omitempty"`
// ResilienceScore defines the score of the experiment on the basis of probes result
ResilienceScore string `json:"resilienceScore,omitempty"`
}

// +genclient
Expand Down
Loading

0 comments on commit a5d1a83

Please sign in to comment.