diff --git a/shardingsphere-operator/api/v1alpha1/shardingsphere_chaos_types.go b/shardingsphere-operator/api/v1alpha1/chaos_types.go similarity index 88% rename from shardingsphere-operator/api/v1alpha1/shardingsphere_chaos_types.go rename to shardingsphere-operator/api/v1alpha1/chaos_types.go index 4cfa97f0..9874fe7c 100644 --- a/shardingsphere-operator/api/v1alpha1/shardingsphere_chaos_types.go +++ b/shardingsphere-operator/api/v1alpha1/chaos_types.go @@ -22,28 +22,29 @@ 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"` +// ChaosSpec defines the desired state of Chaos +type ChaosSpec struct { + EmbedChaos `json:",inline"` + + InjectJob JobSpec `json:"injectJob,omitempty"` PressureCfg PressureCfg `json:"pressureCfg"` } @@ -92,15 +93,15 @@ const ( Unknown ChaosCondition = "Unknown" ) -// ShardingSphereChaosStatus defines the actual state of ShardingSphereChaos -type ShardingSphereChaosStatus struct { +// 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"` } -// 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"` @@ -168,7 +169,6 @@ type NetworkChaosSpec struct { // +optional Action NetworkChaosAction `json:"action"` - // +optional Duration *string `json:"duration,omitempty"` // +optional @@ -250,5 +250,5 @@ type PodSelector struct { } func init() { - SchemeBuilder.Register(&ShardingSphereChaos{}, &ShardingSphereChaosList{}) + SchemeBuilder.Register(&Chaos{}, &ChaosList{}) } diff --git a/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go b/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go index 510fb132..68d2b4bd 100644 --- a/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go +++ b/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go @@ -24,8 +24,8 @@ package v1alpha1 import ( "k8s.io/api/autoscaling/v2beta2" - "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -154,6 +154,110 @@ func (in *BootstrapConfig) DeepCopy() *BootstrapConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Chaos) DeepCopyInto(out *Chaos) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Chaos. +func (in *Chaos) DeepCopy() *Chaos { + if in == nil { + return nil + } + out := new(Chaos) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Chaos) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChaosList) DeepCopyInto(out *ChaosList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Chaos, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChaosList. +func (in *ChaosList) DeepCopy() *ChaosList { + if in == nil { + return nil + } + out := new(ChaosList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ChaosList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChaosSpec) DeepCopyInto(out *ChaosSpec) { + *out = *in + in.EmbedChaos.DeepCopyInto(&out.EmbedChaos) + out.InjectJob = in.InjectJob + in.PressureCfg.DeepCopyInto(&out.PressureCfg) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChaosSpec. +func (in *ChaosSpec) DeepCopy() *ChaosSpec { + if in == nil { + return nil + } + out := new(ChaosSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChaosStatus) DeepCopyInto(out *ChaosStatus) { + *out = *in + out.Result = in.Result + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]*v1.Condition, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(v1.Condition) + (*in).DeepCopyInto(*out) + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChaosStatus. +func (in *ChaosStatus) DeepCopy() *ChaosStatus { + if in == nil { + return nil + } + out := new(ChaosStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterConfig) DeepCopyInto(out *ClusterConfig) { *out = *in @@ -351,7 +455,7 @@ func (in *ComputeNodeSpec) DeepCopyInto(out *ComputeNodeSpec) { } if in.Selector != nil { in, out := &in.Selector, &out.Selector - *out = new(metav1.LabelSelector) + *out = new(v1.LabelSelector) (*in).DeepCopyInto(*out) } if in.Probes != nil { @@ -361,12 +465,12 @@ func (in *ComputeNodeSpec) DeepCopyInto(out *ComputeNodeSpec) { } if in.ImagePullSecrets != nil { in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]v1.LocalObjectReference, len(*in)) + *out = make([]corev1.LocalObjectReference, len(*in)) copy(*out, *in) } if in.Env != nil { in, out := &in.Env, &out.Env - *out = make([]v1.EnvVar, len(*in)) + *out = make([]corev1.EnvVar, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -649,7 +753,7 @@ func (in *LoadBalancerStatus) DeepCopyInto(out *LoadBalancerStatus) { *out = *in if in.Ingress != nil { in, out := &in.Ingress, &out.Ingress - *out = make([]v1.LoadBalancerIngress, len(*in)) + *out = make([]corev1.LoadBalancerIngress, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -1001,7 +1105,7 @@ func (in *PodSelector) DeepCopyInto(out *PodSelector) { } if in.ExpressionSelectors != nil { in, out := &in.ExpressionSelectors, &out.ExpressionSelectors - *out = make([]metav1.LabelSelectorRequirement, len(*in)) + *out = make([]v1.LabelSelectorRequirement, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -1172,17 +1276,17 @@ func (in *ProxyProbe) DeepCopyInto(out *ProxyProbe) { *out = *in if in.LivenessProbe != nil { in, out := &in.LivenessProbe, &out.LivenessProbe - *out = new(v1.Probe) + *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } if in.ReadinessProbe != nil { in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(v1.Probe) + *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } if in.StartupProbe != nil { in, out := &in.StartupProbe, &out.StartupProbe - *out = new(v1.Probe) + *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } } @@ -1208,7 +1312,7 @@ func (in *ProxySpec) DeepCopyInto(out *ProxySpec) { } if in.ImagePullSecrets != nil { in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]v1.LocalObjectReference, len(*in)) + *out = make([]corev1.LocalObjectReference, len(*in)) copy(*out, *in) } if in.MySQLDriver != nil { @@ -1219,17 +1323,17 @@ func (in *ProxySpec) DeepCopyInto(out *ProxySpec) { in.Resources.DeepCopyInto(&out.Resources) if in.LivenessProbe != nil { in, out := &in.LivenessProbe, &out.LivenessProbe - *out = new(v1.Probe) + *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } if in.ReadinessProbe != nil { in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(v1.Probe) + *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } if in.StartupProbe != nil { in, out := &in.StartupProbe, &out.StartupProbe - *out = new(v1.Probe) + *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } } @@ -1350,7 +1454,7 @@ func (in *Service) DeepCopyInto(out *Service) { *out = *in if in.Ports != nil { in, out := &in.Ports, &out.Ports - *out = make([]v1.ServicePort, len(*in)) + *out = make([]corev1.ServicePort, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -1382,110 +1486,6 @@ func (in *ServiceType) DeepCopy() *ServiceType { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ShardingSphereChaos) DeepCopyInto(out *ShardingSphereChaos) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereChaos. -func (in *ShardingSphereChaos) DeepCopy() *ShardingSphereChaos { - if in == nil { - return nil - } - out := new(ShardingSphereChaos) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ShardingSphereChaos) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ShardingSphereChaosList) DeepCopyInto(out *ShardingSphereChaosList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]ShardingSphereChaos, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereChaosList. -func (in *ShardingSphereChaosList) DeepCopy() *ShardingSphereChaosList { - if in == nil { - return nil - } - out := new(ShardingSphereChaosList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ShardingSphereChaosList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ShardingSphereChaosSpec) DeepCopyInto(out *ShardingSphereChaosSpec) { - *out = *in - out.InjectJob = in.InjectJob - in.EmbedChaos.DeepCopyInto(&out.EmbedChaos) - in.PressureCfg.DeepCopyInto(&out.PressureCfg) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereChaosSpec. -func (in *ShardingSphereChaosSpec) DeepCopy() *ShardingSphereChaosSpec { - if in == nil { - return nil - } - out := new(ShardingSphereChaosSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ShardingSphereChaosStatus) DeepCopyInto(out *ShardingSphereChaosStatus) { - *out = *in - out.Result = in.Result - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]*metav1.Condition, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(metav1.Condition) - (*in).DeepCopyInto(*out) - } - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereChaosStatus. -func (in *ShardingSphereChaosStatus) DeepCopy() *ShardingSphereChaosStatus { - if in == nil { - return nil - } - out := new(ShardingSphereChaosStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ShardingSphereProxy) DeepCopyInto(out *ShardingSphereProxy) { *out = *in diff --git a/shardingsphere-operator/pkg/controllers/shardingsphere_chaos_controller.go b/shardingsphere-operator/pkg/controllers/shardingsphere_chaos_controller.go index 535ec488..f8b504a7 100644 --- a/shardingsphere-operator/pkg/controllers/shardingsphere_chaos_controller.go +++ b/shardingsphere-operator/pkg/controllers/shardingsphere_chaos_controller.go @@ -126,7 +126,7 @@ func (r *ShardingSphereChaosReconciler) Reconcile(ctx context.Context, req ctrl. return ctrl.Result{RequeueAfter: defaultRequeueTime}, nil } -func (r *ShardingSphereChaosReconciler) reconcilePressure(ctx context.Context, chao *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) reconcilePressure(ctx context.Context, chao *v1alpha1.Chaos) error { if chao.Status.Phase == "" { return nil @@ -153,7 +153,7 @@ func (r *ShardingSphereChaosReconciler) reconcilePressure(ctx context.Context, c return nil } -func (r *ShardingSphereChaosReconciler) reconcileStatus(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) reconcileStatus(ctx context.Context, chaos *v1alpha1.Chaos) error { cur := chaos.Status.DeepCopy() @@ -175,7 +175,7 @@ func (r *ShardingSphereChaosReconciler) reconcileStatus(ctx context.Context, cha return r.Status().Update(ctx, chaos) } -func updateCondition(chaos *v1alpha1.ShardingSphereChaos) { +func updateCondition(chaos *v1alpha1.Chaos) { phase := chaos.Status.Phase for i := range chaos.Status.Conditions { @@ -190,7 +190,7 @@ func updateCondition(chaos *v1alpha1.ShardingSphereChaos) { } } -func (r *ShardingSphereChaosReconciler) updatePhaseExec(chaos *v1alpha1.ShardingSphereChaos) { +func (r *ShardingSphereChaosReconciler) updatePhaseExec(chaos *v1alpha1.Chaos) { exec := r.getNeedExec(chaos) //because the goroutine asynchronous,we cant check it start immediately or not @@ -240,7 +240,7 @@ func generateMsgFromExec(exec *pressure.Pressure) *v1alpha1.Msg { return &msg } -func getExecName(chao *v1alpha1.ShardingSphereChaos) string { +func getExecName(chao *v1alpha1.Chaos) string { var execName string nameSpacedName := types.NamespacedName{Namespace: chao.Namespace, Name: chao.Name} @@ -258,7 +258,7 @@ func makeExecName(namespacedName types.NamespacedName, execType string) string { return fmt.Sprintf("%s-%s-%s", namespacedName.Namespace, namespacedName.Name, execType) } -func (r *ShardingSphereChaosReconciler) getNeedExec(chao *v1alpha1.ShardingSphereChaos) *pressure.Pressure { +func (r *ShardingSphereChaosReconciler) getNeedExec(chao *v1alpha1.Chaos) *pressure.Pressure { jobName := getExecName(chao) //if pressure do not exist,run it @@ -271,14 +271,14 @@ func (r *ShardingSphereChaosReconciler) getNeedExec(chao *v1alpha1.ShardingSpher return nil } -func (r *ShardingSphereChaosReconciler) getRuntimeChaos(ctx context.Context, name types.NamespacedName) (*v1alpha1.ShardingSphereChaos, error) { - var rt = &v1alpha1.ShardingSphereChaos{} +func (r *ShardingSphereChaosReconciler) getRuntimeChaos(ctx context.Context, name types.NamespacedName) (*v1alpha1.Chaos, error) { + var rt = &v1alpha1.Chaos{} err := r.Get(ctx, name, rt) return rt, err } // nolint:nestif -func (r *ShardingSphereChaosReconciler) finalize(ctx context.Context, ssChaos *v1alpha1.ShardingSphereChaos) (ctrl.Result, error) { +func (r *ShardingSphereChaosReconciler) finalize(ctx context.Context, ssChaos *v1alpha1.Chaos) (ctrl.Result, error) { namespacedName := types.NamespacedName{ Namespace: ssChaos.Namespace, Name: ssChaos.Name, @@ -296,7 +296,7 @@ func (r *ShardingSphereChaosReconciler) finalize(ctx context.Context, ssChaos *v return ctrl.Result{}, nil } -func (r *ShardingSphereChaosReconciler) deleteExternalResources(ctx context.Context, chao *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) deleteExternalResources(ctx context.Context, chao *v1alpha1.Chaos) error { nameSpacedName := types.NamespacedName{Namespace: chao.Namespace, Name: chao.Name} if chao.Spec.EmbedChaos.PodChaos != nil { if err := r.deletePodChaos(ctx, nameSpacedName); err != nil { @@ -359,7 +359,7 @@ func (r *ShardingSphereChaosReconciler) deleteNetworkChaos(ctx context.Context, return nil } -func (r *ShardingSphereChaosReconciler) reconcileChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) reconcileChaos(ctx context.Context, chaos *v1alpha1.Chaos) error { logger := r.Log.WithValues("reconcile shardingspherechaos", fmt.Sprintf("%s/%s", chaos.Namespace, chaos.Name)) if chaos.Status.Phase == "" || chaos.Status.Phase == v1alpha1.BeforeSteady || chaos.Status.Phase == v1alpha1.AfterSteady { @@ -387,7 +387,7 @@ func (r *ShardingSphereChaosReconciler) reconcileChaos(ctx context.Context, chao return nil } -func (r *ShardingSphereChaosReconciler) reconcilePodChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos, namespacedName types.NamespacedName) error { +func (r *ShardingSphereChaosReconciler) reconcilePodChaos(ctx context.Context, chaos *v1alpha1.Chaos, namespacedName types.NamespacedName) error { pc, err := r.getPodChaosByNamespacedName(ctx, namespacedName) if err != nil { return err @@ -407,7 +407,7 @@ func (r *ShardingSphereChaosReconciler) getPodChaosByNamespacedName(ctx context. return pc, nil } -func (r *ShardingSphereChaosReconciler) createPodChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) createPodChaos(ctx context.Context, chaos *v1alpha1.Chaos) error { err := r.Chaos.CreatePodChaos(ctx, chaos) if err != nil { return err @@ -416,7 +416,7 @@ func (r *ShardingSphereChaosReconciler) createPodChaos(ctx context.Context, chao return nil } -func (r *ShardingSphereChaosReconciler) updatePodChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos, podChaos chaosmesh.PodChaos) error { +func (r *ShardingSphereChaosReconciler) updatePodChaos(ctx context.Context, chaos *v1alpha1.Chaos, podChaos chaosmesh.PodChaos) error { err := r.Chaos.UpdatePodChaos(ctx, podChaos, chaos) if err != nil { return err @@ -425,7 +425,7 @@ func (r *ShardingSphereChaosReconciler) updatePodChaos(ctx context.Context, chao return nil } -func (r *ShardingSphereChaosReconciler) reconcileNetworkChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos, namespacedName types.NamespacedName) error { +func (r *ShardingSphereChaosReconciler) reconcileNetworkChaos(ctx context.Context, chaos *v1alpha1.Chaos, namespacedName types.NamespacedName) error { nc, err := r.getNetworkChaosByNamespacedName(ctx, namespacedName) if err != nil { return err @@ -437,7 +437,7 @@ func (r *ShardingSphereChaosReconciler) reconcileNetworkChaos(ctx context.Contex return r.createNetworkChaos(ctx, chaos) } -func (r *ShardingSphereChaosReconciler) updateNetWorkChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos, networkChaos chaosmesh.NetworkChaos) error { +func (r *ShardingSphereChaosReconciler) updateNetWorkChaos(ctx context.Context, chaos *v1alpha1.Chaos, networkChaos chaosmesh.NetworkChaos) error { err := r.Chaos.UpdateNetworkChaos(ctx, networkChaos, chaos) if err != nil { return err @@ -446,7 +446,7 @@ func (r *ShardingSphereChaosReconciler) updateNetWorkChaos(ctx context.Context, return nil } -func (r *ShardingSphereChaosReconciler) createNetworkChaos(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) createNetworkChaos(ctx context.Context, chaos *v1alpha1.Chaos) error { err := r.Chaos.CreateNetworkChaos(ctx, chaos) if err != nil { return err @@ -456,7 +456,7 @@ func (r *ShardingSphereChaosReconciler) createNetworkChaos(ctx context.Context, return nil } -func (r *ShardingSphereChaosReconciler) reconcileConfigMap(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) reconcileConfigMap(ctx context.Context, chaos *v1alpha1.Chaos) error { namespaceName := types.NamespacedName{ Namespace: chaos.Namespace, Name: chaos.Name, @@ -482,7 +482,7 @@ func (r *ShardingSphereChaosReconciler) reconcileConfigMap(ctx context.Context, return nil } -func setDefaultStatus(chaos *v1alpha1.ShardingSphereChaos) { +func setDefaultStatus(chaos *v1alpha1.Chaos) { if chaos.Status.Phase == "" { chaos.Status.Phase = v1alpha1.BeforeSteady @@ -518,7 +518,7 @@ func setDefaultStatus(chaos *v1alpha1.ShardingSphereChaos) { } } -func (r *ShardingSphereChaosReconciler) updateChaosCondition(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) updateChaosCondition(ctx context.Context, chaos *v1alpha1.Chaos) error { namespacedName := types.NamespacedName{ Namespace: chaos.Namespace, Name: chaos.Name, @@ -560,7 +560,7 @@ func (r *ShardingSphereChaosReconciler) getConfigMapByNamespacedName(ctx context return config, nil } -func (r *ShardingSphereChaosReconciler) updateConfigMap(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos, cur *corev1.ConfigMap) error { +func (r *ShardingSphereChaosReconciler) updateConfigMap(ctx context.Context, chaos *v1alpha1.Chaos, cur *corev1.ConfigMap) error { // exp := sschaos.UpdateShardingSphereChaosConfigMap(chao, cur) exp := r.ConfigMap.Build(ctx, chaos) exp.ObjectMeta = cur.ObjectMeta @@ -570,7 +570,7 @@ func (r *ShardingSphereChaosReconciler) updateConfigMap(ctx context.Context, cha return r.ConfigMap.Update(ctx, exp) } -func (r *ShardingSphereChaosReconciler) createConfigMap(ctx context.Context, chaos *v1alpha1.ShardingSphereChaos) error { +func (r *ShardingSphereChaosReconciler) createConfigMap(ctx context.Context, chaos *v1alpha1.Chaos) error { cm := r.ConfigMap.Build(ctx, chaos) if err := ctrl.SetControllerReference(chaos, cm, r.Scheme); err != nil { return err @@ -587,7 +587,7 @@ func (r *ShardingSphereChaosReconciler) createConfigMap(ctx context.Context, cha // SetupWithManager sets up the controller with the Manager. func (r *ShardingSphereChaosReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&v1alpha1.ShardingSphereChaos{}). + For(&v1alpha1.Chaos{}). Owns(&corev1.ConfigMap{}). Owns(&batchV1.Job{}). Complete(r) diff --git a/shardingsphere-operator/pkg/kubernetes/chaosmesh/builder.go b/shardingsphere-operator/pkg/kubernetes/chaosmesh/builder.go index 5d895ae6..a0a84ebd 100644 --- a/shardingsphere-operator/pkg/kubernetes/chaosmesh/builder.go +++ b/shardingsphere-operator/pkg/kubernetes/chaosmesh/builder.go @@ -56,7 +56,7 @@ var ( type GenericChaos interface{} -func ConvertChaosStatus(ctx context.Context, ssChaos *v1alpha1.ShardingSphereChaos, chaos GenericChaos) v1alpha1.ChaosCondition { +func ConvertChaosStatus(ctx context.Context, ssChaos *v1alpha1.Chaos, chaos GenericChaos) v1alpha1.ChaosCondition { var status chaosmeshv1alpha1.ChaosStatus if ssChaos.Spec.EmbedChaos.PodChaos != nil { if podChao, ok := chaos.(*chaosmeshv1alpha1.PodChaos); ok && podChao != nil { @@ -100,7 +100,7 @@ func judgeCondition(condition map[chaosmeshv1alpha1.ChaosConditionType]bool, pha return v1alpha1.Unknown } -func NewPodChaos(ssChao *v1alpha1.ShardingSphereChaos) (PodChaos, error) { +func NewPodChaos(ssChao *v1alpha1.Chaos) (PodChaos, error) { pcb := NewPodChaosBuilder() pcb.SetName(ssChao.Name).SetNamespace(ssChao.Namespace).SetLabels(ssChao.Labels) @@ -156,7 +156,7 @@ func getAnnotation(anno map[string]string, k string) string { return "" } -func NewNetworkChaos(ssChao *v1alpha1.ShardingSphereChaos) (NetworkChaos, error) { +func NewNetworkChaos(ssChao *v1alpha1.Chaos) (NetworkChaos, error) { ncb := NewNetworkChaosBuilder() ncb.SetName(ssChao.Name).SetNamespace(ssChao.Namespace).SetLabels(ssChao.Labels) diff --git a/shardingsphere-operator/pkg/kubernetes/chaosmesh/chaosmesh.go b/shardingsphere-operator/pkg/kubernetes/chaosmesh/chaosmesh.go index 9e1d3bc8..676aadcf 100644 --- a/shardingsphere-operator/pkg/kubernetes/chaosmesh/chaosmesh.go +++ b/shardingsphere-operator/pkg/kubernetes/chaosmesh/chaosmesh.go @@ -57,8 +57,8 @@ type chaosClient struct { // Builder build Chaos from different parameters type Builder interface { - NewPodChaos(context.Context, *v1alpha1.ShardingSphereChaos) PodChaos - NewNetworkChaos(context.Context, *v1alpha1.ShardingSphereChaos) NetworkChaos + NewPodChaos(context.Context, *v1alpha1.Chaos) PodChaos + NewNetworkChaos(context.Context, *v1alpha1.Chaos) NetworkChaos } // Getter get Chaos from different parameters @@ -69,12 +69,12 @@ type Getter interface { // Setter set Chaos from different parameters type Setter interface { - CreatePodChaos(context.Context, *v1alpha1.ShardingSphereChaos) error - UpdatePodChaos(context.Context, PodChaos, *v1alpha1.ShardingSphereChaos) error + CreatePodChaos(context.Context, *v1alpha1.Chaos) error + UpdatePodChaos(context.Context, PodChaos, *v1alpha1.Chaos) error DeletePodChaos(context.Context, PodChaos) error - CreateNetworkChaos(context.Context, *v1alpha1.ShardingSphereChaos) error - UpdateNetworkChaos(context.Context, NetworkChaos, *v1alpha1.ShardingSphereChaos) error + CreateNetworkChaos(context.Context, *v1alpha1.Chaos) error + UpdateNetworkChaos(context.Context, NetworkChaos, *v1alpha1.Chaos) error DeleteNetworkChaos(context.Context, NetworkChaos) error } @@ -112,12 +112,12 @@ func (cg getter) GetNetworkChaosByNamespacedName(ctx context.Context, namespaced type builder struct{} -func (blder builder) NewPodChaos(ctx context.Context, sschaos *v1alpha1.ShardingSphereChaos) PodChaos { +func (blder builder) NewPodChaos(ctx context.Context, sschaos *v1alpha1.Chaos) PodChaos { pc, _ := NewPodChaos(sschaos) return pc } -func (blder builder) NewNetworkChaos(ctx context.Context, sschaos *v1alpha1.ShardingSphereChaos) NetworkChaos { +func (blder builder) NewNetworkChaos(ctx context.Context, sschaos *v1alpha1.Chaos) NetworkChaos { nc, _ := NewNetworkChaos(sschaos) return nc } @@ -127,7 +127,7 @@ type setter struct { } // CreatePodChaos creates a new pod chaos -func (cs setter) CreatePodChaos(ctx context.Context, sschaos *v1alpha1.ShardingSphereChaos) error { +func (cs setter) CreatePodChaos(ctx context.Context, sschaos *v1alpha1.Chaos) error { pc, err := NewPodChaos(sschaos) if err != nil { return err @@ -136,7 +136,7 @@ func (cs setter) CreatePodChaos(ctx context.Context, sschaos *v1alpha1.ShardingS } // UpdatePodChaos updates a pod chaos -func (cs setter) UpdatePodChaos(ctx context.Context, podChaos PodChaos, sschaos *v1alpha1.ShardingSphereChaos) error { +func (cs setter) UpdatePodChaos(ctx context.Context, podChaos PodChaos, sschaos *v1alpha1.Chaos) error { pc, err := NewPodChaos(sschaos) if err != nil { return err @@ -171,7 +171,7 @@ func (cs setter) DeletePodChaos(ctx context.Context, chao PodChaos) error { } // CreateNetworkChaos creates a new network chaos -func (cs setter) CreateNetworkChaos(ctx context.Context, sschaos *v1alpha1.ShardingSphereChaos) error { +func (cs setter) CreateNetworkChaos(ctx context.Context, sschaos *v1alpha1.Chaos) error { nc, err := NewNetworkChaos(sschaos) if err != nil { return err @@ -180,7 +180,7 @@ func (cs setter) CreateNetworkChaos(ctx context.Context, sschaos *v1alpha1.Shard } // UpdateNetworkChaos updates a network chaos -func (cs setter) UpdateNetworkChaos(ctx context.Context, networkChaos NetworkChaos, sschaos *v1alpha1.ShardingSphereChaos) error { +func (cs setter) UpdateNetworkChaos(ctx context.Context, networkChaos NetworkChaos, sschaos *v1alpha1.Chaos) error { pc, err := NewNetworkChaos(sschaos) if err != nil { return err diff --git a/shardingsphere-operator/pkg/kubernetes/configmap/builders.go b/shardingsphere-operator/pkg/kubernetes/configmap/builders.go index 73caaf64..1241be33 100644 --- a/shardingsphere-operator/pkg/kubernetes/configmap/builders.go +++ b/shardingsphere-operator/pkg/kubernetes/configmap/builders.go @@ -99,7 +99,7 @@ func NewConfigMap(obj runtime.Object) *corev1.ConfigMap { var ( cn *v1alpha1.ComputeNode - sc *v1alpha1.ShardingSphereChaos + sc *v1alpha1.Chaos meta metav1.Object ok bool ) @@ -109,7 +109,7 @@ func NewConfigMap(obj runtime.Object) *corev1.ConfigMap { return factory.NewConfigMapBuilder(meta, gvk).Build() } - if sc, ok = obj.(*v1alpha1.ShardingSphereChaos); ok { + if sc, ok = obj.(*v1alpha1.Chaos); ok { meta = sc.GetObjectMeta() return factory.NewConfigMapBuilder(meta, gvk).Build() } @@ -264,10 +264,10 @@ func (c *shardingsphereChaosConfigMapBuilder) SetBinaryData(binary map[string][] // Build builds the ConfigMap func (c *shardingsphereChaosConfigMapBuilder) Build() *corev1.ConfigMap { var ( - chaos *v1alpha1.ShardingSphereChaos + chaos *v1alpha1.Chaos ok bool ) - if chaos, ok = c.obj.(*v1alpha1.ShardingSphereChaos); !ok { + if chaos, ok = c.obj.(*v1alpha1.Chaos); !ok { return nil } c.SetName(chaos.Name).SetNamespace(chaos.Namespace).SetLabels(chaos.Labels).SetAnnotations(chaos.Annotations) @@ -294,7 +294,7 @@ const ( ) // UpdateConfigMap returns a new ConfigMap -func UpdateShardingSphereChaosConfigMap(ssChaos *v1alpha1.ShardingSphereChaos, cur *corev1.ConfigMap) *corev1.ConfigMap { +func UpdateShardingSphereChaosConfigMap(ssChaos *v1alpha1.Chaos, cur *corev1.ConfigMap) *corev1.ConfigMap { exp := &corev1.ConfigMap{} exp.ObjectMeta = cur.ObjectMeta exp.Labels = cur.Labels diff --git a/shardingsphere-operator/pkg/reconcile/shardingspherechaos/job.go b/shardingsphere-operator/pkg/reconcile/shardingspherechaos/job.go index 2c6fd0c5..36811f37 100644 --- a/shardingsphere-operator/pkg/reconcile/shardingspherechaos/job.go +++ b/shardingsphere-operator/pkg/reconcile/shardingspherechaos/job.go @@ -63,7 +63,7 @@ func MakeJobName(name string, requirement JobType) string { return fmt.Sprintf("%s-%s", name, string(requirement)) } -func NewJob(ssChaos *v1alpha1.ShardingSphereChaos, requirement JobType) (*v1.Job, error) { +func NewJob(ssChaos *v1alpha1.Chaos, requirement JobType) (*v1.Job, error) { jbd := NewJobBuilder() jbd.SetNamespace(ssChaos.Namespace).SetLabels(ssChaos.Labels).SetName(MakeJobName(ssChaos.Name, requirement)) @@ -143,7 +143,7 @@ func MustInt64(s string) (int64, error) { return int64(v), nil } -func IsJobChanged(ssChaos *v1alpha1.ShardingSphereChaos, requirement JobType, cur *v1.Job) (bool, error) { +func IsJobChanged(ssChaos *v1alpha1.Chaos, requirement JobType, cur *v1.Job) (bool, error) { now, err := NewJob(ssChaos, requirement) if err != nil { return false, err