Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Support for retrieving logs for pods #36

Closed
pcm32 opened this issue Apr 14, 2016 · 8 comments
Closed

Support for retrieving logs for pods #36

pcm32 opened this issue Apr 14, 2016 · 8 comments

Comments

@pcm32
Copy link
Contributor

pcm32 commented Apr 14, 2016

What would be needed to support log retrieval from pods like you do with kubectl logs mypod

I'm happy to start coding something with some directions.

@brosner
Copy link
Contributor

brosner commented Apr 14, 2016

I am excited to see this feature. The best place to start is to scope out the API call(s) needed to accomplish this. If I were implementing this, I would start with dissecting what kubectl logs does and translate it to API calls that can be made by pykube.

@pcm32
Copy link
Contributor Author

pcm32 commented Apr 14, 2016

Thanks @brosner. According to http://kubernetes.io/docs/api-reference/v1/operations/ this implies making a GET request to

/api/v1/namespaces/{namespace}/pods/{name}/log

plus some query parameters for the GET. I presume that this should be a method on the Pod object, right, something like

def get_logs(self, container=None):
    url_base = some_pykube_method_that_does_this()
    query_params = { 'pretty': True, ... other query_params}
    if container is not None:
        query_params['container'] = container
    return self.api.get( url_base + 
             '/api/v1/namespaces/' + self.namespace() + '/pods/' +  + '/log', query_params )

this leads me to the following questions:

  • from where in pykube API do I get the base URL for the call?
  • am I correct in passing the GET query parameters as kwargs?

@pcm32 pcm32 mentioned this issue Apr 18, 2016
@pcm32
Copy link
Contributor Author

pcm32 commented Apr 18, 2016

Have made a pull request to solve this issue. Usage is as follows:

pykube_api = HTTPClient(KubeConfig.from_file("/path/to/your/.kube/config_kubecluster"))
pre_pod = Pod.objects(pykube_api).filter(selector="app=yourApp") 
# line above can be changed by any query that returns a Pod
pod_obj = Pod(pykube_api, pre_pod.response['items'][0]) 
log_txt = pod_obj.logs()

@Chris-Dee
Copy link

Has there been any progress on this since ? Or is unmerged #38 above still the latest progress?

@brosner
Copy link
Contributor

brosner commented Aug 31, 2016

The PR is the latest progress. I hope to spend a few hour session on pykube this week to get many of the PRs wrapped up and merged in.

@pcm32
Copy link
Contributor Author

pcm32 commented Oct 6, 2016

This is now fixed, and awaiting to be merged on #38 !

@tobegit3hub
Copy link

Thanks @pcm32 👍

Looking forward to this feature as well. Can anyone help to review and merge this?

@brosner
Copy link
Contributor

brosner commented Oct 26, 2016

This feature will be in 0.14.0.

@brosner brosner closed this as completed Oct 26, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants