Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid creating CronJob with TZ or CRON_TZ, but allow updates #116252

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Mar 3, 2023

What type of PR is this?

/kind cleanup
/kind api-change

What this PR does / why we need it:

Back in #106455 (k8s 1.23) after we've upgraded github.com/robfig/cron (in #102735) we've accidentally exposed internal details of the library allowing users to set TZ or CRON_TZ variable in .spec.schedule to affect TimeZone of a CronJob.

Now that kubernetes/enhancements#3140 is becoming GA we're proposing failing creating a new CronJobs with TZ or CRON_TZ in .spec.Schedule in favor of setting .spec.timeZone, but leave the warning and allow updates not to break users.

Special notes for your reviewer:

/assign @liggitt @sftim

Does this PR introduce a user-facing change?

Creation of new CronJob objects containing `TZ` or `CRON_TZ` in `.spec.schedule`, accidentally enabled in 1.22, is now disallowed. Use the `.spec.timeZone` field instead, supported in 1.25+ clusters in default configurations. See https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#unsupported-timezone-specification for more information.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://github.com/kubernetes/enhancements/issues/3140

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 3, 2023
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 3, 2023
@k8s-ci-robot k8s-ci-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 3, 2023
@soltysh
Copy link
Contributor Author

soltysh commented Mar 3, 2023

/hold
for reaching consensus
/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 3, 2023
@soltysh
Copy link
Contributor Author

soltysh commented Mar 3, 2023

/sig apps

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 3, 2023
@sftim
Copy link
Contributor

sftim commented Mar 3, 2023

-Fail CronJob creation with TZ or CRON_TZ set in .spec.schedule
+Fail CronJob creation with TZ or CRON_TZ set in `.spec.schedule`

?

We can use Markdown in the changelog.
Do we want to mention that we also block adding TZ or CRON_TZ to existing CronJobs (which I think we do)?

@sftim
Copy link
Contributor

sftim commented Mar 3, 2023

We could have an on-by-default feature gate for this, and for one release allow people to force it off (to help people migrate). Even though the “wrong” way was never official.

@liggitt
Copy link
Member

liggitt commented Mar 3, 2023

should we wait until TimeZone is enabled by default or GA in all supported releases before dropping this? rejecting this now means you can't write a manifest that uses time zone and works with all supported kubernetes versions

@soltysh
Copy link
Contributor Author

soltysh commented Mar 3, 2023

should we wait until TimeZone is enabled by default or GA in all supported releases before dropping this? rejecting this now means you can't write a manifest that uses time zone and works with all supported kubernetes versions

I think that's a reasonable approach.

/milestone v1.28

@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Mar 3, 2023
@sftim
Copy link
Contributor

sftim commented Mar 3, 2023

I suppose the genie is out of the bottle.

should we wait until TimeZone is enabled by default or GA in all supported releases before dropping this? rejecting this now means you can't write a manifest that uses time zone and works with all supported kubernetes versions

I mean, I guess, but: how much do we want to tacitly endorse TZ and CRON_TZ which are explicitly unsupported? AIUI the timeZone field is the only way that we commit to support.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@soltysh soltysh force-pushed the tz_validation branch 2 times, most recently from 827d128 to a372f36 Compare September 6, 2023 13:24
@soltysh
Copy link
Contributor Author

soltysh commented Sep 6, 2023

@liggitt this should be ready for a re-review, unfortunately I had to leave that mutation tag, since the verification mechanism is rather simple and will always match that line, and I don't want to change the entire method's body just in case someone will in the future try to modify.

Copy link
Member

@pacoxu pacoxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/assign @liggitt
for api change review

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 12, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: cc896e36c026a8542ab074fbe78868f86c4fd278

@@ -564,13 +568,16 @@ func validateConcurrencyPolicy(concurrencyPolicy *batch.ConcurrencyPolicy, fldPa
return allErrs
}

func validateScheduleFormat(schedule string, timeZone *string, fldPath *field.Path) field.ErrorList {
func validateScheduleFormat(schedule, oldSchedule string, timeZone *string, fldPath *field.Path) field.ErrorList {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than passing in the whole schedule, I think it would be easier to understand and unit test to make the parameter here as narrow as possible, like allowTZInSchedule bool

could invoke it like this:

allowTZInSchedule := false
if oldSpec != nil {
  allowTZInSchedule = strings.Contains(oldSpec.Schedule, "TZ")
}
allErrs = append(allErrs, validateScheduleFormat(spec.Schedule, allowTZInSchedule, spec.TimeZone, fldPath.Child("schedule"))...)

and use it like this:

switch {
case allowTZInSchedule && strings.Contains(schedule, "TZ") && timeZone != nil:
  allErrs = append(allErrs, field.Invalid(fldPath, schedule, "cannot use both timeZone field and TZ or CRON_TZ in schedule"))
case !allowTZInSchedule && strings.Contains(schedule, "TZ"):
  allErrs = append(allErrs, field.Invalid(fldPath, schedule, "cannot use TZ or CRON_TZ in schedule, use timeZone field instead"))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion - updated.

@liggitt liggitt moved this from In progress to Changes requested in API Reviews Oct 12, 2023
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 20, 2023
@sftim
Copy link
Contributor

sftim commented Oct 20, 2023

/uncc

@k8s-ci-robot k8s-ci-robot removed the request for review from sftim October 20, 2023 15:30
Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
/kind deprecation

@k8s-ci-robot k8s-ci-robot added kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Oct 20, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 9d10a1efab75a10a906f33f8e760d01a56f7fefc

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, pacoxu, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 20, 2023
@liggitt
Copy link
Member

liggitt commented Oct 20, 2023

be sure to open a docs PR to update the https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#unsupported-timezone-specification to say

The implementation of the CronJob API from Kubernetes 1.22-1.28 lets you ...

@k8s-ci-robot k8s-ci-robot merged commit f5d7c34 into kubernetes:master Oct 20, 2023
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.29 milestone Oct 20, 2023
@soltysh
Copy link
Contributor Author

soltysh commented Oct 23, 2023

Done in kubernetes/website#43654

@soltysh soltysh deleted the tz_validation branch October 23, 2023 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.29
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

7 participants