Skip to content

Commit

Permalink
[patch] 🐛 Set concurrency policy of cronjob as Replace (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pohfy123 authored Jul 6, 2022
1 parent 22fc0cb commit 5af5acf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/config/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ func (c *controller) generateCronJob(cronJobName, cronJobCmd, schedule, compName
Spec: batchv1beta1.CronJobSpec{
SuccessfulJobsHistoryLimit: &successfulJobsHistoryLimit,
Schedule: schedule,
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
Expand Down Expand Up @@ -653,7 +654,7 @@ func (c *controller) detectSchedulerChanged(comps map[string]*s2hv1.Component, t
creatingCronJobObjs, deletingCronJobObjs := c.getUpdatedCronJobs(namespace, teamName, comp, cronJobList)
if len(deletingCronJobObjs) > 0 {
for _, obj := range deletingCronJobObjs {
err := c.deleteCronJobAndMatchingJobs(obj)
err = c.deleteCronJobAndMatchingJobs(obj)
if err != nil && !k8serrors.IsNotFound(err) {
logger.Error(err, "cannot delete cronJob", "component", obj.Name)
return err
Expand All @@ -663,7 +664,7 @@ func (c *controller) detectSchedulerChanged(comps map[string]*s2hv1.Component, t

if len(creatingCronJobObjs) > 0 {
for _, obj := range creatingCronJobObjs {
err := c.createCronJob(obj)
err = c.createCronJob(obj)
if err != nil && !k8serrors.IsAlreadyExists(err) {
logger.Error(err, "cannot create cronJob", "component", obj.Name)
return err
Expand Down
3 changes: 3 additions & 0 deletions internal/config/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ wordpress:
Spec: batchv1beta1.CronJobSpec{
SuccessfulJobsHistoryLimit: &successfulJobsHistoryLimit,
Schedule: "0 11 * * *",
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
Expand Down Expand Up @@ -247,6 +248,7 @@ wordpress:
Spec: batchv1beta1.CronJobSpec{
SuccessfulJobsHistoryLimit: &successfulJobsHistoryLimit,
Schedule: "0 4 * * *",
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
Expand Down Expand Up @@ -278,6 +280,7 @@ wordpress:
Spec: batchv1beta1.CronJobSpec{
SuccessfulJobsHistoryLimit: &successfulJobsHistoryLimit,
Schedule: "*/5 2,3 * * *",
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
Expand Down

0 comments on commit 5af5acf

Please sign in to comment.