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

Ability to create custom objects #430

Closed
robertgates55 opened this issue Dec 31, 2019 · 2 comments
Closed

Ability to create custom objects #430

robertgates55 opened this issue Dec 31, 2019 · 2 comments

Comments

@robertgates55
Copy link

I've found create_entity but I'm struggling to work out how to use it.

The entity that I'm trying to create is a HelmRelease object - the crd for which looks like:

uk-lon-17:~ robertgates$ kubectl describe crd helmreleases.helm.fluxcd.io
Name:         helmreleases.helm.fluxcd.io
Namespace:
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
             {"apiVersion":"apiextensions.k8s.io/v1beta1","kind":"CustomResourceDefinition","metadata":{"annotations":{},"name":"helmreleases.helm.flux...
API Version:  apiextensions.k8s.io/v1beta1
Kind:         CustomResourceDefinition
Metadata:
  Creation Timestamp:  2019-12-31T16:22:35Z
  Generation:          1
  Resource Version:    717521
  Self Link:           /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/helmreleases.helm.fluxcd.io
  UID:                 c15d1bd8-2be9-11ea-aeb5-025000000001
Spec:
  Additional Printer Columns:
    JSON Path:  .status.releaseName
    Name:       Release
    Type:       string
    JSON Path:  .status.releaseStatus
    Name:       Status
    Type:       string
    JSON Path:  .status.conditions[?(@.type=="Released")].message
    Name:       Message
    Type:       string
    JSON Path:  .metadata.creationTimestamp
    Name:       Age
    Type:       date
  Conversion:
    Strategy:  None
  Group:       helm.fluxcd.io
  Names:
    Kind:       HelmRelease
    List Kind:  HelmReleaseList
    Plural:     helmreleases
    Short Names:
      hr
    Singular:  helmrelease
  Scope:       Namespaced
....

How can I use the kubeclient to create an object of this type? Believe I can use create_entity but can't work out which value needs to go where!

@cben
Copy link
Collaborator

cben commented Jan 1, 2020

CRDs are not special in kubeclient, they're just another api group.
First you need a Client object for the right api group, something like:

helm_client = Kubeclient::Client.new('http://localhost:8080/apis/helm.fluxcd.io', 'v1', ...)

Then, the kind is transformed into method names, so it should be possible to use helm_client.create_helm_release(...), helm_client.get_helm_release(...), helm_client.get_helm_releases(...), etc.
(Internally, a discovery request is made first in order to define the methods. But it's automatic, from your perspective you can call these methods immediately after constructing the Client)

Currently, it's impossible to use a single Client for multiple api groups. You'd need one Client for all helm.fluxcd.io operations, another for pods and other core 'v1' resources, etc...


If you only need operations on fixed hard-coded kinds, the above is all you need, no need for create_entity().

If you have a use case where the kind is dynamic (e.g. #329), create_entity() and friends are undocumented and considered internal. We'd like to replace them with a better thought-out interface (#332), and for now it's better to do client.public_send("create_#{...}", ...), clunky as that is, because that will keep working.

@cben
Copy link
Collaborator

cben commented Jan 12, 2020

Closing in hope I answered you, fel free to reply and/or reopen if not

@cben cben closed this as completed Jan 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants