mnubo / kubernetes-py

A python module for Kubernetes.
Apache License 2.0
123 stars 46 forks source link

update a service #30

Closed adiri closed 7 years ago

adiri commented 8 years ago

I tried to add a selector and update() a service and I get the following:

kubernetes.K8sExceptions.UnprocessableEntityException: K8sObject: UPDATE failed: HTTP 422 : Service "myservice" is invalid: [metadata.resourceVersion: Invalid value: "": must be specified for an update, spec.clusterIP: Invalid value: "": field is immutable, spec.ports: Required value]

Here is my code:

from kubernetes import K8sConfig, K8sService

configuration = K8sConfig()
service = K8sService(config=configuration, name='myservice')
service.add_selector(selector=dict(newkey="newvalue"))
service.update()
froch commented 8 years ago

Hello, thank you for taking the time to raise this issue. I'm unable to reproduce your problem here locally:

service = K8sService(config=configuration, name='myservice')
service.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
service.create()
service.add_selector(selector=dict(newkey="newvalue"))
service.update()
$ kubectl describe service myservice
Name:           myservice
Namespace:      default
Labels:         name=myservice
Selector:       newkey=newvalue
Type:           ClusterIP
IP:         10.0.0.152
Port:           redis   5432/TCP
Endpoints:      <none>
Session Affinity:   None
No events.

How exactly are you using the module? What versions are you using?

adiri commented 8 years ago

Your example also works for me. maybe it's because k8s-py created it. The service was already created by me (manually with a YAML file).

I’m using k8s 1.3.6.

this is a description of both services:

20:43:26-root@mymachine:~$ kubectl describe service myservice
Name:           myservice
Namespace:      default
Labels:         name=myservice
Selector:       newkey=newvalue
Type:           ClusterIP
IP:         100.71.120.89
Port:           redis   5432/TCP
Endpoints:      <none>
Session Affinity:   None
No events.
20:43:35-root@mymachine:~$ kubectl describe service mgfdjapps
Name:           serviceThatNotWorking
Namespace:      default
Labels:         app=serviceThatNotWorking
            tier=frontend
Selector:       app=serviceThatNotWorking-8f7f4d3b73ffa0c67bd76208dcdac574656216f8
Type:           LoadBalancer
IP:         100.67.75.92
LoadBalancer Ingress:   amazonelbaddr.us-west-2.elb.amazonaws.com
Port:           <unset> 80/TCP
NodePort:       <unset> 31125/TCP
Endpoints:      100.96.3.23:8000,100.96.4.22:8000
Session Affinity:   None
No events.
sebastienc commented 7 years ago

Is this still an issue? Can you give us a code snippet that's failing?

Thanks.

adiri commented 7 years ago

Yup, still happen. the code snippet is already pasted in the first initial comment. I'm trying to edit a service that I create without the lib. the service description was also pasted on Oct 12. I can show you that live if you want. contact me personally.

MaikuMori commented 7 years ago

Randomly stumbled on this, even though I'm not using the library. I think the problem is related to kubernetes/kubernetes#26202. Basically once created using kubectl apply, it has annotation with default values which on subsequent updates don't work.

sebastienc commented 7 years ago

Thanks @MaikuMori, I haven't managed to reproduce it on my end. @adiri Does it matches your issue?

froch commented 7 years ago

Closing this thread due to inactivity. This is not a problem with the kubernetes-py module.