Skip to content
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

Merged

Conversation

@sttts
Copy link
Contributor

commented May 10, 2019

Fixes #72160

Specified in kubernetes/enhancements#1063.

TODOs:

  • unit tests
  • webhook integration test
In CRD webhook conversion ignore changes to metadata other than for labels and annotations.
@sttts

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2019

/assign @liggitt @jpbetz

@fejta-bot

This comment has been minimized.

Copy link

commented May 10, 2019

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.

@jpbetz
Copy link
Contributor

left a comment

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.

@sttts sttts force-pushed the sttts:sttts-crd-webhook-conversion-metadata branch from ddaa813 to 210a9c3 May 14, 2019

@liggitt

This comment has been minimized.

Copy link
Member

commented May 14, 2019

a few comments, nothing major

@sttts sttts force-pushed the sttts:sttts-crd-webhook-conversion-metadata branch from 210a9c3 to 8c79150 May 14, 2019

@k8s-ci-robot k8s-ci-robot added size/XL and removed size/L labels May 14, 2019

@sttts sttts force-pushed the sttts:sttts-crd-webhook-conversion-metadata branch 3 times, most recently from f7bf465 to 6cef4d4 May 25, 2019

@k8s-ci-robot k8s-ci-robot added size/XXL and removed size/XL labels May 25, 2019

@sttts sttts force-pushed the sttts:sttts-crd-webhook-conversion-metadata branch 2 times, most recently from 4caa3b4 to 2f40b7d May 25, 2019

sttts added 2 commits May 10, 2019

@sttts sttts force-pushed the sttts:sttts-crd-webhook-conversion-metadata branch from 2f40b7d to 4f6d755 May 28, 2019

@k8s-ci-robot k8s-ci-robot added size/XL and removed size/XXL labels May 28, 2019

@sttts

This comment has been minimized.

Copy link
Contributor Author

commented May 28, 2019

Rebased

@liggitt @jpbetz please take a look.

@sttts sttts force-pushed the sttts:sttts-crd-webhook-conversion-metadata branch from 4f6d755 to 9814914 May 28, 2019

@sttts

This comment has been minimized.

Copy link
Contributor Author

commented May 28, 2019

/retest

empty verify log

@liggitt

This comment has been minimized.

Copy link
Member

commented May 28, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm label May 28, 2019

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

commented May 28, 2019

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jpbetz

This comment has been minimized.

Copy link
Contributor

commented May 28, 2019

/lgtm

@liggitt

This comment has been minimized.

Copy link
Member

commented May 28, 2019

/retest

@liggitt liggitt added this to Required for GA, in progress in Custom Resource Definitions May 28, 2019

@k8s-ci-robot k8s-ci-robot merged commit 358bfe3 into kubernetes:master May 29, 2019

20 checks passed

cla/linuxfoundation sttts authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-conformance-image-test Skipped.
pull-kubernetes-cross Skipped.
pull-kubernetes-dependencies Job succeeded.
Details
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-csi-serial Skipped.
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gce-storage-slow Skipped.
pull-kubernetes-godeps Skipped.
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped.
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
pull-publishing-bot-validate Skipped.
tide In merge pool.
Details
stringMap[k] = v.(string)
}
var errs field.ErrorList
if fld == "labels" {

This comment has been minimized.

Copy link
@tedyu

tedyu May 29, 2019

Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.