-
Notifications
You must be signed in to change notification settings - Fork 40k
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
fix apiserver crash caused by nil pointer #58438
Conversation
/ok-to-test |
/retest |
@@ -318,6 +305,10 @@ func (v *specStandardValidatorV3) validate(schema *apiextensions.JSONSchemaProps | |||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("dependencies"), "dependencies is not supported")) | |||
} | |||
|
|||
if schema.Ref != nil { | |||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("$ref"), "$ref is not supported")) |
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.
just ref
here i.e. $ref
-> ref
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
We should cherry pick this PR to 1.8 and 1.9. |
/cc @sttts |
@@ -314,12 +314,13 @@ func (r *crdHandler) removeDeadStorage() { | |||
|
|||
// GetCustomResourceListerCollectionDeleter returns the ListerCollectionDeleter for | |||
// the given uid, or nil if one does not exist. | |||
func (r *crdHandler) GetCustomResourceListerCollectionDeleter(crd *apiextensions.CustomResourceDefinition) finalizer.ListerCollectionDeleter { | |||
func (r *crdHandler) GetCustomResourceListerCollectionDeleter(crd *apiextensions.CustomResourceDefinition) (finalizer.ListerCollectionDeleter, error) { | |||
info, err := r.getOrCreateServingInfoFor(crd) | |||
if err != nil { | |||
utilruntime.HandleError(err) |
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.
If a error returned, there is no need 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.
fixed
@carlory run update bazel |
@hzxuzhonghu thank you |
/test pull-kubernetes-node-e2e |
/test pull-kubernetes-e2e-kops-aw |
/test pull-kubernetes-verify |
/test pull-kubernetes-e2e-kops-aw |
/retest |
@@ -318,6 +312,10 @@ func (v *specStandardValidatorV3) validate(schema *apiextensions.JSONSchemaProps | |||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("dependencies"), "dependencies is not supported")) | |||
} | |||
|
|||
if schema.Ref != nil { |
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.
Does this mean we forbid schemata like described in https://spacetelescope.github.io/understanding-json-schema/structuring.html with local definitions? Then I do not agree with this PR.
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.
To my understanding the id
of a document is only used as a base for relative references. With #/definitions/foo
you can reference absolute definitions. The later is completely fine and users might use them. If we forbid that suddenly, we break compatibility.
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.
@sttts We don't support definitions now:
Lines 313 to 315 in 23226c2
if len(schema.Definitions) != 0 { | |
allErrs = append(allErrs, field.Forbidden(fldPath.Child("definitions"), "definitions is not supported")) | |
} |
because OpenAPI v3 does not support definitions (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject)
Ref
is used in OpenAPI v3 like this: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#reference-object.
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.
Alright. Poor OpenAPI (again). Then, without definitions my concerns are gone.
/unhold
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.
thanks for your review
/hold until #58438 (review) is discussed. |
Shortened and clarified release notes. |
@@ -318,6 +312,10 @@ func (v *specStandardValidatorV3) validate(schema *apiextensions.JSONSchemaProps | |||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("dependencies"), "dependencies is not supported")) | |||
} | |||
|
|||
if schema.Ref != nil { | |||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("ref"), "ref is not supported")) |
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.
Shouldn't this be $ref
?
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.
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 should match the json field
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.
@liggitt ok
if err := apiservervalidation.ConvertToOpenAPITypes(crd, openapiSchema); err != nil { | ||
return nil, err | ||
} | ||
if err := openapispec.ExpandSchema(openapiSchema, nil, nil); err != nil { |
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.
are we sure this is only about expanding refs?
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.
@sttts
yes, see this comment
err := fmt.Errorf("unable to find a custom resource client for %s.%s", crd.Status.AcceptedNames.Plural, crd.Spec.Group) | ||
crClient, err := c.crClientGetter.GetCustomResourceListerCollectionDeleter(crd) | ||
if err != nil { | ||
err = fmt.Errorf("unable to find a custom resource client for %s.%s due to %v", crd.Status.AcceptedNames.Plural, crd.Spec.Group, err) |
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.
s/ due to/:/
, let's use the normal error style of Go
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.
you are right.
// if validation passed otherwise, make sure we can actually construct a schema validator from this custom resource validation. | ||
if len(allErrs) == 0 { | ||
if _, err := apiservervalidation.NewSchemaValidator(customResourceValidation); err != nil { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("customResourceValidation"), "", fmt.Sprintf("error building validator: %v", err))) |
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.
wrong child string. I guess we do not need any child at all here.
/test pull-kubernetes-e2e-kops-aws |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: carlory, sttts Associated issue: #58427 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 |
[MILESTONENOTIFIER] Milestone Pull Request Needs Approval @carlory @deads2k @enisoc @lavalamp @sttts @kubernetes/sig-api-machinery-misc Action required: This pull request must have the Pull Request Labels
|
Please create a cherry-pick for 1.9. |
/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. |
I can do it. |
…58438-#58914-origin-release-1.9 Automatic merge from submit-queue. Automated cherry pick of #58438: fix apiserver crash caused by nil pointer and ensure CRD #58914: fix GetCustomResourceListerCollectionDeleter comments Cherry pick of #58438 #58914 on release-1.9. #58438: fix apiserver crash caused by nil pointer and ensure CRD #58914: fix GetCustomResourceListerCollectionDeleter comments ```release-note CustomResourceDefinitions: OpenAPI v3 validation schemas containing `$ref`references are no longer permitted. Before upgrading, ensure CRD definitions do not include those `$ref` fields. ```
Commit found in the "release-1.9" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked. |
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #58427
Release note: