Skip to content

Commit

Permalink
chore: the pod of the custom ops is always pending (#8455)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Nov 14, 2024
1 parent 3179905 commit bc7dd2f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/operations/custom/action_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ func (e *ExecAction) buildExecPodSpec(actionCtx ActionContext,
}, execAction.Command...),
}
intctrlutil.InjectZeroResourcesLimitsIfEmpty(container)
var tolerations []corev1.Toleration
if e.Comp.SchedulingPolicy != nil {
tolerations = e.Comp.SchedulingPolicy.Tolerations
toleration, err := getTolerations(e.Cluster, e.Comp)
if err != nil {
return nil, err
}
return &corev1.PodSpec{
Containers: []corev1.Container{*container},
// tolerate all taints
Tolerations: tolerations,
Tolerations: toleration,
ImagePullSecrets: intctrlutil.BuildImagePullSecrets(),
}, nil
}
8 changes: 6 additions & 2 deletions pkg/operations/custom/action_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ func (w *WorkloadAction) buildPodSpec(actionCtx ActionContext,
if podSpec.RestartPolicy == "" {
podSpec.RestartPolicy = corev1.RestartPolicyNever
}
if len(podSpec.Tolerations) == 0 && w.Comp.SchedulingPolicy != nil {
podSpec.Tolerations = w.Comp.SchedulingPolicy.Tolerations
if len(podSpec.Tolerations) == 0 {
toleration, err := getTolerations(w.Cluster, w.Comp)
if err != nil {
return nil, err
}
podSpec.Tolerations = toleration
}
switch {
case w.OpsRequest.Spec.CustomOps.ServiceAccountName != nil:
Expand Down
12 changes: 12 additions & 0 deletions pkg/operations/custom/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/apecloud/kubeblocks/pkg/common"
"github.com/apecloud/kubeblocks/pkg/constant"
"github.com/apecloud/kubeblocks/pkg/controller/component"
"github.com/apecloud/kubeblocks/pkg/controller/scheduling"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
)

Expand Down Expand Up @@ -408,3 +409,14 @@ func getNameFromObjectKey(objectKey string) string {
}
return objectKey
}

func getTolerations(cluster *appsv1.Cluster, compSpec *appsv1.ClusterComponentSpec) ([]corev1.Toleration, error) {
schedulePolicy, err := scheduling.BuildSchedulingPolicy(cluster, compSpec)
if err != nil {
return nil, err
}
if schedulePolicy == nil {
return nil, nil
}
return schedulePolicy.Tolerations, nil
}
12 changes: 12 additions & 0 deletions pkg/operations/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ var _ = Describe("CustomOps", func() {
GetObject()

cluster = testapps.NewClusterFactory(testCtx.DefaultNamespace, clusterName, "").
SetSchedulingPolicy(&appsv1.SchedulingPolicy{
Tolerations: []corev1.Toleration{
{Operator: corev1.TolerationOpExists, Key: "test"},
},
}).
WithRandomName().AddComponent(defaultCompName, componentDefObj.Name).SetReplicas(1).Create(&testCtx).GetObject()

fullCompName := constant.GenerateClusterComponentName(cluster.Name, defaultCompName)
Expand Down Expand Up @@ -291,6 +296,8 @@ var _ = Describe("CustomOps", func() {

By("mock job is completed, expect for ops phase is Succeed")
job := &jobList.Items[0]
Expect(job.Spec.Template.Spec.Tolerations).Should(HaveLen(1))
Expect(job.Spec.Template.Spec.Tolerations[0].Key).Should(Equal("test"))
patchJobPhase(job, batchv1.JobComplete)
By("reconcile once and make the action succeed")
_, err = GetOpsManager().Reconcile(reqCtx, k8sClient, opsResource)
Expand Down Expand Up @@ -325,6 +332,11 @@ var _ = Describe("CustomOps", func() {
It("Test custom ops with sharding cluster", func() {
By("init environment for sharding cluster")
cluster = testapps.NewClusterFactory(testCtx.DefaultNamespace, "", "").
SetSchedulingPolicy(&appsv1.SchedulingPolicy{
Tolerations: []corev1.Toleration{
{Operator: corev1.TolerationOpExists, Key: "test"},
},
}).
WithRandomName().AddSharding(defaultCompName, "", compDefName).Create(&testCtx).GetObject()

opsResource.Cluster = cluster
Expand Down

0 comments on commit bc7dd2f

Please sign in to comment.