From 243766e3e65fdbe23218f8be1402254b1ae1721c Mon Sep 17 00:00:00 2001 From: ColdsteelRail <574252631@qq.com> Date: Thu, 22 Aug 2024 12:07:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=80=B9refactor-opj-opsStatus=E2=80=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/v1alpha1/operationjob_types.go | 33 ++++++++++++++----- apps/v1alpha1/zz_generated.deepcopy.go | 32 +++++++++++++++++- .../apps.kusionstack.io_operationjobs.yaml | 25 ++++++++++---- 3 files changed, 75 insertions(+), 15 deletions(-) diff --git a/apps/v1alpha1/operationjob_types.go b/apps/v1alpha1/operationjob_types.go index 331ff4c..4ccd241 100644 --- a/apps/v1alpha1/operationjob_types.go +++ b/apps/v1alpha1/operationjob_types.go @@ -17,6 +17,8 @@ limitations under the License. package v1alpha1 import ( + "fmt" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -35,11 +37,10 @@ const ( type OperationProgress string const ( - OperationProgressPending OperationProgress = "Pending" - OperationProgressProcessing OperationProgress = "Processing" - OperationProgressFinishingOpsLifecycle OperationProgress = "FinishingOpsLifecycle" - OperationProgressFailed OperationProgress = "Failed" - OperationProgressSucceeded OperationProgress = "Succeeded" + OperationProgressPending OperationProgress = "Pending" + OperationProgressProcessing OperationProgress = "Processing" + OperationProgressFailed OperationProgress = "Failed" + OperationProgressSucceeded OperationProgress = "Succeeded" ) // OperationJobSpec defines the desired state of OperationJob @@ -127,15 +128,31 @@ type OpsStatus struct { // +optional Progress OperationProgress `json:"progress,omitempty"` - // reason for current operation progress + // extra info of the target operating progress // +optional - Reason string `json:"reason,omitempty"` + ExtraInfo map[string]string `json:"extraInfo,omitempty"` + + // error indicates the error info of progressing + // +optional + Error *CodeReasonMessage `json:"error,omitempty"` +} - // message displays detail of reason +type CodeReasonMessage struct { + // Code is a globally unique identifier + Code string `json:"code,omitempty"` + // A human-readable short word + // +optional + Reason string `json:"reason,omitempty"` + // A human-readable message indicating details about the transition. // +optional Message string `json:"message,omitempty"` } +// Error implements error. +func (c *CodeReasonMessage) Error() string { + return fmt.Sprintf("err: code=%q, reason=%q, message=%q", c.Code, c.Reason, c.Message) +} + // +k8s:openapi-gen=true // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/apps/v1alpha1/zz_generated.deepcopy.go b/apps/v1alpha1/zz_generated.deepcopy.go index cf04c52..94d6e16 100644 --- a/apps/v1alpha1/zz_generated.deepcopy.go +++ b/apps/v1alpha1/zz_generated.deepcopy.go @@ -112,6 +112,22 @@ func (in *ClientConfigBeta1) DeepCopy() *ClientConfigBeta1 { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeReasonMessage) DeepCopyInto(out *CodeReasonMessage) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeReasonMessage. +func (in *CodeReasonMessage) DeepCopy() *CodeReasonMessage { + if in == nil { + return nil + } + out := new(CodeReasonMessage) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CollaSet) DeepCopyInto(out *CollaSet) { *out = *in @@ -433,7 +449,9 @@ func (in *OperationJobStatus) DeepCopyInto(out *OperationJobStatus) { if in.TargetDetails != nil { in, out := &in.TargetDetails, &out.TargetDetails *out = make([]OpsStatus, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } @@ -451,6 +469,18 @@ func (in *OperationJobStatus) DeepCopy() *OperationJobStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OpsStatus) DeepCopyInto(out *OpsStatus) { *out = *in + if in.ExtraInfo != nil { + in, out := &in.ExtraInfo, &out.ExtraInfo + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Error != nil { + in, out := &in.Error, &out.Error + *out = new(CodeReasonMessage) + **out = **in + } return } diff --git a/config/crd/apps/apps.kusionstack.io_operationjobs.yaml b/config/crd/apps/apps.kusionstack.io_operationjobs.yaml index e54058b..3c90691 100644 --- a/config/crd/apps/apps.kusionstack.io_operationjobs.yaml +++ b/config/crd/apps/apps.kusionstack.io_operationjobs.yaml @@ -121,18 +121,31 @@ spec: description: Operation details of the target pods items: properties: - message: - description: message displays detail of reason - type: string + error: + description: error indicates the error info of progressing + properties: + code: + description: Code is a globally unique identifier + type: string + message: + description: A human-readable message indicating details + about the transition. + type: string + reason: + description: A human-readable short word + type: string + type: object + extraInfo: + additionalProperties: + type: string + description: extra info of the target operating progress + type: object name: description: name of the target pod type: string progress: description: operation progress of target pod type: string - reason: - description: reason for current operation progress - type: string type: object type: array totalPodCount: From 25ec3a9073c12e034ffd4cf5666102f80297485a Mon Sep 17 00:00:00 2001 From: ColdsteelRail <574252631@qq.com> Date: Thu, 22 Aug 2024 12:19:22 +0800 Subject: [PATCH 2/2] remove code --- apps/v1alpha1/operationjob_types.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/v1alpha1/operationjob_types.go b/apps/v1alpha1/operationjob_types.go index 4ccd241..a18efbc 100644 --- a/apps/v1alpha1/operationjob_types.go +++ b/apps/v1alpha1/operationjob_types.go @@ -138,8 +138,6 @@ type OpsStatus struct { } type CodeReasonMessage struct { - // Code is a globally unique identifier - Code string `json:"code,omitempty"` // A human-readable short word // +optional Reason string `json:"reason,omitempty"` @@ -150,7 +148,7 @@ type CodeReasonMessage struct { // Error implements error. func (c *CodeReasonMessage) Error() string { - return fmt.Sprintf("err: code=%q, reason=%q, message=%q", c.Code, c.Reason, c.Message) + return fmt.Sprintf("err: reason=%q, message=%q", c.Reason, c.Message) } // +k8s:openapi-gen=true