Skip to content

Commit

Permalink
feat: support for custom schedulerName in observer pod configuration (#…
Browse files Browse the repository at this point in the history
…515)

Related to issue #494
  • Loading branch information
qchenzi authored Aug 14, 2024
1 parent 5ad5523 commit a188c14
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 7 deletions.
7 changes: 4 additions & 3 deletions api/types/observer_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ See the Mulan PSL v2 for more details.
package types

type OBServerTemplate struct {
Image string `json:"image"`
Resource *ResourceSpec `json:"resource"`
Storage *OceanbaseStorageSpec `json:"storage"`
Image string `json:"image"`
Resource *ResourceSpec `json:"resource"`
Storage *OceanbaseStorageSpec `json:"storage"`
PodFields *PodFieldsSpec `json:"podFields,omitempty"`
}
17 changes: 17 additions & 0 deletions api/types/podfields.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2024 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

package types

type PodFieldsSpec struct {
SchedulerName *string `json:"schedulerName,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -4610,6 +4610,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_observers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/oceanbase.oceanbase.com_obzones.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down
20 changes: 20 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4633,6 +4633,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down Expand Up @@ -7626,6 +7631,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down Expand Up @@ -11695,6 +11705,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down Expand Up @@ -17177,6 +17192,11 @@ spec:
properties:
image:
type: string
podFields:
properties:
schedulerName:
type: string
type: object
resource:
properties:
cpu:
Expand Down
19 changes: 17 additions & 2 deletions internal/resource/obcluster/obcluster_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func ValidateUpgradeInfo(m *OBClusterManager) tasktypes.TaskError {
Spec: corev1.PodSpec{
Containers: []corev1.Container{container},
RestartPolicy: corev1.RestartPolicyNever,
SchedulerName: resourceutils.GetSchedulerName(m.OBCluster.Spec.OBServerTemplate.PodFields),
},
},
BackoffLimit: &backoffLimit,
Expand Down Expand Up @@ -766,6 +767,7 @@ func CheckImageReady(m *OBClusterManager) tasktypes.TaskError {
Command: []string{"bash", "-c", "/home/admin/oceanbase/bin/oceanbase-helper help"},
}},
RestartPolicy: corev1.RestartPolicyNever,
SchedulerName: resourceutils.GetSchedulerName(m.OBCluster.Spec.OBServerTemplate.PodFields),
},
},
TTLSecondsAfterFinished: &ttl,
Expand Down Expand Up @@ -840,6 +842,7 @@ func CheckClusterMode(m *OBClusterManager) tasktypes.TaskError {
versionOutput, _, err := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace,
m.OBCluster.Name+"-get-version",
m.OBCluster.Spec.OBServerTemplate.Image,
m.OBCluster.Spec.OBServerTemplate.PodFields,
"/home/admin/oceanbase/bin/oceanbase-helper version",
)
if err != nil {
Expand All @@ -850,12 +853,14 @@ func CheckClusterMode(m *OBClusterManager) tasktypes.TaskError {
_, code, err = resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace,
m.OBCluster.Name+"-standalone-validate",
m.OBCluster.Spec.OBServerTemplate.Image,
m.OBCluster.Spec.OBServerTemplate.PodFields,
"/home/admin/oceanbase/bin/oceanbase-helper standalone validate",
)
case oceanbaseconst.ModeService:
_, code, err = resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace,
m.OBCluster.Name+"-service-validate",
m.OBCluster.Spec.OBServerTemplate.Image,
m.OBCluster.Spec.OBServerTemplate.PodFields,
"/home/admin/oceanbase/bin/oceanbase-helper service validate",
)
}
Expand Down Expand Up @@ -911,7 +916,11 @@ func CheckMigration(m *OBClusterManager) tasktypes.TaskError {
}

// check version strictly matches
targetVersionStr, _, err := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, fmt.Sprintf("%s-version", m.OBCluster.Name), m.OBCluster.Spec.OBServerTemplate.Image, oceanbaseconst.CmdVersion)
targetVersionStr, _, err := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace,
fmt.Sprintf("%s-version", m.OBCluster.Name),
m.OBCluster.Spec.OBServerTemplate.Image,
m.OBCluster.Spec.OBServerTemplate.PodFields,
oceanbaseconst.CmdVersion)
if err != nil {
return errors.Wrap(err, "get target oceanbase version")
}
Expand Down Expand Up @@ -1058,6 +1067,7 @@ func CheckEnvironment(m *OBClusterManager) tasktypes.TaskError {
m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace,
jobName,
m.OBCluster.Spec.OBServerTemplate.Image,
m.OBCluster.Spec.OBServerTemplate.PodFields,
"/home/admin/oceanbase/bin/oceanbase-helper env-check storage "+oceanbaseconst.ClogPath,
volumeConfigs,
)
Expand Down Expand Up @@ -1126,7 +1136,12 @@ func OptimizeClusterByScenario(m *OBClusterManager) tasktypes.TaskError {
// start a job to read optimize parameters, ignore errors, only proceed with valid outputs and ignore the errors
m.Logger.Info("Start to optimize obcluster parameters")
jobName := fmt.Sprintf("optimize-cluster-%s-%s", m.OBCluster.Name, rand.String(6))
output, code, _ := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, jobName, m.OBCluster.Spec.OBServerTemplate.Image, fmt.Sprintf("bin/oceanbase-helper optimize cluster %s", m.OBCluster.Spec.Scenario))
output, code, _ := resourceutils.RunJob(
m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace,
jobName,
m.OBCluster.Spec.OBServerTemplate.Image,
m.OBCluster.Spec.OBServerTemplate.PodFields,
fmt.Sprintf("bin/oceanbase-helper optimize cluster %s", m.OBCluster.Spec.Scenario))
if code == int32(cmdconst.ExitCodeOK) || code == int32(cmdconst.ExitCodeIgnorableErr) {
optimizeConfig := &helpermodel.OptimizationResponse{}
err := json.Unmarshal([]byte(output), optimizeConfig)
Expand Down
1 change: 1 addition & 0 deletions internal/resource/observer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func (m *OBServerManager) createOBPodSpec(obcluster *v1alpha1.OBCluster) corev1.
Affinity: m.OBServer.Spec.Affinity,
Tolerations: m.OBServer.Spec.Tolerations,
ServiceAccountName: m.OBServer.Spec.ServiceAccount,
SchedulerName: resourceutils.GetSchedulerName(m.OBServer.Spec.OBServerTemplate.PodFields),
}
return podSpec
}
Expand Down
6 changes: 5 additions & 1 deletion internal/resource/obtenant/obtenant_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,11 @@ func OptimizeTenantByScenario(m *OBTenantManager) tasktypes.TaskError {
}
m.Logger.Info("Start to optimize tenant parameter and variable")
jobName := fmt.Sprintf("optimize-tenant-%s-%s", m.OBTenant.Name, rand.String(6))
output, code, _ := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBTenant.Namespace, jobName, obcluster.Spec.OBServerTemplate.Image, fmt.Sprintf("bin/oceanbase-helper optimize tenant %s", m.OBTenant.Spec.Scenario))
output, code, _ := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBTenant.Namespace,
jobName,
obcluster.Spec.OBServerTemplate.Image,
obcluster.Spec.OBServerTemplate.PodFields,
fmt.Sprintf("bin/oceanbase-helper optimize tenant %s", m.OBTenant.Spec.Scenario))
if code == int32(cmdconst.ExitCodeOK) || code == int32(cmdconst.ExitCodeIgnorableErr) {
optimizeConfig := &helpermodel.OptimizationResponse{}
err := json.Unmarshal([]byte(output), optimizeConfig)
Expand Down
6 changes: 5 additions & 1 deletion internal/resource/utils/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/util/rand"
"sigs.k8s.io/controller-runtime/pkg/client"

apitypes "github.com/oceanbase/ob-operator/api/types"
"github.com/oceanbase/ob-operator/api/v1alpha1"
obcfg "github.com/oceanbase/ob-operator/internal/config/operator"
cmdconst "github.com/oceanbase/ob-operator/internal/const/cmd"
Expand All @@ -50,7 +51,9 @@ type JobContainerVolumes struct {
Volumes []corev1.Volume
}

func RunJob(ctx context.Context, c client.Client, logger *logr.Logger, namespace string, jobName string, image string, cmd string, volumeConfigs ...JobContainerVolumes) (output string, exitCode int32, err error) {
func RunJob(ctx context.Context, c client.Client, logger *logr.Logger, namespace string,
jobName string, image string, podFields *apitypes.PodFieldsSpec,
cmd string, volumeConfigs ...JobContainerVolumes) (output string, exitCode int32, err error) {
fullJobName := fmt.Sprintf("%s-%s", jobName, rand.String(6))
var backoffLimit int32
var ttl int32 = 300
Expand Down Expand Up @@ -78,6 +81,7 @@ func RunJob(ctx context.Context, c client.Client, logger *logr.Logger, namespace
Containers: []corev1.Container{container},
RestartPolicy: corev1.RestartPolicyNever,
Volumes: volumes,
SchedulerName: GetSchedulerName(podFields),
},
},
BackoffLimit: &backoffLimit,
Expand Down
28 changes: 28 additions & 0 deletions internal/resource/utils/podfields.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (c) 2024 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

package utils

import (
corev1 "k8s.io/api/core/v1"

"github.com/oceanbase/ob-operator/api/types"
)

// GetSchedulerName returns the scheduler name from the given PodFields.
// If PodFields or SchedulerName is nil, it returns the default scheduler name.
func GetSchedulerName(podFields *types.PodFieldsSpec) string {
if podFields == nil || podFields.SchedulerName == nil {
return corev1.DefaultSchedulerName // return Kubernetes's default scheduler name
}
return *podFields.SchedulerName
}

0 comments on commit a188c14

Please sign in to comment.