Skip to content

Commit

Permalink
refactor: refactor Chaos type and PodChaos reconciliation
Browse files Browse the repository at this point in the history
Signed-off-by: mlycore <maxwell92@126.com>
  • Loading branch information
mlycore committed Jun 7, 2023
1 parent 1a10f7c commit 8bf3751
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 200 deletions.
29 changes: 20 additions & 9 deletions shardingsphere-operator/api/v1alpha1/chaos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ type Chaos struct {
type ChaosSpec struct {
EmbedChaos `json:",inline"`

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

type PressureCfg struct {
Expand All @@ -68,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 @@ -95,10 +97,14 @@ const (

// ChaosStatus defines the actual state of Chaos
type ChaosStatus struct {
ChaosCondition ChaosCondition `json:"chaosCondition"`
Phase ChaosPhase `json:"phase"`
Result Result `json:"result"`
Conditions []*metav1.Condition `json:"condition,omitempty"`
// +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 Chaos
Expand Down Expand Up @@ -155,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 All @@ -181,6 +189,9 @@ type MemoryStressParams struct {
Workers int `json:"workers,omitempty"`
//+optional
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
Expand Down
33 changes: 30 additions & 3 deletions shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ var featureGatesHandlers = map[string]FeatureGateHandler{
}
return nil
},
"ShardingSphereChaos": func(mgr manager.Manager) error {
"Chaos": func(mgr manager.Manager) error {
clientset, err := clientset.NewForConfig(mgr.GetConfig())
if err != nil {
return err
}
if err := (&controllers.ShardingSphereChaosReconciler{
if err := (&controllers.ChaosReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: mgr.GetLogger(),
Chaos: sschaos.NewChaos(mgr.GetClient()),
Job: job.NewJob(mgr.GetClient()),
ExecCtrls: make([]*controllers.ExecCtrl, 0),
ConfigMap: configmap.NewConfigMapClient(mgr.GetClient()),
Events: mgr.GetEventRecorderFor("shardingsphere-chaos-controller"),
Events: mgr.GetEventRecorderFor("chaos-controller"),
ClientSet: clientset,
}).SetupWithManager(mgr); err != nil {
logger.Error(err, "unable to create controller", "controller", "ShardingSphereChaos")
logger.Error(err, "unable to create controller", "controller", "Chaos")
return err
}
return nil
Expand Down
Loading

0 comments on commit 8bf3751

Please sign in to comment.