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

Support for CRDs #1

Open
wozniakjan opened this issue Jul 26, 2021 · 5 comments
Open

Support for CRDs #1

wozniakjan opened this issue Jul 26, 2021 · 5 comments

Comments

@wozniakjan
Copy link
Owner

wozniakjan commented Jul 26, 2021

This currently has no support for CRDs, but I suspect adding CRDs to the scheme should be sufficient.

// TODO allow adding CRDs to the scheme
codecs := serializer.NewCodecFactory(scheme.Scheme)
obj, _, err := codecs.UniversalDeserializer().Decode(data, nil, nil)
checkFatal(err)
return obj

The plan is to look for these patterns from apimachinery and/or controller-runtime

import (
     "k8s.io/apimachinery/pkg/runtime/schema"
     "sigs.k8s.io/controller-runtime/pkg/scheme"
)
 
var (
    // GroupVersion is group version used to register these objects
    GroupVersion = schema.GroupVersion{Group: "group.k8s", Version: "v1beta1"}

    // SchemeBuilder is used to add go types to the GroupVersionKind scheme
    SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

    // AddToScheme adds the types in this group-version to the given scheme.
    AddToScheme = SchemeBuilder.AddToScheme
)
@wozniakjan
Copy link
Owner Author

native support for CRDs is still not there, but there is a fallback to unstructured #10

@veggiemonk
Copy link

@wozniakjan Great work! Really interesting to read how you solved the CRDs puzzle with unstructured. Too bad I didn't know about this project earlier, we had to build our own https://github.com/volvo-cars/lingon
Even made a quick web app with it https://lingonweb.bisconti.cloud/

This is the best I could come up with https://github.com/volvo-cars/lingon/blob/main/docs/kubernetes/crd/readme.md

As you can see in the code, we need to register the CRDs with AddToScheme otherwise it errors https://github.com/volvo-cars/lingon/blob/main/pkg/kube/import.go#L328-L334

I haven't found a better way to deal with those CRDs. I would love to have to opinion on the matter.

@wozniakjan
Copy link
Owner Author

hey @veggiemonk, glad you like it :)

lingon looks really cool, I especially like the idea of interactive webapp to try it. There is also now a similar tool called naml - https://github.com/krisnova/naml, it has some interesting concepts for sure.

This is the best I could come up with https://github.com/volvo-cars/lingon/blob/main/docs/kubernetes/crd/readme.md

and it's pretty much exactly what I would like to do here using AST parser and --crd-packages argument, just haven't found time to finish this yet...

@veggiemonk
Copy link

Thank you 😄

Indeed, I saw naml and it uses https://github.com/hexops/valast to parse the objects. It even figures out all the unexported fields and deal with unsafe.Pointer ...

Another idea was to use the JSON schema to construct the custom resources in Go, a little bit like CUE does it, but that's another rabbit hole.

Do you actually use the generated Go code? Or is this project just for fun?

In any case, I was really happy to have found your project. Happy to discuss it more.

@wozniakjan
Copy link
Owner Author

I had two cases so far where I used this, it started due to this task (albeit was superseded by an alternative approach) kubermatic/kubermatic#7413. But in another project, it did see production use - kyma-incubator/reconciler#722.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants