Automatic merge from submit-queue Do not list CronJob unmet starting times beyond deadline **What this PR does / why we need it**: See #36311. `getRecentUnmetScheduleTimes` gives up after 100 unmet times to avoid wasting too much CPU or memory generating all the times, as it generates them sequentially. When concurrency is forbidden, this is conceptually un-necessary: we only need the last unmet start time. This suggests that when concurrency is forbidden, we could generate times by going backward in time from now. This is not very practical as CronJob currently relies on a package that only provides `Next` and no `Prev`. Hand-cooking a `Prev` does not seem like a good idea. I could submit a PR to the cron library to add a `Prev` method, and use that when concurrency is forbidden through something like `getLastUnmetScheduleTime`. This would be `O(1)` and there would be no limit involved. (edit: actually, even for the other concurrency settings, we only start the last unmet start times -- there is a `TODO` in the controller to actually start all of them, but that is not implemented at the moment. This means the solution would apply, at least temporarily, to all concurrency settings). cc @soltysh what do you think? In the meantime, I would suggest to do something simple. Currently, the user has no way to configure anything to ensure that his CronJob will not get stuck if one job takes more that 100 unmet times. `getRecentUnmetScheduleTimes` starts with an initial time corresponding to the last start (or to the creation of the CronJob, if nothing has started yet). However, when `StartingDeadlineSeconds` is set, the controller will not start anything that is older than the deadline, so if the last start is way beyond the deadline, we are generating potentially lots of unmet start times that will not be considered by the scheduler for scheduling anyway. Consider a job running every minute, where the last instance has taken 120 minutes. This means there are more than 100 unmet times when we start counting from the last start time. **The PR makes `getRecentUnmetScheduleTimes` only consider times that do not fall beyond the deadline.** Here, the CronJob can be configured with a `StartingDeadlineSeconds` of, say, 10 minutes. After the 120min job has run, `getRecentUnmetScheduleTimes` will only consider the times in the last 10 minutes from now, and will not get stuck. As a side note on the max. number of unmet times to use as limits in terms of CPU used by the controller: I have run a quick benchmark on my i7 mac. Schedules corresponding to "once a week" tend to be more expensive to generate unmet times for. Just FYI. ``` +--------------+---------------+--------------+ | SCHEDULE | MISSED STARTS | TIMING | +--------------+---------------+--------------+ | */1 * * * ? | 100 | 383.645µs | | */30 * * * ? | 100 | 354.765µs | | 30 1 * * ? | 100 | 1.065124ms | | 30 1 * * 0 | 100 | 1.80034ms | | */1 * * * ? | 500 | 1.341365ms | | */30 * * * ? | 500 | 1.814441ms | | 30 1 * * ? | 500 | 8.475012ms | | 30 1 * * 0 | 500 | 10.020613ms | | */1 * * * ? | 1000 | 2.551697ms | | */30 * * * ? | 1000 | 4.075813ms | | 30 1 * * ? | 1000 | 17.674945ms | | 30 1 * * 0 | 1000 | 19.149324ms | | */1 * * * ? | 10000 | 25.725531ms | | */30 * * * ? | 10000 | 87.520022ms | | 30 1 * * ? | 10000 | 174.29216ms | | 30 1 * * 0 | 10000 | 196.565748ms | +--------------+---------------+--------------+ ``` using ```.go package main import ( "fmt" "time" "os" "strconv" "github.com/robfig/cron" "github.com/olekukonko/tablewriter" ) func timeSchedule(schedule string, iterations int) (time.Duration) { sched, err := cron.ParseStandard(schedule) if err != nil { panic(fmt.Sprintf("Unparseable schedule: %s", err)) } start := time.Now() t := time.Now() for i := 1; i <= iterations; i++ { t = sched.Next(t) } return time.Since(start) } func main() { table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Schedule", "Missed starts", "Timing"}) schedules := []string{"*/1 * * * ?", "*/30 * * * ?", "30 1 * * ?", "30 1 * * 0"} iteration_nums := []int{100, 500, 1000, 10000} for _, iterations := range iteration_nums { for _, schedule := range schedules { table.Append([]string{schedule, strconv.Itoa(iterations), timeSchedule(schedule, iterations).String()}) } } table.Render() } ``` **Which issue this PR fixes**: fixes #36311 **Special notes for your reviewer**: **Release note**: ```release-note ``` |
||
---|---|---|
.github | ||
api | ||
build | ||
cluster | ||
cmd | ||
docs | ||
examples | ||
federation | ||
Godeps | ||
hack | ||
hooks | ||
logo | ||
pkg | ||
plugin | ||
staging | ||
test | ||
third_party | ||
translations | ||
vendor | ||
.gazelcfg.json | ||
.generated_docs | ||
.generated_files | ||
.gitattributes | ||
.gitignore | ||
BUILD.bazel | ||
CHANGELOG.md | ||
code-of-conduct.md | ||
CONTRIBUTING.md | ||
labels.yaml | ||
LICENSE | ||
Makefile | ||
Makefile.generated_files | ||
OWNERS | ||
OWNERS_ALIASES | ||
README.md | ||
Vagrantfile | ||
WORKSPACE |
Kubernetes

Introduction
Kubernetes is an open source system for managing containerized applications across multiple hosts, providing basic mechanisms for deployment, maintenance, and scaling of applications. Kubernetes is hosted by the Cloud Native Computing Foundation (CNCF)
Kubernetes builds upon a decade and a half of experience at Google running production workloads at scale using a system called Borg, combined with best-of-breed ideas and practices from the community.
Are you ...
- Interested in learning more about using Kubernetes?
- See our documentation on kubernetes.io
- Try our interactive tutorial
- Take a free course on Scalable Microservices with Kubernetes.
- Interested in developing the core Kubernetes code base, developing tools using the Kubernetes API or helping in anyway possible ? Keep reading!
Code of Conduct
The Kubernetes community abides by the CNCF code of conduct. Here is an excerpt:
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
Community
Do you want to help "shape the evolution of technologies that are container-packaged, dynamically-scheduled and microservices-oriented? ". If you are a company, you should consider joining the CNCF. For details about who's involved in CNCF and how Kubernetes plays a role, read the announcement. For general information about our community see the website community page.
Join us on social media (Twitter, Google+) and read our blog
Ask questions and help answer them on Slack or Stack Overflow
Attend our key events (kubecon, cloudnativecon, weekly community meeting)
Join a Special Interest Group (SIG)
Contribute
If you're interested in being a contributor and want to get involved in developing Kubernetes, get started with this reading:
- The community expectations
- The contributor guidelines
- The Kubernetes Developer Guide
You will then most certainly gain a lot from joining a SIG, attending the regular hangouts as well as the community meeting.
If you have an idea for a new feature, see the Kubernetes Features repository for a list of features that are coming in new releases as well as details on how to propose one.
Building Kubernetes for the impatient
If you want to build Kubernetes right away there are two options:
- You have a working Go environment.
$ go get -d k8s.io/kubernetes
$ cd $GOPATH/src/k8s.io/kubernetes
$ make
- You have a working Docker environment.
$ git clone https://github.com/kubernetes/kubernetes
$ cd kubernetes
$ make quick-release
If you are less impatient, head over to the developer's documentation.
Support
While there are many different channels that you can use to get hold of us (Slack, Stack Overflow, Issues, Forums/Mailing lists), you can help make sure that we are efficient in getting you the help that you need.
If you need support, start with the troubleshooting guide and work your way through the process that we've outlined.
That said, if you have questions, reach out to us one way or another. We don't bite!