Giter Site home page Giter Site logo

Comments (5)

nikhita avatar nikhita commented on August 16, 2024

go client to create one crd

Do you mean how you can create a CRD programatically using a Go client?

You can use the apiextensions client - https://github.com/kubernetes/apiextensions-apiserver/blob/master/pkg/client/clientset/clientset/typed/apiextensions/v1beta1/customresourcedefinition.go.

Here is an example on how to use it: https://github.com/kubernetes/kube-deploy/blob/6fd78203fdd2fde0069b8e0f63788f8e7fd63c52/cluster-api/api/cluster/v1alpha1/crd.go#L25-L73.

However, in general, we do not suggest creating a CRD in this way (also the reason why sample-controller doesn't do this). Creating CRDs is not a permission you regularly want to grant to a controller. Instead, it's better for the admin to do it at the time of deploy so you don’t have to grant more privileges to the controller executable than it actually needs.

from sample-controller.

hochuenw avatar hochuenw commented on August 16, 2024

Hi nikhita, I mean after crd is registered in k8s (e.g. kubectl create -f artifacts/examples/crd.yaml), how to run a crd instance in go instead of kubectl create -f artifacts/examples/example-foo.yaml. It seems possible to use a k8s dynamic client and Unstructured type?

from sample-controller.

krmayankk avatar krmayankk commented on August 16, 2024

@nikhita why is this not recommended to do creation using the client ? We are internally using the extensions client to do this in an automated way . Also How do you block this ?

from sample-controller.

nikhita avatar nikhita commented on August 16, 2024

how to run a crd instance in go instead of kubectl create -f artifacts/examples/example-foo.yaml. It seems possible to use a k8s dynamic client and Unstructured type?

@hochuenw You can use a typed client i.e. client generated from code-generator and use the Create() method - https://github.com/kubernetes/sample-controller/blob/master/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go#L99.

Also, the sample-controller uses the Update method (https://github.com/kubernetes/sample-controller/blob/master/controller.go#L334) so you can probably use that as a reference.

from sample-controller.

nikhita avatar nikhita commented on August 16, 2024

@nikhita why is this not recommended to do creation using the client ?

@krmayankk Creating a CRD is a privileged operation. If you are creating the CRD using the controller, it means your controller has privileged permissions - which isn't really necessary and can be avoided.

Also How do you block this ?

Sorry, I am not sure I follow the question. How to block what?

from sample-controller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.