Git Product home page Git Product logo

python's People

Contributors

ananya2001-an avatar bpicolo avatar brendandburns avatar cclauss avatar dependabot[bot] avatar dims avatar djangopeng avatar djkonro avatar fabianvf avatar goddenrich avatar iamneha avatar iciclespider avatar itaru2622 avatar jonasdlindner avatar k8s-ci-robot avatar mbohlool avatar micw523 avatar oz123 avatar palnabarun avatar pmareke avatar pokoli avatar prabha1331 avatar priyankasaggu11929 avatar roycaihw avatar ryphon avatar spiffxp avatar tomplus avatar vishnu667 avatar xg0719 avatar yliaog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python's Issues

ThirdParty resources support

If we create a 3rd party resource, it creates a new API group.

I am not sure how kubectl implements it, but we need to have an example on how to do this with this client.

For example, say I create a 3rd party resource called snake. In kubectl I can do:

kubectl get snakes

It dynamically learns of new resources in new API groups.

How to create a NFS volume?

Hello,

I'm creating deployments with a NFS volume like this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  ...
  labels:
    ...
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        ...
      spec:
      containers:
      - image: ...
        name: ...
        imagePullPolicy: Always
        env:
        - name: foo
          value: "bar"
        ports:
        - containerPort: 80
          name: foobar
        volumeMounts:
        - mountPath: /var/www/foo
          name: foo-mount
        resources:
          requests:
            memory: "128Mi"
          limits:
            memory: "512Mi"
      volumes:
      - name: foo-mount
        nfs:
          path: /opt/nfs/foo
          server: 10.1.0.123

Is this possible the python kubernetes client? The V1Volume don't specify the needed parameters, like the "nfs" option.

The k8s API definition for V1Volume mention several possible options, including NFS: http://kubernetes.io/docs/api-reference/extensions/v1beta1/definitions/#_v1_volume

There is also the v1.NFSVolumeSource: http://kubernetes.io/docs/api-reference/extensions/v1beta1/definitions/#_v1_nfsvolumesource

If this is not implemented yet, can I help somehow?

Generate.sh should download spec from a release branch in k8s

Current scripts/genrate.sh script assumes kubernetes is on $KUBE_ROOT and gets the swagger.spec file from there. It should actually download an specific version of spec from github instead. This version should be in passed to preprocessing script to be set inside the spec (until kubernetes set the right version).

Write How-To page(s)

Things like #63 is possible with current client but not clear how to. A set of how-to articles would be really useful for these kind of stuff.

`read_namespaced_pod_log` get None response

When I use kubectl logs ms-999-near-090248-357595620-lze7r, I can get container log messages. But the following code get response with None message:

import os
from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config(os.environ["HOME"] + '/.kube/config')

def callback_func(response):
  print(response)

api = client.CoreV1Api()
api.read_namespaced_pod_log("ms-999-near-090248-357595620-lze7r", "default", callback=callback_func)

The exec result is:

{'metadata': None, 'spec': None, 'status': None}

Is this way to call read_namespaced_pod_log not appropriate?

Value Error - list namespaced config map

Hi,

I have he following code snippet (I want all config maps in a specific namespace):

api_instance = client.CoreV1Api()
api_response = None
try:
    api_response = api_instance.list_namespaced_config_map(namespace, pretty=True)
except ApiException as e:
    print("Exception when calling CoreV1Api->list_namespaced_config_map: %s\n" % e)

but when I execute it I get the following Error (if no config map exists in the namespace) :

python3 quobyte-k8s-deployer.py                                                                                                                                                                        
Traceback (most recent call last):
  File "quobyte-k8s-deployer.py", line 126, in <module>
    main()
  File "quobyte-k8s-deployer.py", line 112, in main
    create_configmap(quobyte_config['namespace'], quobyte_config['kubernetes_files']['path'])
  File "quobyte-k8s-deployer.py", line 45, in create_configmap
    api_response = api_instance.list_namespaced_config_map(namespace, pretty=True)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/core_v1_api.py", line 12359, in list_namespaced_config_map
    (data) = self.list_namespaced_config_map_with_http_info(namespace, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/core_v1_api.py", line 12463, in list_namespaced_config_map_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 328, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 160, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 281, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 629, in __deserialize_model
    setattr(instance, attr, self.__deserialize(value, attr_type))
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1_config_map_list.py", line 108, in items
    raise ValueError("Invalid value for `items`, must not be `None`")
ValueError: Invalid value for `items`, must not be `None`

So I added the following part as workaround:

except ValueError:
    # no config maps found
    pass

I wanted to ask if this behaviour is wanted, actually I thought the items list would be empty like this if there are no existing config maps:

{"api_version": "v1",
 "items": null,
 "kind": "ConfigMapList",
 "metadata": {"resource_version": "3049",
              "self_link": "/api/v1/namespaces/quobyte/configmaps"}}

How to reproduce:

execute api_instance.list_namespaced_config_map(namespace, pretty=True) on an namespace without config maps.

Thanks!

1.0.0-beta.1 release

I am going to do another release soon now that kubernetes 1.5 is out. We don't expect to change the interface at all at this point and there could be some bug fixes before 1.0.0 release.

Let me know if you have any suggestions/concerns.

version names, next release should be 1.0.1-whatever

the versions released look weird to me. See https://www.python.org/dev/peps/pep-0440/

how are you getting the latest installed?

sudo pip3 install -v -v --upgrade --pre kubernetes

Getting page https://pypi.python.org/simple/kubernetes/
URLs to search for versions for kubernetes in /usr/local/lib/python3.4/dist-packages:
* https://pypi.python.org/simple/kubernetes/
Analyzing links from page https://pypi.python.org/simple/kubernetes/
  Found link https://pypi.python.org/packages/07/09/afd16baa9623eb1fd5436957b25b7438b4ea00dff91af8a1c9007bc0a910/kubernetes-1.0.0a3-py2.py3-none-any.whl#md5=1149a59d7d087d5858c1e04a1a1ab5b1 (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0a3
  Found link https://pypi.python.org/packages/2a/a2/9ae68644fcb0d93dc2275222c21fd8c2e49a61353328dfa90161bdec2e4e/kubernetes-1.0.0a5-py2.py3-none-any.whl#md5=8266196f912c98232aba589c0feee48b (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0a5
  Found link https://pypi.python.org/packages/61/c1/68e7ca2b11545cc62d89a104a1a546ddc6eb7020010192f20122f517a335/kubernetes-1.0.0a4-py2.py3-none-any.whl#md5=ddb84f6e4eb276fdf4b25d5139c43f57 (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0a4
  Found link https://pypi.python.org/packages/98/60/4a434a088fb6d7fc3daefbebf89e79bcd14bb49a617b62fe9c667a81582e/kubernetes-1.0.0a2.tar.gz#md5=5f4bb4b47e0051b84b0c9815c8742768 (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0a2
  Found link https://pypi.python.org/packages/a2/bb/dd0fc10b51e251c88da54852eafeb673630313b1e5156d1633db476444f9/kubernetes-1.0.0a5.tar.gz#md5=bef4a6332c10c2a85d89da4ec36f6989 (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0a5
  Found link https://pypi.python.org/packages/ab/b3/d051e868c1aeb221b343aaca13fc0979ee9f86aeeb21aedd723f99e9aff3/kubernetes-1.0.0a4.tar.gz#md5=ac798a2e262e1a3268d49e588d61e3e2 (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0a4
  Found link https://pypi.python.org/packages/ed/cd/b867b4836f318550539b252bde8078fd515b407a058ed47b81834b6b176f/kubernetes-1.0.0-alpha.2.tar.gz#md5=df45611842dbb0f1ee4ce92cf657853c (from https://pypi.python.org/simple/kubernetes/), version: 1.0.0-alpha.2
Installed version (1.0.0-alpha.2) is most up-to-date (past versions: 1.0.0-alpha.2, 1.0.0a5, 1.0.0a5, 1.0.0a4, 1.0.0a4, 1.0.0a3, 1.0.0a2)

For now I requested the exact version:

pip3 install --upgrade 'kubernetes==1.0.0a5'

Maybe call the next release 1.0.1 to ensure it is considered newer.

Any reason for not using asyncio?

I'm wondering if asyncio was considered. If I wanted to write a Kubernetes controller/operator in Python using ThirdPartyResource, then an asynchronous programming model like aiohttp offers would definitely be a matter match than the blocking one from urllib.

I understand people have uses cases for a blocking client too, but that would be relatively easy to implement on top of an asynchronous one, while the other way around is harder.

add pylint to tox

following up on @marun's comment on #50:

Consider adding a linter check (e.g. flake8/pylint) to the tox configuration to catch these issues automatically.

`stat: can't specify None for path argument` when loading config from GKE cluster

The client appears to be unable to parse authentication information from GKE clusters.

The exception is being raised here: https://github.com/kubernetes-incubator/client-python/blob/master/kubernetes/config/kube_config.py#L185, when _load_cluster_info expects there to be a client-certificate key in the user dictionary.

With the GKE provider, my config looks like this:

{'auth-provider': {'name': 'gcp', 'config': {'expiry': datetime.datetime(2016, 12, 27, 22, 18, 24, 911838), 'access-token': '<redacted>'}}}

I also had to fix this in pykube, as follows: https://github.com/kelproject/pykube/pull/67/files. Would you accept a fix along those lines here too?

Here is the full stack trace:

Traceback (most recent call last):
  File "dns_controller.py", line 17, in <module>
    main()
  File "dns_controller.py", line 6, in main
    config.load_kube_config()
  File "/Users/paul/.virtualenvs/dns-controller/lib/python3.5/site-packages/kubernetes/config/kube_config.py", line 297, in load_kube_config
    client_configuration=client_configuration).load_and_set()
  File "/Users/paul/.virtualenvs/dns-controller/lib/python3.5/site-packages/kubernetes/config/kube_config.py", line 203, in load_and_set
    self._load_cluster_info()
  File "/Users/paul/.virtualenvs/dns-controller/lib/python3.5/site-packages/kubernetes/config/kube_config.py", line 187, in _load_cluster_info
    file_base_path=self._config_base_path).as_file()
  File "/Users/paul/.virtualenvs/dns-controller/lib/python3.5/site-packages/kubernetes/config/kube_config.py", line 82, in as_file
    if not os.path.isfile(self._file):
  File "/Users/paul/.virtualenvs/dns-controller/bin/../lib/python3.5/genericpath.py", line 30, in isfile
    st = os.stat(path)
TypeError: stat: can't specify None for path argument

int-or-string

support kubernetes custom format "int-or-string".

pip upgrade

The release notes mention that we need to uninstall the client before installing the new version.

Why not pip install --upgrade kubernetes ?

Support kube-config change context

Right now the load kube config function loads the default context. We should support loading other contexts and [maybe?] listing them.

[PROPOSAL] Add convenience function

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)

Consider removing watch_* operations

watch_* operations are deprecated in kubernetes in favor of "watch" query flag. Consider removing them from the swagger.json in the preprocessing step.

What needs to be done to get patch_namespaced_deployment to work?

I want to update the image for one of my containers in a deployment and it seems I can't provide an UnversionedPatch. Using a valid JSON patch string, or the strategic-merge string I use in kubectl ends up with variations of
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"json: cannot unmarshal string into Go value of type jsonpatch.Patch","code":500}

Am I doing something wrong or is this not implemented yet? The link to UnversionedPatch returns a 404 https://github.com/kubernetes-incubator/client-python/blob/master/kubernetes/docs/UnversionedPatch.md If it's not implemented I'd be happy to work on it.

Python client does not resolve relative paths in kubeconfig

When using relative paths in ~/.kube/config like this:

- cluster:
    certificate-authority: certs/cfm.ca.crt

The following error message is thrown:

kubernetes.client.rest.ApiException: (0)
Reason: SSLError
[Errno 2] No such file or directory

Additionally it would be nice when in case of a No such file or directory error, the tried path would be shown. 😃

cannot create resources

I tried to create a few things, here is an example to create a namespace:

import k8sclient
from k8sclient.rest import ApiException
import time

from pprint import pprint

k8sclient.configuration.host="http://127.0.0.1:8001"

api_instance=k8sclient.CoreV1Api()

body = k8sclient.V1Namespace() # V1Namespace | 
body.metadata = k8sclient.V1ObjectMeta()
body.metadata.name = "foobar"
body.spec = k8sclient.V1NamespaceSpec()
body.status = k8sclient.V1NamespaceStatus()

print body

try: 
    api_response = api_instance.create_core_v1_namespace(body)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling CoreV1Api->create_core_v1_namespace: %s\n" % e)

I just cannot get passed the content type error, even though reading the API docs I have all the right type and struct in place:

$ ./podcreate.py 
{'metadata': {'annotations': None,
              'cluster_name': None,
              'creation_timestamp': None,
              'deletion_grace_period_seconds': None,
              'deletion_timestamp': None,
              'finalizers': None,
              'generate_name': None,
              'generation': None,
              'labels': None,
              'name': 'foobar',
              'namespace': None,
              'owner_references': None,
              'resource_version': None,
              'self_link': None,
              'uid': None},
 'spec': {'finalizers': None},
 'status': {'phase': None}}
Exception when calling CoreV1Api->create_core_v1_namespace: (0)
Reason: Cannot prepare a request message for provided arguments.
                             Please check that your arguments match declared content type.

Same type of error when trying to create a pod. I get this on a v1.4.0 endpoint

any suggestions ?

Support multi-watch

@mml suggested that a multi-watcher would be a nice addition to the Watch Class. I could be a simple multi-threading class that uses existing Watch operations or we can think of something more elegant.

Models <-> Json/Yaml

In addition to fully wrapping the k8s client and replacing kubectl, I've found it very useful to be able to generate raw JSON/YAML for objects created using the swagger generated schema models.

This makes a few other deployment methods easier, such as Spread or Helm.

Thoughts on whether it's worth adding to this project, and where the cleanest place would be? Seems like it should likely be some utility functions in the model layer, rather than patching the client (unless there's a built-in way of doing this with the swagger-codegen client).

Figure out how to get a release in Pypi

I am not sure how the account setup is going to be handled.

I have my own account in pypi where I could upload this, but there may be an official kubernetes/google way of making this happen.

Move generated readme to /docs

I would suggest moving the generated README to something like /docs

And make the README.prefix the main README

Otherwise it is a very long file.

It should also containe instructions on how to build the new client

V1ConfigMapKeySelector missing name field?

I'm trying to give environment variables to a V1Container constructor, and particularly I want those environment variables to come from a config map. In yaml it would look like:

env:
  - name: MY_ENV_VAR
    valueFrom:
      configMapKeyRef:
          name: myconfigmap
          key: foo

However, the V1ConfigMapKeySelector that is expected in the constructor of V1EnvVarSource only takes a 'key' argument, not the 'name' argument. Is this a change in the API or am I using the wrong types? My apologies if I've misunderstood! The same issue seems to apply to V1SecretKeySelector too.

SSL verification on python2.7 failing

I saw a commit flying by that said this was fixed but I get:

>>> import os
>>> config.load_kube_config(os.environ["HOME"] + '/.kube/config')
>>> v1=client.CoreV1Api()
>>> ret = v1.list_pod_for_all_namespaces(watch=False)
2016-11-23 10:26:29,195 ERROR Certificate did not match expected hostname: 192.168.99.100. Certificate: {'subjectAltName': (('DNS', 'kubernetes.default.svc.cluster.local'), ('DNS', 'kubernetes.default.svc'), ('DNS', 'kubernetes.default'), ('DNS', 'kubernetes'), ('IP Address', '192.168.99.100'), ('IP Address', '10.0.0.1')), 'notBefore': u'Nov 16 09:38:49 2016 GMT', 'serialNumber': u'02', 'notAfter': 'Nov 16 09:38:49 2017 GMT', 'version': 3L, 'subject': ((('commonName', u'minikube'),),), 'issuer': ((('commonName', u'minikubeCA'),),)}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "kubernetes/client/apis/core_v1_api.py", line 14377, in list_pod_for_all_namespaces
    (data) = self.list_pod_for_all_namespaces_with_http_info(**kwargs)
  File "kubernetes/client/apis/core_v1_api.py", line 14475, in list_pod_for_all_namespaces_with_http_info
    collection_formats=collection_formats)
  File "kubernetes/client/api_client.py", line 326, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "kubernetes/client/api_client.py", line 150, in __call_api
    _request_timeout=_request_timeout)
  File "kubernetes/client/api_client.py", line 349, in request
    headers=headers)
  File "kubernetes/client/rest.py", line 222, in GET
    query_params=query_params)
  File "kubernetes/client/rest.py", line 199, in request
    raise ApiException(status=0, reason=msg)
kubernetes.client.rest.ApiException: (0)
Reason: SSLError
hostname '192.168.99.100' doesn't match either of 'kubernetes.default.svc.cluster.local', 'kubernetes.default.svc', 'kubernetes.default', 'kubernetes', '192.168.99.100', '10.0.0.1'

Make a release script with a consistent behavior on different enviroment

Problem: We have two identical package for alpha2 in pypi with different names.

diagnosis: That is because we build and release the same thing on different environments (linux vs osx, different version of python).

Solution: we need to have a script to make sure the environment we are making release on, is consistent. Probably running release inside a docker container is the best solution.

add verify-* scripts

Kubernetes has a number of hack/verify-*.sh scripts that some of them may be useful here. For example, to prevent #15 we could adopt kubernetes's hack/verify-boilerplate.sh. This is the issue to track efforts on finding relevant verify scripts and add them to client-python.

Support API calls with no json response

Some of the calls like logs does support json and text response but there is no way to get the text response as the generated client automatically select json as the accepted response. One example of this is kubernetes/kubernetes#37881. The workaround in that issue is working (and shows the value of _preload_content we added to generated code) but we can do better by having a solution like Watch class to get response as text and even stream the result if the call supports it. In this case read_namespaced_pod_log supports streaming but the parameter is named follow not watch.

Possible Solution:

v1 = client.CoreV1Api()
# either:
raw = kubernetes.raw_response.RawResponse(v1.read_namespaced_pod_log, 
    namespace="...", name="...")
raw.read()

# or
raw = kubernetes.raw_response.RawResponse(v1.read_namespaced_pod_log, 
    namespace="...", name="...", follow=True)
for line in raw.stream():
   print(line)

Exec calls

Whenever I try to open an exec call I get:

{
  "kind":"Status",
  "apiVersion":"v1",
  "metadata":{},
  "status":"Failure",
  "message":"Upgrade request required",
  "reason":"BadRequest","code":400
}

Which is related with the fact that requests is not SPDY compatible. Are you going to support this kind of requests in the near future?

1.0.0-alpha Release

To get the client adapted more, I plan to do a 0.1.0 1.0.0-alpha release and push it to pypi.
Pre-release:

  • in-cluster config support #32
  • rename package to kubernetes #31

release items:

  • github release tag
  • Pypi push (automated on releases somehow?)

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.