Skip to content

✨ CRD v1 support - #356

Merged
k8s-ci-robot merged 10 commits into
kubernetes-sigs:masterfrom
DirectXMan12:feature/crd-v1
Nov 6, 2019
Merged

k8s-ci-robot merged 10 commits into
kubernetes-sigs:masterfrom
DirectXMan12:feature/crd-v1

Conversation

@DirectXMan12

@DirectXMan12 DirectXMan12 commented Nov 5, 2019 •

Copy link
Copy Markdown
Contributor

This introduces CRD v1 support, as well as support for generating CRDs in multiple versions of the CRD type itself (apiextensions/v1 and apiextensions/v1beta1 currently).

crd-gen and schemapatcher both have support for the new format.

The default in crd-gen is now to generate both v1beta1 and v1, with the first specified version (or v1beta1 if default) getting an unsuffixed file name, and the rest getting something that looks like <old-name>.<crd-version>.yaml.

This also contains a couple of utility updates, such as fixing up some helpers for regenerating testdata and some missed generator help generation.

Fixes #352

This includes all the basic imports from apiextensions/v1 -->
apiextensions/v1beta1 that didn't also have signification code changes.
@DirectXMan12
DirectXMan12 requested a review from sttts November 5, 2019 04:52
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 5, 2019
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 5, 2019
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12

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 Nov 5, 2019
@DirectXMan12
DirectXMan12 requested review from marun and removed request for pwittrock November 5, 2019 04:53
@DirectXMan12

Copy link
Copy Markdown
Contributor Author

cc @sttts @droot

It was previous possible for a generator implementation to become
non-hashable by adding non-hashable fields, and since interface values
compare by deferencing to their underlying values, this was a problem.

This changes it to refer to everything by a *pointer* to a Generator,
which just compares the pointer value.  Since we're shipping around
unique instances anyway, this is fine.
Comment thread Gopkg.lock
@@ -1,382 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.

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.

finally 🎉

Comment thread pkg/schemapatcher/gen.go
return fmt.Errorf("failed to set versioned schemas for %s: %v", existingInfo.GroupKind, err)
if err := existingSet.setVersionedSchemata(); err != nil {
return fmt.Errorf("failed to set versioned schemas for %s: %v", existingSet.GroupKind, err)
}

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.

the top-level field does not exist anymore in v1. You always set schemas, subresources etc. in the versions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep. I can probably make it clearer, but if you look at the source for setGlobalSchema, it only does so if it's looking at a v1beta1 CRD, and delegates back to setVersionedSchemata for the v1 CRD. We might want to rename the methods...

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.

yep, looks good

@droot droot left a comment

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.

Overall looks good. have minor comments/questions.

Comment thread .run-controller-gen.sh
current_dir=$(pwd)
if ! readlink -f . &>/dev/null; then
echo "you're probably on OSX. Please install gnu readlink -- otherwise you're missing the most useful readlink flag."
exit 1

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.

ha ha :)

Comment thread pkg/crd/gen.go Outdated

if len(crdVersions) == 0 {
// put v1beta1 first to make it the "default" file for compatibility purposes
crdVersions = []string{"v1beta1", "v1"}

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.

Not sure if this requires major version bump for controller-tools. In a way, it changes the default behavior. I am fine with bumping up 0.3.0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's a problem because v1beta1 is still in the same named file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we can just not generate v1 at all by default as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

let's just do that and eventually change to make this the default

Comment thread pkg/crd/gen.go

versionedCRDs := make([]interface{}, len(crdVersions))
for i, ver := range crdVersions {
conv, err := AsVersion(crdRaw, schema.GroupVersion{Group: apiext.SchemeGroupVersion.Group, Version: ver})

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.

Summarizing our offline conversation --> so if I am using v1 specific feature (say defaulting), generated v1beta1 CRD will have defaulting specific features enabled, but when submitted to API-Server will result an error.
So current KB projects will run in to this issue when they start using v1 features. Still wondering if there is a better way to handle this transition.

This updates crd-gen to support generating CRDs of multiple "encodings"
of the CRD itself (i.e. versions of the CRD object).  Currently that
means v1 and v1beta1.  It defaults to all known versions, each getting
their own file.  The first version specified (v1beta1 by default) gets a
non-suffixed, file, the rest are suffixed with their version.
The internal_version stuff shouldn't've had its own go.mod or go
generate command -- it's intentionally part of the parent test suite.
This updates the testdata for CRD v1.  All the changes are just
description wrapping.  We only test generation of CRD v1, since we now
rely entirely on the k/apiextensions-apiserver conversion logic to do
the hoisting of the common versions (and have separate tests for that).
This makes deepcopy-gen's testdata's go:generate comment use the run
script to run controller-gen, meaning people updating it will always
get the local copy of controller-gen without having to build it
separately.
The webhook was missing generated help for its generator marker.  This
fixes that.
This updates schemapatcher to match the changes in crd-gen.  It'll now
patch all CRD versions present, and only hoist when in the legacy
(v1beta1) version.
This updates the schemapatcher testdata to work with the previous
commit, which introduced multi-CRD-version support.
Run `go mod tidy`, remove unused dep support now that go 1.13 is around.
@droot droot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 6, 2019
@k8s-ci-robot
k8s-ci-robot merged commit 3038b25 into kubernetes-sigs:master Nov 6, 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRD v1 support

4 participants