Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(operator): refactor Chaos type and PodChaos reconciliation #401

Merged
merged 7 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,32 @@ import (
)

// +kubebuilder:object:root=true
// ShardingSphereChaosList contains a list of ShardingSphereChaos
type ShardingSphereChaosList struct {
// ChaosList contains a list of Chaos
type ChaosList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ShardingSphereChaos `json:"items"`
Items []Chaos `json:"items"`
}

// +kubebuilder:printcolumn:JSONPath=".metadata.creationTimestamp",name=Age,type=date
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// ShardingSphereChaos defines a chaos test case for the ShardingSphere Proxy cluster
type ShardingSphereChaos struct {
// Chaos defines a chaos test case for the ShardingSphere Proxy cluster
type Chaos struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ShardingSphereChaosSpec `json:"spec,omitempty"`
Status ShardingSphereChaosStatus `json:"status,omitempty"`
Spec ChaosSpec `json:"spec,omitempty"`
Status ChaosStatus `json:"status,omitempty"`
}

// ShardingSphereChaosSpec defines the desired state of ShardingSphereChaos
type ShardingSphereChaosSpec struct {
InjectJob JobSpec `json:"injectJob,omitempty"`
EmbedChaos `json:",inline"`
PressureCfg PressureCfg `json:"pressureCfg"`
// ChaosSpec defines the desired state of Chaos
type ChaosSpec struct {
EmbedChaos `json:",inline"`

// +optional
InjectJob *JobSpec `json:"injectJob,omitempty" yaml:"injectJob,omitempty"`
// +optional
PressureCfg *PressureCfg `json:"pressureCfg,omitempty" yaml:"pressureCfg,omitempty"`
}

type PressureCfg struct {
Expand All @@ -67,11 +70,11 @@ type Script string
// JobSpec specifies the config of job to create
type JobSpec struct {
// +optional
Experimental Script `json:"experimental,omitempty"`
Experimental Script `json:"experimental,omitempty" yaml:"experimental,omitempty"`
// +optional
Pressure Script `json:"pressure,omitempty"`
Pressure Script `json:"pressure,omitempty" yaml:"pressure,omitempty"`
// +optional
Verify Script `json:"verify,omitempty"`
Verify Script `json:"verify,omitempty" yaml:"verify,omitempty"`
}

type EmbedChaos struct {
Expand All @@ -92,15 +95,19 @@ const (
Unknown ChaosCondition = "Unknown"
)

// ShardingSphereChaosStatus defines the actual state of ShardingSphereChaos
type ShardingSphereChaosStatus struct {
ChaosCondition ChaosCondition `json:"chaosCondition"`
Phase ChaosPhase `json:"phase"`
Result Result `json:"result"`
Conditions []*metav1.Condition `json:"condition,omitempty"`
// ChaosStatus defines the actual state of Chaos
type ChaosStatus struct {
// +optional
ChaosCondition ChaosCondition `json:"chaosCondition,omitempty" yaml:"chaosCondition,omitempty"`
// +optional
Phase ChaosPhase `json:"phase,omitempty" yaml:"phase,omitempty"`
// +optional
// Result Result `json:"result,omitempty" yaml:"result,omitempty"`
// +optional
Conditions []*metav1.Condition `json:"conditions,omitempty" yaml:"conditions,omitempty"`
}

// Result represents the result of the ShardingSphereChaos
// Result represents the result of the Chaos
type Result struct {
Steady Msg `json:"steady"`
Chaos Msg `json:"chaos"`
Expand Down Expand Up @@ -154,6 +161,8 @@ type PodChaosParams struct {
CPUStress *CPUStressParams `json:"cpuStress,omitempty"`
//+optional
MemoryStress *MemoryStressParams `json:"memoryStress,omitempty"`
// +optional
PodKill *PodKillParams `json:"podKill,omitempty"`
}

type PodFailureParams struct {
Expand Down Expand Up @@ -182,14 +191,18 @@ type MemoryStressParams struct {
Consumption string `json:"consumption,omitempty"`
}

type PodKillParams struct {
// +optional
GracePeriod int64 `json:"gracePeriod,omitempty"`
}

// NetworkChaosSpec Fields that need to be configured for network type chaos
type NetworkChaosSpec struct {
Source PodSelector `json:",inline"`
Target *PodSelector `json:"target,omitempty"`

// +optional
Action NetworkChaosAction `json:"action"`

// +optional
Duration *string `json:"duration,omitempty"`
// +optional
Expand Down Expand Up @@ -271,5 +284,5 @@ type PodSelector struct {
}

func init() {
SchemeBuilder.Register(&ShardingSphereChaos{}, &ShardingSphereChaosList{})
SchemeBuilder.Register(&Chaos{}, &ChaosList{})
}
Loading