mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #106455 from soltysh/cronjob_warning
Add warning about using unsupported CRON_TZ
This commit is contained in:
commit
39c76ba2ed
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
@ -489,15 +490,20 @@ func (jm *ControllerV2) syncCronJob(
|
|||||||
// this is likely a user error in defining the spec value
|
// this is likely a user error in defining the spec value
|
||||||
// we should log the error and not reconcile this cronjob until an update to spec
|
// we should log the error and not reconcile this cronjob until an update to spec
|
||||||
klog.V(2).InfoS("Unparseable schedule", "cronjob", klog.KRef(cj.GetNamespace(), cj.GetName()), "schedule", cj.Spec.Schedule, "err", err)
|
klog.V(2).InfoS("Unparseable schedule", "cronjob", klog.KRef(cj.GetNamespace(), cj.GetName()), "schedule", cj.Spec.Schedule, "err", err)
|
||||||
jm.recorder.Eventf(cj, corev1.EventTypeWarning, "UnparseableSchedule", "unparseable schedule: %s : %s", cj.Spec.Schedule, err)
|
jm.recorder.Eventf(cj, corev1.EventTypeWarning, "UnparseableSchedule", "unparseable schedule: %q : %s", cj.Spec.Schedule, err)
|
||||||
return cj, nil, nil
|
return cj, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(cj.Spec.Schedule, "TZ") {
|
||||||
|
jm.recorder.Eventf(cj, corev1.EventTypeWarning, "UnsupportedSchedule", "CRON_TZ or TZ used in schedule %q is not officially supported, see https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ for more details", cj.Spec.Schedule)
|
||||||
|
}
|
||||||
|
|
||||||
scheduledTime, err := getNextScheduleTime(*cj, now, sched, jm.recorder)
|
scheduledTime, err := getNextScheduleTime(*cj, now, sched, jm.recorder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// this is likely a user error in defining the spec value
|
// this is likely a user error in defining the spec value
|
||||||
// we should log the error and not reconcile this cronjob until an update to spec
|
// we should log the error and not reconcile this cronjob until an update to spec
|
||||||
klog.V(2).InfoS("invalid schedule", "cronjob", klog.KRef(cj.GetNamespace(), cj.GetName()), "schedule", cj.Spec.Schedule, "err", err)
|
klog.V(2).InfoS("invalid schedule", "cronjob", klog.KRef(cj.GetNamespace(), cj.GetName()), "schedule", cj.Spec.Schedule, "err", err)
|
||||||
jm.recorder.Eventf(cj, corev1.EventTypeWarning, "InvalidSchedule", "invalid schedule schedule: %s : %s", cj.Spec.Schedule, err)
|
jm.recorder.Eventf(cj, corev1.EventTypeWarning, "InvalidSchedule", "invalid schedule: %s : %s", cj.Spec.Schedule, err)
|
||||||
return cj, nil, nil
|
return cj, nil, nil
|
||||||
}
|
}
|
||||||
if scheduledTime == nil {
|
if scheduledTime == nil {
|
||||||
|
@ -18,6 +18,8 @@ package cronjob
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
@ -114,7 +116,11 @@ func (cronJobStrategy) Validate(ctx context.Context, obj runtime.Object) field.E
|
|||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (cronJobStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
func (cronJobStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
newCronJob := obj.(*batch.CronJob)
|
newCronJob := obj.(*batch.CronJob)
|
||||||
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "jobTemplate", "spec", "template"), &newCronJob.Spec.JobTemplate.Spec.Template, nil)
|
warnings := pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "jobTemplate", "spec", "template"), &newCronJob.Spec.JobTemplate.Spec.Template, nil)
|
||||||
|
if strings.Contains(newCronJob.Spec.Schedule, "TZ") {
|
||||||
|
warnings = append(warnings, fmt.Sprintf("CRON_TZ or TZ used in %s is not officially supported, see https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ for more details", field.NewPath("spec", "spec", "schedule")))
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
@ -147,6 +153,9 @@ func (cronJobStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Ob
|
|||||||
if newCronJob.Generation != oldCronJob.Generation {
|
if newCronJob.Generation != oldCronJob.Generation {
|
||||||
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "jobTemplate", "spec", "template"), &newCronJob.Spec.JobTemplate.Spec.Template, &oldCronJob.Spec.JobTemplate.Spec.Template)
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "jobTemplate", "spec", "template"), &newCronJob.Spec.JobTemplate.Spec.Template, &oldCronJob.Spec.JobTemplate.Spec.Template)
|
||||||
}
|
}
|
||||||
|
if strings.Contains(newCronJob.Spec.Schedule, "TZ") {
|
||||||
|
warnings = append(warnings, fmt.Sprintf("CRON_TZ or TZ used in %s is not officially supported, see https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ for more details", field.NewPath("spec", "spec", "schedule")))
|
||||||
|
}
|
||||||
return warnings
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user