-
Notifications
You must be signed in to change notification settings - Fork 39.7k
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
apiextensions: ignore ObjectMeta from webhook converted objects other than labels and annotations #77743
apiextensions: ignore ObjectMeta from webhook converted objects other than labels and annotations #77743
Conversation
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
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.
As a FYI, As part of #77756 I'll be adding integration tests for converters that do invalid things (return various illegal responses). I've taken notes to include metadata label and annotations test cases.
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
Outdated
Show resolved
Hide resolved
ddaa813
to
210a9c3
Compare
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto
Outdated
Show resolved
Hide resolved
a few comments, nothing major |
210a9c3
to
8c79150
Compare
f7bf465
to
6cef4d4
Compare
4caa3b4
to
2f40b7d
Compare
… than labels and annotations
2f40b7d
to
4f6d755
Compare
4f6d755
to
9814914
Compare
/retest empty verify log |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, sttts 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 |
/lgtm |
/retest |
stringMap[k] = v.(string) | ||
} | ||
var errs field.ErrorList | ||
if fld == "labels" { |
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 seems these 5 lines can be rewritten as:
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
index 8cc7e78e22..121654846d 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/webhook_converter.go
@@ -317,7 +317,11 @@ func restoreObjectMeta(original, converted *unstructured.Unstructured) error {
return fmt.Errorf("invalid metadata of type %T in input object", obj)
}
- for _, fld := range []string{"labels", "annotations"} {
+ type validatorType = func(map[string]string, *field.Path) field.ErrorList
+ fldToValidator := make(map[string]validatorType)
+ fldToValidator["labels"] = metav1validation.ValidateLabels
+ fldToValidator["annotations"] = apivalidation.ValidateAnnotations
+ for fld, validator := range fldToValidator {
obj, found := responseMetaData[fld]
if !found || obj == nil {
delete(convertedMetaData, fld)
@@ -349,11 +353,7 @@ func restoreObjectMeta(original, converted *unstructured.Unstructured) error {
stringMap[k] = v.(string)
}
var errs field.ErrorList
- if fld == "labels" {
- errs = metav1validation.ValidateLabels(stringMap, field.NewPath("metadata", "labels"))
- } else {
- errs = apivalidation.ValidateAnnotations(stringMap, field.NewPath("metadata", "annotation"))
- }
+ errs = validator(stringMap, field.NewPath("metadata", "labels"))
if len(errs) > 0 {
return errs.ToAggregate()
}
The above is expandable: it is trivial to add more supported fields.
Fixes #72160
Specified in kubernetes/enhancements#1063.
TODOs: