kubernetes / kubernetes

Production-Grade Container Scheduling and Management
https://kubernetes.io
Apache License 2.0
110.58k stars 39.52k forks source link

Cronjobs with names longer than 52 characters fail to schedule jobs #50850

Closed julia-stripe closed 7 years ago

julia-stripe commented 7 years ago

Is this a BUG REPORT or FEATURE REQUEST?:

/kind bug

What happened:

We have some cron jobs with longish names (~60 characters), and noticed that the corresponding jobs weren't being created by the cronjob controller because the name was too long.

Here's what happened: There's a 63-character limit on job names (because for some reason on job creation the name gets copied into a label, where the limit is 63 chars). For example, if I try to create a job with a long name, I get the error message:

The Job "100000000010000000001000000000100000000010000000001000000000100000000010000000000000000010000000000"
 is invalid: spec.template.labels: Invalid value: 
"100000000010000000001000000000100000000010000000001000000000100000000010000000000000000010000000000": 
must be no more than 63 characters

By itself, this is fine. I can just make a job with a shorter name. However! If I create a cron job, the cron job controller will create jobs named $CRON_JOB_NAME-$TIMESTAMP. So the job's name is 11 characters longer than the job name.

This means that if I create a cron job with a 63-character name, it'll result in a job name that's 74 characters, which the API will refuse to accept. This means the cron job never gets scheduled.

Some possible resolutions:

  1. Add validation on cron job creation that refuses to let you create jobs with names > 52 characters
  2. Have the cron job controller truncate cronjobs names
  3. Somehow remove the 63-character limit on job names (this seems difficult)

There's actually a deeper problem here at play: Kubernetes' resource name limit is 253 characters. But the limit for resouce labels is 63 characters. So when a job is created, the name (which is allowed to be up to 255 chars) gets copied into a label, which has a lower limit. So the job creation fails. (these are the docs on limits)

What you expected to happen:

When I create a cron job, I expect it to either

  1. refuse to create the cron job, or
  2. schedule jobs correctly from that cron job

How to reproduce it (as minimally and precisely as possible):

  1. Create a cronjob with a name that's more than 52 characters
  2. Observe that it does not schedule jobs, with an error message like spec.template.labels: Invalid value: "{name}": must be no more than 63 characters

Anything else we need to know?:

example of a job definition with a long name

This job definition is invalid:

apiVersion: batch/v1
kind: Job
metadata:
  name: "100000000010000000001000000000100000000010000000001000000000100000000010000000000000000010000000000"
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
k8s-github-robot commented 7 years ago

@julia-stripe There are no sig labels on this issue. Please add a sig label by:

  1. mentioning a sig: @kubernetes/sig-<group-name>-<group-suffix> e.g., @kubernetes/sig-contributor-experience-<group-suffix> to notify the contributor experience sig, OR

  2. specifying the label manually: /sig <label> e.g., /sig scalability to apply the sig/scalability label

Note: Method 1 will trigger an email to the group. You can find the group list here and label list here. The <group-suffix> in the method 1 has to be replaced with one of these: bugs, feature-requests, pr-reviews, test-failures, proposals

julia-stripe commented 7 years ago

/sig apps

0xmichalis commented 7 years ago

cc @soltysh