Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Req: Example for deployment rollback #427

Closed
gangadhars opened this issue Jan 10, 2018 · 6 comments
Closed

Req: Example for deployment rollback #427

gangadhars opened this issue Jan 10, 2018 · 6 comments

Comments

@gangadhars
Copy link

gangadhars commented Jan 10, 2018

Hi,

When I tried to rollback to last revision, getting below error:

Traceback (most recent call last):
  File "deployment_examples.py", line 111, in <module>
    main()
  File "deployment_examples.py", line 105, in main
    rollback_deployment(extensions_v1beta1)
  File "deployment_examples.py", line 86, in rollback_deployment
    body=body)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/apis/extensions_v1beta1_api.py", line 273, in create_namespaced_deployment_rollback
    (data) = self.create_namespaced_deployment_rollback_with_http_info(name, namespace, body, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/apis/extensions_v1beta1_api.py", line 364, in create_namespaced_deployment_rollback_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 321, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 163, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/models/extensions_v1beta1_deployment_rollback.py", line 65, in __init__
    self.name = name
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/models/extensions_v1beta1_deployment_rollback.py", line 137, in name
    raise ValueError("Invalid value for `name`, must not be `None`")
ValueError: Invalid value for `name`, must not be `None`

Below is snippet that generating error:

def rollback_deployment(api_instance, revision=0):
    rollback_to = client.AppsV1beta1RollbackConfig(revision)
    body = client.AppsV1beta1DeploymentRollback(
        name=DEPLOYMENT_NAME,
        rollback_to=rollback_to)
    api_response = api_instance.create_namespaced_deployment_rollback(
        name=DEPLOYMENT_NAME,
        namespace="default",
        body=body)
    print("Deployment rolled back. status='%s'" % str(api_response.status))

You can find the complete code at https://pastebin.com/yNkA85ub

Could you please provide the example for rollback of a deployment?

@cristifalcas
Copy link

I think that the new deployment needs another name

@gangadhars
Copy link
Author

Sorry! @cristifalcas . Pasted the wrong exception. Now updated with correct exception.

@gangadhars
Copy link
Author

gangadhars commented Jan 18, 2018

After debugging little more, problem is not with request. Deployment is successfully rollbacked to previous version.

$ kubectl rollout history deploy -n default
deployments "nginx-app"
REVISION  CHANGE-CAUSE
2         <none>
3         <none>=

kubernetes client is failing may be because of the rollback response is different that other responses

{u'status': u'Success', u'kind': u'Status', u'code': 200, u'apiVersion': u'v1', u'message': u'rollback request for deployment "nginx-app" succeeded', u'metadata': {}}

Is this already a known bug?

@roycaihw
Copy link
Member

It's a problem in k8s openapi spec. This client is generated based on the openapi spec in every k8s release. A PR is in progress here kubernetes/kubernetes#56591. Closing

@prasad1991
Copy link

w = watch.Watch()
print w
for event in w.stream(v1.list_namespaced_pod,"default"):
if event['object'].status.phase == "Pending" and event['object'].spec.scheduler_name == scheduler_name:
# print event['object']
r1 = event['object'].metadata.name
#print event['object'].namespace
print r1
pod = client.V1Pod()
pod.api_version="v1"
pod.kind="Pod"
pod.metadata=client.V1ObjectMeta(name=r1)
container= client.V1Container()
print container

    print client
    container.name="redis"
    container.image= "redis"
    container.priorityClassName="high-priority"
    spec=client.V1PodSpec()
    spec.containers=[container]
    pod.spec=spec
    print pod
    try:
         v1.create_namespaced_pod(name=event['object'].metadata.name,namespace="default",body=pod,_preload_content=False)
    except ValueError:
         print('pass it')

i am getting error
Traceback (most recent call last):
File "custome.py", line 151, in
container= client.V1Container()
File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/models/v1_container.py", line 123, in init
self.name = name
File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/models/v1_container.py", line 350, in name
raise ValueError("Invalid value for name, must not be None") # noqa: E501
ValueError: Invalid value for name, must not be None

@roycaihw
Copy link
Member

@prasad1991 At a glance the error is unrelated to this issue. Please file a separate issue

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants