-
Notifications
You must be signed in to change notification settings - Fork 299
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
Add labels for workload parent #1032
Add labels for workload parent #1032
Conversation
* Added parent name and group-kind labels for workload objects. * If parent's name, or group-kind exceeds the limit of 63 characters length, respective labels won't be added to a workload object.
✅ Deploy Preview for kubernetes-sigs-kueue canceled.
|
Welcome @achernevskii! |
Hi @achernevskii. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
* UID shouldn't exceed the 63 character label value length limit, and it uniquely identifies a parent.
|
||
if utf8.RuneCountInString(jobGVK.GroupKind().String()) < 64 { | ||
wl.Labels[controllerconsts.ParentGroupKindLabel] = jobGVK.GroupKind().String() | ||
if uid := string(job.Object().GetUID()); utf8.RuneCountInString(uid) < 64 && uid != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k8s validation just uses len
https://github.com/kubernetes/kubernetes/blob/2c6c4566eff972d6c1320b5f8ad795f88c822d09/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L169
I think using the rune len would be weaker.
I'm wondering if we should just try to put the label and let the apiserver return an error. Note that there is a regex check, so that could potentially fail as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should just try to put the label and let the apiserver return an error.
We can do that, but I would rather create a workload without a job-uid
label, since this functionality is not essential for the controller. We could also log a warning if a label can't be added to a workload. Please let me know which of those three options is the best in your opinion.
Note that there is a regex check, so that could potentially fail as well.
According to this page, UIDs are standardized as ISO/IEC 9834-8 and as ITU-T X.667. And ISO/IEC 9834-8 says the following:
UUIDs forming a component of an OID are represented in ASN.1 value notation as the decimal representation of their integer value, but for all other display purposes it is more usual to represent them with hexadecimal digits with a hyphen separating the different fields within the 16-octet UUID.
Regex that kuberentes is using for label validation is the following (([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?
, if I'm not mistaken. This regex should match the UID format, so I think we're good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k8s validation just uses len
Replaced RuneCountInString call with len call in 866a09a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that, but I would rather create a workload without a job-uid label, since this functionality is not essential for the controller.
In that case, use IsValidLabelValue
from https://github.com/kubernetes/kubernetes/blob/2c6c4566eff972d6c1320b5f8ad795f88c822d09/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L167
We could also log a warning if a label can't be added to a workload.
Logging is not visible to users. Webhooks support warnings https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#best-practices-and-warnings:~:text=Admission%20webhooks%20can%20optionally%20return%20warning%20messages%20that%20are%20returned%20to%20the%20requesting%20client%20in%20HTTP%20Warning%20headers%20with%20a%20warning%20code%20of%20299.%20Warnings%20can%20be%20sent%20with%20allowed%20or%20rejected%20admission%20responses.
But in our case, it's not end users creating Workloads, but users. Maybe a log is not so bad so administrators can take action.
UIDs are standardized as ISO/IEC 9834-8 and as ITU-T X.667.
I think there is a way where an end user can override the UID and potentially use something that wouldn't pass label validation. However this should be very uncommon.
The log should be enough :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced len label check with IsValidLabelValue, and added the log message in 0350ad8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just nits
@@ -32,4 +32,8 @@ const ( | |||
// ignores this Job from admission, and takes control of its suspension | |||
// status based on the admission status of the parent workload. | |||
ParentWorkloadAnnotation = "kueue.x-k8s.io/parent-workload" | |||
|
|||
// JobUIDLabel is the label key in the workload resource, that holds the UID of | |||
// a parent job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// a parent job. | |
// the owner job. |
nit: Similarly, to avoid confusion with parent
which is a relation between jobs in Kueue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the comment in 0350ad8.
pkg/util/testing/wrappers.go
Outdated
@@ -165,6 +165,11 @@ func (w *WorkloadWrapper) ReclaimablePods(rps ...kueue.ReclaimablePod) *Workload | |||
return w | |||
} | |||
|
|||
func (w *WorkloadWrapper) SetLabels(l map[string]string) *WorkloadWrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (w *WorkloadWrapper) SetLabels(l map[string]string) *WorkloadWrapper { | |
func (w *WorkloadWrapper) Labels(l map[string]string) *WorkloadWrapper { |
nit, but we generally don't use for functions like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this method in 0350ad8.
* Replace len label check with IsValidLabelValue from k8s apimachinery, which is used on the server side to validate the label values. * Add a log message, for the case, when UID label validation returns any errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
wl.Labels[controllerconsts.JobUIDLabel] = jobUid | ||
} else { | ||
log.V(2).Info( | ||
"Validation of the owner job UID label has failed. Creating workload without the label.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Validation of the owner job UID label has failed. Creating workload without the label.", | |
"Validation of the owner job UID label has failed. Creating workload without the label", |
} else { | ||
log.V(2).Info( | ||
"Validation of the owner job UID label has failed. Creating workload without the label.", | ||
"ValidationErrors", errs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ValidationErrors", errs, | |
"err", errs.ToAggregate(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a ErrorList
type here, IsValidLabelValue
will return a slice of strings, so I can't call this method here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhhh, that's why the value is not present either
log.V(2).Info( | ||
"Validation of the owner job UID label has failed. Creating workload without the label.", | ||
"ValidationErrors", errs, | ||
"LabelValue", jobUid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will probably already be part of the error, so no need to include again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the log message, that I'm getting while unit testing:
"Validation of the owner job UID label has failed. Creating workload without the label"
"job"="ns/job"
"ValidationErrors"=["must be no more than 63 characters"]
"LabelValue"="long-uidlong-uidlong-uidlong-uidlong-uidlong-uidlong-uidlong-uid"
Label is not included in the error here.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: achernevskii, alculquicondor 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 |
Please add a release note. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/release-note-edit
|
What type of PR is this?
/kind feature
What this PR does / why we need it:
Added parent name and group-kind labels for workload objects.
If parent's name, or group-kind exceeds the limit of 63 characters length, respective labels won't be added to a workload object.
Which issue(s) this PR fixes:
Fixes #992
Special notes for your reviewer:
Does this PR introduce a user-facing change?