@@ -21,6 +21,7 @@ package component
2121
2222import (
2323 "context"
24+ "encoding/json"
2425 "fmt"
2526 "strings"
2627 "time"
@@ -39,6 +40,7 @@ import (
3940 "github.com/apecloud/kubeblocks/pkg/controller/job"
4041 "github.com/apecloud/kubeblocks/pkg/controller/model"
4142 intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
43+ viper "github.com/apecloud/kubeblocks/pkg/viperx"
4244)
4345
4446// LifeCycleActionType represents the lifecycle action type.
@@ -216,8 +218,8 @@ func renderActionCmdJob(ctx context.Context, cli client.Reader, actionCtx *Actio
216218 },
217219 },
218220 }
219- if len ( actionCtx .cluster . Spec . Tolerations ) > 0 {
220- jobObj . Spec . Template . Spec . Tolerations = actionCtx . cluster . Spec . Tolerations
221+ if err := BuildJobTolerations ( jobObj , actionCtx .cluster ); err != nil {
222+ return nil , err
221223 }
222224 for i := range jobObj .Spec .Template .Spec .Containers {
223225 intctrlutil .InjectZeroResourcesLimitsIfEmpty (& jobObj .Spec .Template .Spec .Containers [i ])
@@ -241,6 +243,34 @@ func renderActionCmdJob(ctx context.Context, cli client.Reader, actionCtx *Actio
241243 return renderedJob , nil
242244}
243245
246+ // BuildJobTolerations builds the job tolerations.
247+ func BuildJobTolerations (job * batchv1.Job , cluster * appsv1alpha1.Cluster ) error {
248+ // build data plane tolerations from config
249+ var tolerations []corev1.Toleration
250+ if val := viper .GetString (constant .CfgKeyDataPlaneTolerations ); val != "" {
251+ if err := json .Unmarshal ([]byte (val ), & tolerations ); err != nil {
252+ return err
253+ }
254+ }
255+
256+ if len (job .Spec .Template .Spec .Tolerations ) > 0 {
257+ job .Spec .Template .Spec .Tolerations = append (job .Spec .Template .Spec .Tolerations , tolerations ... )
258+ } else {
259+ job .Spec .Template .Spec .Tolerations = tolerations
260+ }
261+
262+ // build job tolerations from legacy cluster.spec.Tolerations
263+ if len (cluster .Spec .Tolerations ) > 0 {
264+ job .Spec .Template .Spec .Tolerations = append (job .Spec .Template .Spec .Tolerations , cluster .Spec .Tolerations ... )
265+ }
266+
267+ // build job tolerations from cluster.spec.SchedulingPolicy.Tolerations
268+ if cluster .Spec .SchedulingPolicy != nil && len (cluster .Spec .SchedulingPolicy .Tolerations ) > 0 {
269+ job .Spec .Template .Spec .Tolerations = append (job .Spec .Template .Spec .Tolerations , cluster .Spec .SchedulingPolicy .Tolerations ... )
270+ }
271+ return nil
272+ }
273+
244274// buildLifecycleActionEnvs builds the environment variables for lifecycle actions.
245275func buildLifecycleActionEnvs (ctx context.Context ,
246276 cli client.Reader ,
0 commit comments