mnubo / kubernetes-py

A python module for Kubernetes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

update a service

adiri opened this issue · comments

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()

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?

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.

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

Thanks.

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.

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.

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

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