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

add task status to output, run validate upgrade job using method in u… #730

Merged
merged 1 commit into from
Jan 14, 2025
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
1 change: 1 addition & 0 deletions api/v1alpha1/obcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/obclusteroperation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/observer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/obtenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/obtenantbackuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/obtenantoperation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/obzone_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_observers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_obtenantoperations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_obtenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_obzones.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion internal/const/oceanbase/oceanbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
62 changes: 6 additions & 56 deletions internal/resource/obcluster/obcluster_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading