-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add support for CRDs #105
Conversation
bcba4ff
to
5eacaaa
Compare
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.
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 { |
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.
line to long. break this line
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.
pkg/crds/crds_test.go
Outdated
[]transformers.PathConfig{ | ||
{ | ||
CreateIfNotPresent: false, | ||
GroupVersionKind: &schema.GroupVersionKind{Kind: "github.com/example/pkg/apis/jingfang/v1beta1.MyKind"}, |
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.
schema.GroupVersionKind{Kind: "github.com/example/pkg/apis/jingfang/v1beta1.MyKind"}
This doesn't look like a correct GVK.
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 it to MyKind
pkg/crds/crds.go
Outdated
configs.AddAnnotationPathConfig( | ||
transformers.PathConfig{ | ||
CreateIfNotPresent: false, | ||
GroupVersionKind: &schema.GroupVersionKind{Kind: crd}, |
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.
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.
e5d617a
to
81f9b03
Compare
Add an integration test for
|
1168aeb
to
0bdba52
Compare
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.
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 { |
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.
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.
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.
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, |
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.
crd string
should be changed to crd GroupVersionKind
.
This can be done if the getCRDs
method returns a slice of GVK.
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 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}, |
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.
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 { |
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.
Readability:
_, foundKind := properties["kind"]
_, foundAPIVersion := properties["apiVersion"]
_, foundMetadata := properties["metadata"]
if foundKind && foundAPIVersion && foundMetadata {
crds = append(crds, typename)
}
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.
will fix it.
pkg/crds/crds.go
Outdated
|
||
for typename, t := range types { | ||
properties := t.Schema.SchemaProps.Properties | ||
if _, ok := properties["kind"]; ok { |
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.
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.
398f9bc
to
2d7ef05
Compare
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.
/lgtm
Please squash unnecessary commit(s) :)
implement CRD support and add unit tests Add integration test for crd support address comments
New changes are detected. LGTM label has been removed. |
squashed commits |
#42