Skip to content

🐛 Add apiextensions JSON type to known_types.go - #277

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:masterfrom
munnerz:apiextensions-json-type
Oct 7, 2019
Merged

k8s-ci-robot merged 1 commit into
kubernetes-sigs:masterfrom
munnerz:apiextensions-json-type

Conversation

@munnerz

@munnerz munnerz commented Jul 23, 2019

Copy link
Copy Markdown
Member

Adds support for the apiextensions-apiserver JSON type.

Without this patch I get the following error:

/Users/james/go/src/github.com/jetstack/cert-manager/vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types_jsonschema.go:98:2: enountered struct field "Raw" without JSON tag in type "JSON"

/cc @DirectXMan12

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 23, 2019
Comment thread pkg/crd/known_types.go Outdated

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1": func(p *Parser, pkg *loader.Package) {
p.Schemata[TypeIdent{Name: "JSON", Package: pkg}] = apiext.JSONSchemaProps{
Type: "string",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure if the type here should be string or something else - the existing Golang code doesn't actually specify.

cc @sttts any ideas?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type string is wrong. This is arbitrary JSON, like RawExtension but without Type/ObjectMeta.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some testing, I've updated this to object. I think this is correct, although it may not accept data which is a string whereas it probably should given JSON is meant to be completely unstructured.

What's the proper way to set this? It looks like the Kubernetes APIServer exposes an object with a field named Raw of type string in the OpenAPI schema for RawExtension which I think would also be incorrect?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also object is wrong. This is pure JSON, any type. In other words, no type should be set at all.

But you have to set x-kubernetes-preserve-unknown-fields: true.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiext.JSONSchemaProps{
  XPreserveUnknownFields: true,
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks, so it seems like this requires #276 then!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@munnerz

munnerz commented Aug 1, 2019

Copy link
Copy Markdown
Member Author

I've updated our repo (cert-manager/cert-manager#1946) to use this, however now run into an issue when installing these CRDs on anything older than Kubernetes 1.15, presumably because the new field on the CRD does not exist before 1.15.

With preserveUnknownFields eventually flipping to true by default in future, this is going to be a big PITA for us as we'll have to ship manifests specifically for k8s <= 1.14. Just a heads up really, and I assume it's accounted for already in the 'flip the default' plan. I'd hope that 1.14 would be EOL before this default flips 😄

For controller-tools specifically, I'm not sure how best to proceed. It'd be great if this sort of thing can be handled, but in reality it can't be handled properly yet, so maybe this patch should also be skipped until 1.14 is EOL 🙄

@sttts

sttts commented Aug 1, 2019

Copy link
Copy Markdown
Contributor

however now run into an issue when installing these CRDs on anything older than Kubernetes 1.15, presumably because the new field on the CRD does not exist before 1.15.

What is the issue? Unsupported fields are ignored by the API server.

@DirectXMan12

Copy link
Copy Markdown
Contributor

unsupported fields are ignored by the server, but hated by kubectl due to client-side schema validation, which is on by default.

Everyone always seems to forget that, and then it causes headaches down the line.

@sttts

sttts commented Aug 6, 2019

Copy link
Copy Markdown
Contributor

kubebuilder needs a mode for pruned CRDs. In that case, the x-kubernetes-preserve-unknown-fields: true field should be set.

@DirectXMan12

Copy link
Copy Markdown
Contributor

We have 1.15 types now, so this can be updated

/hold

until then

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 17, 2019
@munnerz
munnerz force-pushed the apiextensions-json-type branch from 401683e to 300f61b Compare September 23, 2019 17:18
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 25, 2019
@sttts

sttts commented Sep 25, 2019

Copy link
Copy Markdown
Contributor

lgtm

@munnerz

munnerz commented Sep 25, 2019

Copy link
Copy Markdown
Member Author

Looks like this is ready for merge now, just needs lgtm and approved labels! 😄

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 25, 2019
@munnerz

munnerz commented Sep 26, 2019

Copy link
Copy Markdown
Member Author

/assign @DirectXMan12

Comment thread pkg/crd/known_types.go Resolved
@munnerz
munnerz force-pushed the apiextensions-json-type branch from 3ef7111 to d30e5fc Compare October 2, 2019 18:25
@munnerz

munnerz commented Oct 2, 2019

Copy link
Copy Markdown
Member Author

Updated to inline the function, mind taking another look @DirectXMan12?

@DirectXMan12

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 7, 2019
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12, munnerz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 7, 2019
@k8s-ci-robot
k8s-ci-robot merged commit 83f6193 into kubernetes-sigs:master Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants