Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Validate that cronjob names are 52 characters or less #52733
Conversation
k8s-ci-robot
added
size/S
cncf-cla: yes
labels
Sep 19, 2017
|
Hi @julia-stripe. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
k8s-ci-robot
added
the
needs-ok-to-test
label
Sep 19, 2017
k8s-merge-robot
assigned
caesarxuchao and
sttts
Sep 19, 2017
k8s-merge-robot
added
the
release-note
label
Sep 19, 2017
apelisse
added this to Backlog
in 1.8 Failing tests
Sep 19, 2017
apelisse
removed this from Backlog
in 1.8 Failing tests
Sep 19, 2017
|
cc @soltysh |
|
/ok-to-test |
k8s-ci-robot
assigned
soltysh
Sep 19, 2017
k8s-ci-robot
removed
the
needs-ok-to-test
label
Sep 19, 2017
| @@ -162,6 +162,13 @@ func ValidateCronJob(scheduledJob *batch.CronJob) field.ErrorList { | ||
| // CronJobs and rcs have the same name validation | ||
| allErrs := apivalidation.ValidateObjectMeta(&scheduledJob.ObjectMeta, true, apivalidation.ValidateReplicationControllerName, field.NewPath("metadata")) | ||
| allErrs = append(allErrs, ValidateCronJobSpec(&scheduledJob.Spec, field.NewPath("spec"))...) | ||
| + if len(scheduledJob.ObjectMeta.Name) > 52 { |
soltysh
Sep 19, 2017
Contributor
Replace that maybe with DNS1035LabelMaxLength-11 from k8s.io/apimachinery/pkg/util/validation package.
| + // creating a job. The job name length limit is 63 characters. | ||
| + // Therefore cronjob names must have length <= 63-11=52. If we don't validate this here, | ||
| + // then job creation will fail later. | ||
| + allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), scheduledJob.ObjectMeta.Name, "cronjob name length limit is 52 characters")) |
soltysh
Sep 19, 2017
Contributor
'must be no more than 52 characters' - to keep it consistent with other error messages
|
@soltysh thanks, made those changes! take another look? |
|
/retest |
k8s-ci-robot
added
the
lgtm
label
Sep 19, 2017
|
@julia-stripe thank you! |
k8s-merge-robot
removed
the
lgtm
label
Sep 19, 2017
|
It changed because I forgot to run go fmt before |
|
/retest |
|
/lgtm |
k8s-ci-robot
added
the
lgtm
label
Sep 20, 2017
soltysh
added
the
queue/fix
label
Sep 20, 2017
soltysh
added this to the v1.8 milestone
Sep 20, 2017
|
Eric mind approving this one, this is hardening the cronjob name validation, but that's better than failing to create a job. /assign @erictune |
k8s-ci-robot
assigned
erictune
Sep 20, 2017
soltysh
unassigned
sttts and
caesarxuchao
Sep 20, 2017
|
/assign @thockin |
k8s-ci-robot
assigned
thockin
Sep 20, 2017
|
Blech. Does this mean we can never ever change the naming format that it
uses for pod names? We have this same pattern for deployments and
replicasets, should we formalize this derivative-name pattern?
…
|
| @@ -162,6 +163,13 @@ func ValidateCronJob(scheduledJob *batch.CronJob) field.ErrorList { | ||
| // CronJobs and rcs have the same name validation | ||
| allErrs := apivalidation.ValidateObjectMeta(&scheduledJob.ObjectMeta, true, apivalidation.ValidateReplicationControllerName, field.NewPath("metadata")) | ||
| allErrs = append(allErrs, ValidateCronJobSpec(&scheduledJob.Spec, field.NewPath("spec"))...) | ||
| + if len(scheduledJob.ObjectMeta.Name) > apimachineryvalidation.DNS1035LabelMaxLength-11 { |
thockin
Sep 20, 2017
Owner
Job creates Pods which have further suffixes, right? And Pod names also are limited in size.
julia-stripe
Sep 20, 2017
Contributor
Pod names' size limits are 255 characters, like most Kubernetes resources. As far as I can tell only job names have a size limit of 63 characters (because job names get copied in to a label, which have a lower size limit than Kubernetes resource names).
|
@julia-stripe @soltysh @thockin @erictune - ok to move this out of 1.8? |
|
I'll OK this for now, but I'd like to revisit this topic as part of 1.9. Can I count on you @julia-stripe to bring up back up? |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: julia-stripe, soltysh, thockin Associated issue: 50850 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
k8s-merge-robot
added
the
approved
label
Sep 22, 2017
abgworrall
added
the
cherrypick-candidate
label
Sep 23, 2017
|
This missed the final ffwd for release-1.8, so will need to be cherrypicked in afterwards. It will not be in the release-candidate for 1.8; ping me on slack now if that is a problem ... |
| + // The cronjob controller appends a 11-character suffix to the cronjob (`-$TIMESTAMP`) when | ||
| + // creating a job. The job name length limit is 63 characters. | ||
| + // Therefore cronjob names must have length <= 63-11=52. If we don't validate this here, | ||
| + // then job creation will fail later. |
liggitt
Sep 23, 2017
Member
Does this prevent updating an existing cronjob? That can block addition/removal of finalizers during deletion
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.. |
k8s-merge-robot
merged commit d85f4c2
into
kubernetes:master
Sep 23, 2017
11 of 13 checks passed
|
Just to followup - this was merged into master, but not into release-1.8. You'll need to cherrypick it into 1.8; it'll get approved, as it was just bad timing that meant it missed the 1.8 boat. |
need to double-check this doesn't prevent update/delete of existing cronjobs with longer-than-52-char names before picking |
|
@liggitt I just tested updating and deleting existing cronjobs with this patch. The results were:
My view is that it's okay that cronjob updates fail (and in fact preferable). If I have an invalid cronjob in my cluster, I'd prefer to be notified when updating it that it's invalid than continue having a job that I don't know is broken. Previously we had cronjobs in our cluster that were not running because of this issue and we didn't know about it which was a pretty scary state to be in. |
|
thanks for checking.
if updating fails, it is likely that deleting with a foreground propagation policy would fail as well (this adds a finalizer to the object, which requires doing an update)
no-op updates (get bytes/put bytes) are used to migrate storage (json->protobuf, v1beta1->v1, etc) during cluster upgrades, and should never fail |
Makes sense. How do you recommend dealing with this? |
|
Validation-wise, I'd recommend just validating the shorter name restriction on creation (names are immutable once created, so this would keep new bad data from entering the system, while allowing migrating/deleting old bad data):
longer-term, we should work to make failing cronjobs more visible. there are lots of potential reasons cronjobs could fail, not just invalid names, so we need to surface this sort of case much more visibly (better error status on the cronjob object, events in namespace, etc) |
|
cc @soltysh for visibility on failing cronjobs |
liggitt
referenced this pull request
Sep 25, 2017
Merged
Limit 52-character cronjob name validation to create #52967
FYI, opened #52967 to do this. If this is picked into 1.8, I think that should be as well |
added a commit
that referenced
this pull request
Sep 29, 2017
|
if this is picked to 1.8, #52967 should be as well |
julia-stripe commentedSep 19, 2017
What this PR does / why we need it:
Right now when you create a cronjob with a name longer than 52 characters, creation will succeed but the cronjob controller will create Job objects with names longer than 63 characters. Jobs cannot have names longer than 63 characters, so the cronjob will never be able to run any jobs.
Which issue this PR fixes : Fixes #50850
Special notes for your reviewer:
Release note: