-
Notifications
You must be signed in to change notification settings - Fork 3
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
Example of how to create a CRD #96
Comments
Thank you for submitting this issue and welcome! |
Hi, import dev.hnaderi.k8s.manifest
val obj = manifest.parse("file content") Having a custom resource object at hand, you can then create any API requests you want. Also, for creating your own custom requests, you need to implement |
Right, I think I have a clue where I've gone wrong, thanks. I'll report back if unsuccessful or I'll close this ticket. I couldn't tell you how popular |
I will add the APIs ASAP! |
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")
libraryDependencies ++= Seq(
"dev.hnaderi" %% "scala-k8s-client" % "0.11-19e12b0-SNAPSHOT"
) This version contains CRD APIs and more cluster wide APIs as well, Your feedback is highly appreciated! val define = APIs.crds.create(???)
val replace = APIs.crds.replace("name", ???)
// and a lot of more methods |
Hi @hnaderi, many thanks for the new APIs! We've done some testing (still going), getting a CRD works perfectly, but we're having a bit of trouble doing the creation call. We followed your suggestion of loading the manifest using We're going to try using a different method to load the data and convert it to a I wonder if Separate comment: I noticed that all the error types are encoded to Thanks again! |
Actually that's also possible, the manifest module has changed recently to use yaml4s, which you can use to decode/encode any of the objects in scala k8s, as all the codecs are available. |
That's a good idea and can be really helpful, I wonder why I didn't do it like that in the first place?! 😅 |
Hi @hnaderi - thanks for the quick turn around. Wasn't sure if you'd published that but I've published it locally and it looks good! However, we're now getting this error when we try and use the loaded CRD with
Any ideas? Is there a more meaningful message we could get back somehow? |
This comment was marked as resolved.
This comment was marked as resolved.
@davesmith00sky Kubernetes responds with 422 when it can't process the your request. |
Hi @hnaderi, so there was a bunch of things going on. The issue isn't resolved but I have more information. The proxy logs don't have much to say of any interest (to my eyes anyway), this is the relevant bit:
Is there anywhere else I can check? I have two examples that I'm playing with and as it turns out, the 422 was masking two different errors, which I found by running
However, if I fix those to issues (1. remove, 2. correct the name) and run again I get another 422 status code. Maybe I could run something like Charles proxy in front of my kubectl proxy and see what the request looks like (as-in the serialised data)? Any other suggestions? |
@davesmith00sky I think it's better to get it working on the Also to see the serialized data you can simply re-encode your object, to yaml or json. obj.encodeTo[Json] |
Oh sorry, it does work with |
Also to check if there is a problem with serialization, it would be helpful to use |
Charles proxy to the rescue! (
...and sure enough when I looked at the I hadn't added |
I think the kubectl updating the manifest on the fly is more likely, can you check that by the Charles proxy as well? |
I.... don't think so. 😅 I've had a bit of a look around and I'm not sure how I'd set that up. |
Hi @hnaderi - I'm back from a long weekend, hope you're well. 😄 So I've done some more digging and the culprit is here! final case class CustomResourceDefinitionNames(
plural : String,
singular : Option[String] = None,
listKind : Option[String] = None,
categories : Option[Seq[String]] = None,
shortNames : Option[Seq[String]] = None
) Note that this is missing the
So far so good. (I like how you defined the plugin to do that, btw - nice!) The trouble is that it isn't working correctly. If you go to the spec, you can clearly see the Here's the spec, search for ...and you get this: "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionNames": {
"description": "CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition",
"properties": {
"categories": {
"description": "categories is a list of grouped resources this custom resource belongs to (e.g. 'all'). This is published in API discovery documents, and used by clients to support invocations like `kubectl get all`.",
"items": {
"type": "string"
},
"type": "array"
},
"kind": {
"description": "kind is the serialized kind of the resource. It is normally CamelCase and singular. Custom resource instances will use this value as the `kind` attribute in API calls.",
"type": "string"
},
"listKind": {
"description": "listKind is the serialized kind of the list for this resource. Defaults to \"`kind`List\".",
"type": "string"
},
"plural": {
"description": "plural is the plural name of the resource to serve. The custom resources are served under `/apis/<group>/<version>/.../<plural>`. Must match the name of the CustomResourceDefinition (in the form `<names.plural>.<group>`). Must be all lowercase.",
"type": "string"
},
"shortNames": {
"description": "shortNames are short names for the resource, exposed in API discovery documents, and used by clients to support invocations like `kubectl get <shortname>`. It must be all lowercase.",
"items": {
"type": "string"
},
"type": "array"
},
"singular": {
"description": "singular is the singular name of the resource. It must be all lowercase. Defaults to lowercased `kind`.",
"type": "string"
}
},
"required": [
"plural",
"kind"
],
"type": "object"
} Note: "kind": {
"description": "kind is the serialized kind of the resource. It is normally CamelCase and singular. Custom resource instances will use this value as the `kind` attribute in API calls.",
"type": "string"
}, and "required": [
"plural",
"kind"
], What do you think is going on? |
@davesmith00sky Welcome back! 😊 |
Thank you kindly! |
I close this issue as it is resolved in other issues. |
Hi @hnaderi,
Between being fairly new to k8s and
scala-k8s
, I'm struggling to figure out how to create a CRD from a manifest. I've tried a few things, but essentially what I'm trying to do is simply the equivalent of:kubectl apply -f my-crd-manifest.yaml
Where
my-crd-manifest.yaml
contains the definition of a CRD.Could you point me in the right direction please?
Once I've got it set up, I've got some custom look ups defined that are based on the example in the readme. Can I just check if that is the right way to go about that?
Thanks in advance.
The text was updated successfully, but these errors were encountered: