mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Import tzdata in apiserver, CronJob.timeZone fixes
This commit is contained in:
parent
98837de446
commit
f3b928a23d
@ -20,6 +20,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
_ "time/tzdata" // for timeZone support in CronJob
|
||||||
|
|
||||||
"k8s.io/component-base/cli"
|
"k8s.io/component-base/cli"
|
||||||
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
|
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
|
||||||
|
@ -386,8 +386,8 @@ func (jm *ControllerV2) updateCronJob(old interface{}, curr interface{}) {
|
|||||||
// it will be handled here by the queue. If the next requeue is further than previous schedule,
|
// it will be handled here by the queue. If the next requeue is further than previous schedule,
|
||||||
// the sync loop will essentially be a no-op for the already queued key with old schedule.
|
// the sync loop will essentially be a no-op for the already queued key with old schedule.
|
||||||
if oldCJ.Spec.Schedule != newCJ.Spec.Schedule || (timeZoneEnabled && !pointer.StringEqual(oldCJ.Spec.TimeZone, newCJ.Spec.TimeZone)) {
|
if oldCJ.Spec.Schedule != newCJ.Spec.Schedule || (timeZoneEnabled && !pointer.StringEqual(oldCJ.Spec.TimeZone, newCJ.Spec.TimeZone)) {
|
||||||
// schedule changed, change the requeue time
|
// schedule changed, change the requeue time, pass nil recorder so that syncCronJob will output any warnings
|
||||||
sched, err := cron.ParseStandard(formatSchedule(timeZoneEnabled, newCJ, jm.recorder))
|
sched, err := cron.ParseStandard(formatSchedule(timeZoneEnabled, newCJ, nil))
|
||||||
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
|
||||||
@ -752,7 +752,10 @@ func getRef(object runtime.Object) (*corev1.ObjectReference, error) {
|
|||||||
|
|
||||||
func formatSchedule(timeZoneEnabled bool, cj *batchv1.CronJob, recorder record.EventRecorder) string {
|
func formatSchedule(timeZoneEnabled bool, cj *batchv1.CronJob, recorder record.EventRecorder) string {
|
||||||
if strings.Contains(cj.Spec.Schedule, "TZ") {
|
if strings.Contains(cj.Spec.Schedule, "TZ") {
|
||||||
|
if recorder != nil {
|
||||||
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)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
return cj.Spec.Schedule
|
return cj.Spec.Schedule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,7 +900,10 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
|||||||
for name, tc := range testCases {
|
for name, tc := range testCases {
|
||||||
name := name
|
name := name
|
||||||
tc := tc
|
tc := tc
|
||||||
|
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.CronJobTimeZone, tc.enableTimeZone)
|
||||||
|
|
||||||
cj := cronJob()
|
cj := cronJob()
|
||||||
cj.Spec.ConcurrencyPolicy = tc.concurrencyPolicy
|
cj.Spec.ConcurrencyPolicy = tc.concurrencyPolicy
|
||||||
cj.Spec.Suspend = &tc.suspend
|
cj.Spec.Suspend = &tc.suspend
|
||||||
@ -910,10 +913,6 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
|||||||
cj.Spec.StartingDeadlineSeconds = &tc.deadline
|
cj.Spec.StartingDeadlineSeconds = &tc.deadline
|
||||||
}
|
}
|
||||||
|
|
||||||
if tc.enableTimeZone {
|
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.CronJobTimeZone, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
job *batchv1.Job
|
job *batchv1.Job
|
||||||
err error
|
err error
|
||||||
|
Loading…
Reference in New Issue
Block a user