@@ -21,6 +21,7 @@ package component
21
21
22
22
import (
23
23
"context"
24
+ "encoding/json"
24
25
"fmt"
25
26
"strings"
26
27
"time"
@@ -39,6 +40,7 @@ import (
39
40
"github.com/apecloud/kubeblocks/pkg/controller/job"
40
41
"github.com/apecloud/kubeblocks/pkg/controller/model"
41
42
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
43
+ viper "github.com/apecloud/kubeblocks/pkg/viperx"
42
44
)
43
45
44
46
// LifeCycleActionType represents the lifecycle action type.
@@ -216,8 +218,8 @@ func renderActionCmdJob(ctx context.Context, cli client.Reader, actionCtx *Actio
216
218
},
217
219
},
218
220
}
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
221
223
}
222
224
for i := range jobObj .Spec .Template .Spec .Containers {
223
225
intctrlutil .InjectZeroResourcesLimitsIfEmpty (& jobObj .Spec .Template .Spec .Containers [i ])
@@ -241,6 +243,34 @@ func renderActionCmdJob(ctx context.Context, cli client.Reader, actionCtx *Actio
241
243
return renderedJob , nil
242
244
}
243
245
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
+
244
274
// buildLifecycleActionEnvs builds the environment variables for lifecycle actions.
245
275
func buildLifecycleActionEnvs (ctx context.Context ,
246
276
cli client.Reader ,
0 commit comments