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

Add support for CRDs #105

Merged
merged 2 commits into from
Jun 19, 2018
Merged

Conversation

Liujingfang1
Copy link
Contributor

@Liujingfang1 Liujingfang1 commented Jun 12, 2018

#42

  • assume the crd files are in format as open API definitions
  • read in file content
  • recursively parse types and annotations and construct pathconfig
  • Add a unit test for parsing one CRD file and get the pathconfig
  • Add an integration test

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 12, 2018
@k8s-ci-robot k8s-ci-robot requested review from droot and justinsb June 12, 2018 22:36
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 12, 2018
@Liujingfang1 Liujingfang1 requested review from monopole and removed request for justinsb and droot June 12, 2018 22:36
@Liujingfang1 Liujingfang1 force-pushed the crdsupport branch 4 times, most recently from bcba4ff to 5eacaaa Compare June 13, 2018 16:58
@Liujingfang1 Liujingfang1 requested a review from mengqiy June 13, 2018 16:59
@Liujingfang1 Liujingfang1 changed the title WIP: Add support for CRDs Add support for CRDs Jun 13, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 13, 2018
@Liujingfang1 Liujingfang1 removed the request for review from monopole June 13, 2018 19:53
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 13, 2018
Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

We also should have a integration test to show the whole thing works together in a Kusomize.yaml.

pkg/crds/crds.go Outdated
return crds
}

func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, crd string, path []string, configs *pathConfigs) error {
Copy link
Member

Choose a reason for hiding this comment

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

line to long. break this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

[]transformers.PathConfig{
{
CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: "github.com/example/pkg/apis/jingfang/v1beta1.MyKind"},
Copy link
Member

Choose a reason for hiding this comment

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

schema.GroupVersionKind{Kind: "github.com/example/pkg/apis/jingfang/v1beta1.MyKind"}

This doesn't look like a correct GVK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to MyKind

pkg/crds/crds.go Outdated
configs.AddAnnotationPathConfig(
transformers.PathConfig{
CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: crd},
Copy link
Member

Choose a reason for hiding this comment

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

IMO this doesn't construct a normal GVK.
We can build GVK from apiVersion and kind. You can use TypeMeta{}.GroupVersionKind().
apiVersion and kind info can be find in your getCRDs method.

@Liujingfang1 Liujingfang1 force-pushed the crdsupport branch 3 times, most recently from e5d617a to 81f9b03 Compare June 14, 2018 18:15
@Liujingfang1
Copy link
Contributor Author

We also should have a integration test to show the whole thing works together in a Kusomize.yaml.

Add an integration test for

  • referring one core type
  • referring another crd type

@Liujingfang1 Liujingfang1 force-pushed the crdsupport branch 3 times, most recently from 1168aeb to 0bdba52 Compare June 14, 2018 20:08
@Liujingfang1 Liujingfang1 requested a review from droot June 14, 2018 20:21
Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

Only concern is how to get the GVK for a CRD.

pkg/crds/crds.go Outdated
}

// getCRDs get all CRD types
func getCRDs(types map[string]common.OpenAPIDefinition) []string {
Copy link
Member

Choose a reason for hiding this comment

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

I think the signature of this method should be
func getCRDs(types map[string]common.OpenAPIDefinition) []GroupVersionKind
As I mentioned in my earlier comment, we can use TypeMeta{APIVersion: apiVersion, Kind: kind}.GroupVersionKind() to get a GVK.
Each GVK should map to a CRD.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about this
func getCRDs(types map[string]common.OpenAPIDefinition) map[string]GroupVersionKind
I need that the string name such as "github.com/example/pkg/apis/jingfang/v1beta1.MyKind" to find the corresponding openAPIdefinition in getCRDPathConfig. If we return a map, we have both the string name and GVK available.

pkg/crds/crds.go Outdated
}

// getCRDPathConfig gets pathConfigs for one CRD recursively
func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, crd string,
Copy link
Member

Choose a reason for hiding this comment

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

crd string should be changed to crd GroupVersionKind.
This can be done if the getCRDs method returns a slice of GVK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we can return a map[string]GroupVersionKind from getCRDs, we can use it here.

pkg/crds/crds.go Outdated
configs.addAnnotationPathConfig(
transformers.PathConfig{
CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: crdname},
Copy link
Member

Choose a reason for hiding this comment

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

Only using the kind name can collide with another CRD.
If you have changed the signature of this method, you can use the passed-in crd GroupVersionKind.

pkg/crds/crds.go Outdated

for typename, t := range types {
properties := t.Schema.SchemaProps.Properties
if _, ok := properties["kind"]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

Readability:

_, foundKind := properties["kind"]
_, foundAPIVersion := properties["apiVersion"]
_, foundMetadata := properties["metadata"]
if foundKind && foundAPIVersion && foundMetadata {
  crds = append(crds, typename)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix it.

pkg/crds/crds.go Outdated

for typename, t := range types {
properties := t.Schema.SchemaProps.Properties
if _, ok := properties["kind"]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

IIRC "kind" in properties doesn't have the same meaning as in k8s.
We should think more carefully about how to handle GVK here.
Let's discuss this tomorrow morning.

@Liujingfang1 Liujingfang1 force-pushed the crdsupport branch 3 times, most recently from 398f9bc to 2d7ef05 Compare June 18, 2018 18:28
Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

/lgtm
Please squash unnecessary commit(s) :)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2018
implement CRD support and add unit tests

Add integration test for crd support

address comments
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2018
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@Liujingfang1
Copy link
Contributor Author

squashed commits

@Liujingfang1 Liujingfang1 merged commit d865300 into kubernetes-sigs:master Jun 19, 2018
@Liujingfang1 Liujingfang1 deleted the crdsupport branch August 10, 2018 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

3 participants