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

[PROPOSAL] Add convenience function #66

Closed
sebgoa opened this issue Dec 14, 2016 · 11 comments
Closed

[PROPOSAL] Add convenience function #66

sebgoa opened this issue Dec 14, 2016 · 11 comments
Assignees
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@sebgoa
Copy link
Contributor

sebgoa commented Dec 14, 2016

The client is very low level, it would be great to add a few convenience functions ala kubectl like:

  • kubectl run
  • kubectl expose

Right now starting a simple Pod is a bit "complex" and requires digging through the docs quite a bit to find the correct classes to instantiate. For example:

pod=client.V1Pod()
pod.metadata=client.V1ObjectMeta(name="busy box")

spec=client.V1PodSpec()

container=client.V1Container()
container.image="busybox"
container.args=["sleep", "3600"]
container.name="busybox"

spec.containers = [container]
pod.spec = spec

v1.create_namespaced_pod(namespace="default",body=pod)

It would be nice to have something like:

def run_pod(namespace, image):
    ....
    return v1.create_namespaced_pod(namespace=namespace, body)
@mbohlool
Copy link
Contributor

mbohlool commented Dec 14, 2016

These helper methods are definitely useful and I won't have objection adding them. However the approach is not scalable. I would also suggest we go the route of fluent interface that makes things like this easier like this:

v1.create_namespaced_pod(
    client.V1Pod()
        .metadata_name("busy box")
        .container_image(0, "busybox")
        .container_args(0, ["sleep", "3600"])
        .container_name(0, "busy_box"))

(fluent interface + expanding internal types + array access fluently)

This is not solid yet, just a quick thought. I will write a proposal for it.

@mbohlool
Copy link
Contributor

mbohlool commented Dec 16, 2016

I've had more thoughts on fluent interface, something like this look much better:

 client.V1Pod()
    .edit_metadata()
        .name("busy box")
        .done()
    .add_container()
        .image("busybox")
        .args(["sleep", "3600"])
        .name("busy_box")
        .done()
    .create()

@sebgoa
Copy link
Contributor Author

sebgoa commented Dec 16, 2016

add_metadata() maybe, it is not really an edit method.

@mbohlool
Copy link
Contributor

Maybe, the difference is container is an array, metadata is not.

@djkonro
Copy link
Contributor

djkonro commented Jul 5, 2017

@mbohlool, I just want to let you know that I have started working on this, so any notes you have in mind would be welcomed.

@mbohlool
Copy link
Contributor

mbohlool commented Jul 5, 2017

Would be nice if you can share any design before implementation. I added "x-kubernetes-group-version-kind" and "x-kubernetes-action" in Kubernetes 1.7 spec and I was planning to use that to generate a set of kubernetes friendly object with actions on them based on the generated objects. Not a real design, but I was thinking to do have something like:

from kubernetes import objects
...
pod = objects.V1Pod()   # objects are all in form of GroupVersionKind
or
pod = objects.for_gvk("", "v1", "pod")
# edit pod
pod.create()

@djkonro
Copy link
Contributor

djkonro commented Jul 13, 2017

@mbohlool Sorry for the delayed response, I was traveling to Denver for GopherCon 2017 and I am still in Denver for the Conference but I would just like to make some progress on the issue by the time I return to Cameroon.

Initialy I was hoping to create helper classes for the resources, which would inherite the exiting classes and then implement helper functions for the fluent interface. Below is a sample for what I had in mind.

class PodHelper(V1Pod):

    def edit_metadata(self, name=""):
        #Create metadata object and set name
        return self

    def add_container(self, image="", args=[], name="")
        #Create container with provided details
        return self
        
    def create(self)
        #created pod

We can then create a pod with

client.PodHelper()
    .edit_metadata(name="")
    .add_container(image="", args=[], name="")
    .create()

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 21, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 21, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants