From 6018665d85cbef34f7c0be77588577bb512c7188 Mon Sep 17 00:00:00 2001 From: chris-sun-star Date: Tue, 14 Jan 2025 06:56:11 +0000 Subject: [PATCH] add task status to output, run validate upgrade job using method in utils --- api/v1alpha1/obcluster_types.go | 1 + api/v1alpha1/obclusteroperation_types.go | 1 + api/v1alpha1/observer_types.go | 1 + api/v1alpha1/obtenant_types.go | 3 + api/v1alpha1/obtenantbackuppolicy_types.go | 1 + api/v1alpha1/obtenantoperation_types.go | 3 + api/v1alpha1/obzone_types.go | 1 + ...ase.oceanbase.com_obclusteroperations.yaml | 4 ++ .../oceanbase.oceanbase.com_obclusters.yaml | 4 ++ .../oceanbase.oceanbase.com_observers.yaml | 4 ++ ....oceanbase.com_obtenantbackuppolicies.yaml | 4 ++ ...base.oceanbase.com_obtenantoperations.yaml | 12 ++++ .../oceanbase.oceanbase.com_obtenants.yaml | 12 ++++ .../oceanbase.oceanbase.com_obzones.yaml | 4 ++ deploy/operator.yaml | 44 +++++++++++++ internal/const/oceanbase/oceanbase.go | 3 +- internal/resource/obcluster/obcluster_task.go | 62 ++----------------- 17 files changed, 107 insertions(+), 57 deletions(-) diff --git a/api/v1alpha1/obcluster_types.go b/api/v1alpha1/obcluster_types.go index 2a4b7e268..0db8cb5ee 100644 --- a/api/v1alpha1/obcluster_types.go +++ b/api/v1alpha1/obcluster_types.go @@ -66,6 +66,7 @@ type OBClusterStatus struct { //+kubebuilder:printcolumn:name="Storage",type="string",JSONPath=".spec.observer.storage",priority=1 //+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 //+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBCluster is the Schema for the obclusters API type OBCluster struct { diff --git a/api/v1alpha1/obclusteroperation_types.go b/api/v1alpha1/obclusteroperation_types.go index edb8e79a7..9fa0408c3 100644 --- a/api/v1alpha1/obclusteroperation_types.go +++ b/api/v1alpha1/obclusteroperation_types.go @@ -109,6 +109,7 @@ type OBClusterSnapshot struct { //+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" //+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 //+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBClusterOperation is the Schema for the obclusteroperations API type OBClusterOperation struct { diff --git a/api/v1alpha1/observer_types.go b/api/v1alpha1/observer_types.go index f7e8fadb5..dd070fd22 100644 --- a/api/v1alpha1/observer_types.go +++ b/api/v1alpha1/observer_types.go @@ -74,6 +74,7 @@ type OBServerStatus struct { //+kubebuilder:printcolumn:name="OBStatus",type="string",JSONPath=".status.obStatus",priority=1 //+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 //+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBServer is the Schema for the observers API type OBServer struct { diff --git a/api/v1alpha1/obtenant_types.go b/api/v1alpha1/obtenant_types.go index c0f0a7040..2d023a4f1 100644 --- a/api/v1alpha1/obtenant_types.go +++ b/api/v1alpha1/obtenant_types.go @@ -196,6 +196,9 @@ type TenantRecordInfo struct { //+kubebuilder:printcolumn:name="primaryZone",type="string",JSONPath=".status.tenantRecordInfo.primaryZone",priority=1 //+kubebuilder:printcolumn:name="poolList",type="string",JSONPath=".status.tenantRecordInfo.poolList",priority=1 //+kubebuilder:printcolumn:name="charset",type="string",JSONPath=".status.tenantRecordInfo.charset",priority=1 +//+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 +//+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBTenant is the Schema for the obtenants API type OBTenant struct { diff --git a/api/v1alpha1/obtenantbackuppolicy_types.go b/api/v1alpha1/obtenantbackuppolicy_types.go index bf8092f3c..1097f0869 100644 --- a/api/v1alpha1/obtenantbackuppolicy_types.go +++ b/api/v1alpha1/obtenantbackuppolicy_types.go @@ -112,6 +112,7 @@ func (in *OBTenantBackupPolicyStatus) DeepCopy() *OBTenantBackupPolicyStatus { //+kubebuilder:resource:shortName=obtbp //+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 //+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBTenantBackupPolicy is the Schema for the obtenantbackuppolicies API type OBTenantBackupPolicy struct { diff --git a/api/v1alpha1/obtenantoperation_types.go b/api/v1alpha1/obtenantoperation_types.go index d10225fe2..b987c83b0 100644 --- a/api/v1alpha1/obtenantoperation_types.go +++ b/api/v1alpha1/obtenantoperation_types.go @@ -81,6 +81,9 @@ type OBTenantOperationStatus struct { //+kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=".status.primaryTenant.spec.obcluster" //+kubebuilder:printcolumn:name="PrimaryTenant",type=string,JSONPath=".status.primaryTenant.spec.tenantName" //+kubebuilder:printcolumn:name="SecondaryTenant",type=string,JSONPath=".status.secondaryTenant.spec.tenantName",priority=1 +//+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 +//+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBTenantOperation is the Schema for the obtenantoperations API type OBTenantOperation struct { diff --git a/api/v1alpha1/obzone_types.go b/api/v1alpha1/obzone_types.go index 06e1ff86d..03db4a1b0 100644 --- a/api/v1alpha1/obzone_types.go +++ b/api/v1alpha1/obzone_types.go @@ -60,6 +60,7 @@ type OBZoneStatus struct { //+kubebuilder:printcolumn:name="ZoneName",type="string",JSONPath=".spec.topology.zone" //+kubebuilder:printcolumn:name="Tasks",type="string",JSONPath=".status.operationContext.tasks",priority=1 //+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task",priority=1 +//+kubebuilder:printcolumn:name="TaskStatus",type="string",JSONPath=".status.operationContext.taskStatus",priority=1 // OBZone is the Schema for the obzones API type OBZone struct { diff --git a/config/crd/bases/oceanbase.oceanbase.com_obclusteroperations.yaml b/config/crd/bases/oceanbase.oceanbase.com_obclusteroperations.yaml index 36cbc1c64..4bf86f322 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_obclusteroperations.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_obclusteroperations.yaml @@ -32,6 +32,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml b/config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml index 8a6427502..adf15315b 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml @@ -40,6 +40,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/oceanbase.oceanbase.com_observers.yaml b/config/crd/bases/oceanbase.oceanbase.com_observers.yaml index 1bea864cc..e8f9845bd 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_observers.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_observers.yaml @@ -42,6 +42,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/oceanbase.oceanbase.com_obtenantbackuppolicies.yaml b/config/crd/bases/oceanbase.oceanbase.com_obtenantbackuppolicies.yaml index b0e0a4218..26be0a1a0 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_obtenantbackuppolicies.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_obtenantbackuppolicies.yaml @@ -46,6 +46,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/oceanbase.oceanbase.com_obtenantoperations.yaml b/config/crd/bases/oceanbase.oceanbase.com_obtenantoperations.yaml index 53a2a2d92..2a33e5b7c 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_obtenantoperations.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_obtenantoperations.yaml @@ -34,6 +34,18 @@ spec: name: SecondaryTenant priority: 1 type: string + - jsonPath: .status.operationContext.tasks + name: Tasks + priority: 1 + type: string + - jsonPath: .status.operationContext.task + name: Task + priority: 1 + type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/oceanbase.oceanbase.com_obtenants.yaml b/config/crd/bases/oceanbase.oceanbase.com_obtenants.yaml index 852d5ce4c..f0c328cf1 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_obtenants.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_obtenants.yaml @@ -46,6 +46,18 @@ spec: name: charset priority: 1 type: string + - jsonPath: .status.operationContext.tasks + name: Tasks + priority: 1 + type: string + - jsonPath: .status.operationContext.task + name: Task + priority: 1 + type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/oceanbase.oceanbase.com_obzones.yaml b/config/crd/bases/oceanbase.oceanbase.com_obzones.yaml index 90ab407cd..7c61bfe32 100644 --- a/config/crd/bases/oceanbase.oceanbase.com_obzones.yaml +++ b/config/crd/bases/oceanbase.oceanbase.com_obzones.yaml @@ -35,6 +35,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/deploy/operator.yaml b/deploy/operator.yaml index 70b3e768d..2d5b254f7 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -141,6 +141,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -6814,6 +6818,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -10520,6 +10528,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -13627,6 +13639,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -15066,6 +15082,18 @@ spec: name: SecondaryTenant priority: 1 type: string + - jsonPath: .status.operationContext.tasks + name: Tasks + priority: 1 + type: string + - jsonPath: .status.operationContext.task + name: Task + priority: 1 + type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -16829,6 +16857,18 @@ spec: name: charset priority: 1 type: string + - jsonPath: .status.operationContext.tasks + name: Tasks + priority: 1 + type: string + - jsonPath: .status.operationContext.task + name: Task + priority: 1 + type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -17590,6 +17630,10 @@ spec: name: Task priority: 1 type: string + - jsonPath: .status.operationContext.taskStatus + name: TaskStatus + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/internal/const/oceanbase/oceanbase.go b/internal/const/oceanbase/oceanbase.go index a49f5ff0f..b74eeee47 100644 --- a/internal/const/oceanbase/oceanbase.go +++ b/internal/const/oceanbase/oceanbase.go @@ -82,5 +82,6 @@ const ( ) const ( - CmdVersion = "rpm -q --queryformat '%{VERSION}-%{RELEASE}' oceanbase-ce | sed 's/\\.[^.]*$//'" + CmdVersion = "rpm -q --queryformat '%{VERSION}-%{RELEASE}' oceanbase-ce | sed 's/\\.[^.]*$//'" + CmdUpgradeValidateTemplate = "/home/admin/oceanbase/bin/oceanbase-helper upgrade validate -s %s" ) diff --git a/internal/resource/obcluster/obcluster_task.go b/internal/resource/obcluster/obcluster_task.go index 0b7185588..9d7f29296 100644 --- a/internal/resource/obcluster/obcluster_task.go +++ b/internal/resource/obcluster/obcluster_task.go @@ -344,64 +344,14 @@ func ValidateUpgradeInfo(m *OBClusterManager) tasktypes.TaskError { if err != nil { return errors.Wrapf(err, "Failed to get version of obcluster %s", m.OBCluster.Name) } - // Get target version and patch - jobName := fmt.Sprintf("%s-%s", "oceanbase-upgrade", rand.String(6)) - var backoffLimit int32 - var ttl int32 = 300 - container := corev1.Container{ - Name: "ob-upgrade-validator", - Image: m.OBCluster.Spec.OBServerTemplate.Image, - Command: []string{"bash", "-c", fmt.Sprintf("/home/admin/oceanbase/bin/oceanbase-helper upgrade validate -s %s", version.String())}, - } - job := batchv1.Job{ - ObjectMeta: metav1.ObjectMeta{ - Name: jobName, - Namespace: m.OBCluster.Namespace, - OwnerReferences: []metav1.OwnerReference{{ - Kind: m.OBCluster.Kind, - APIVersion: m.OBCluster.APIVersion, - Name: m.OBCluster.Name, - UID: m.OBCluster.UID, - }}, - }, - Spec: batchv1.JobSpec{ - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{container}, - RestartPolicy: corev1.RestartPolicyNever, - SchedulerName: resourceutils.GetSchedulerName(m.OBCluster.Spec.OBServerTemplate.PodFields), - }, - }, - BackoffLimit: &backoffLimit, - TTLSecondsAfterFinished: &ttl, - }, - } - - m.Logger.V(oceanbaseconst.LogLevelDebug).Info("Create validate upgrade job", "job", jobName) - err = m.Client.Create(m.Ctx, &job) - if err != nil { - return errors.Wrapf(err, "Failed to create validate job for obcluster %s", m.OBCluster.Name) - } - var jobObject *batchv1.Job - check := func() (bool, error) { - jobObject, err = resourceutils.GetJob(m.Ctx, m.Client, m.OBCluster.Namespace, jobName) - if err != nil { - return false, errors.Wrap(err, "Failed to get job") - } - if jobObject.Status.Succeeded == 0 && jobObject.Status.Failed == 0 { - m.Logger.V(oceanbaseconst.LogLevelDebug).Info("Job is still running") - return false, nil - } else if jobObject.Status.Succeeded == 1 { - m.Logger.V(oceanbaseconst.LogLevelDebug).Info("Job succeeded") - return true, nil - } else { - return false, errors.Wrap(err, "Failed to run validate job") - } - } - err = resourceutils.CheckJobWithTimeout(check, time.Second*time.Duration(obcfg.GetConfig().Time.WaitForJobTimeoutSeconds)) + _, _, err = resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, + fmt.Sprintf("%s-upgrade-validate", m.OBCluster.Name), + m.OBCluster.Spec.OBServerTemplate.Image, + m.OBCluster.Spec.OBServerTemplate.PodFields, + fmt.Sprintf(oceanbaseconst.CmdUpgradeValidateTemplate, version.String())) if err != nil { - return errors.Wrap(err, "Failed to run validate job") + return errors.Wrap(err, "Upgrade is unsupported") } return nil }