mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 22:20:18 +00:00
Make updates atomic from the client side.
This commit is contained in:
@@ -192,12 +192,10 @@ func (c *Client) CreatePod(pod api.Pod) (result api.Pod, err error) {
|
||||
|
||||
// UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs
|
||||
func (c *Client) UpdatePod(pod api.Pod) (result api.Pod, err error) {
|
||||
var prev api.Pod
|
||||
err = c.Get().Path("pod").Path(pod.ID).Do().Into(&prev)
|
||||
if err != nil {
|
||||
if pod.ResourceVersion == 0 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", pod)
|
||||
return
|
||||
}
|
||||
pod.ResourceVersion = prev.ResourceVersion
|
||||
err = c.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(&result)
|
||||
return
|
||||
}
|
||||
@@ -222,12 +220,10 @@ func (c *Client) CreateReplicationController(controller api.ReplicationControlle
|
||||
|
||||
// UpdateReplicationController updates an existing replication controller
|
||||
func (c *Client) UpdateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) {
|
||||
var prev api.ReplicationController
|
||||
err = c.Get().Path("replicationControllers").Path(controller.ID).Do().Into(&prev)
|
||||
if err != nil {
|
||||
if controller.ResourceVersion == 0 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", controller)
|
||||
return
|
||||
}
|
||||
controller.ResourceVersion = prev.ResourceVersion
|
||||
err = c.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(&result)
|
||||
return
|
||||
}
|
||||
@@ -251,12 +247,10 @@ func (c *Client) CreateService(svc api.Service) (result api.Service, err error)
|
||||
|
||||
// UpdateService updates an existing service.
|
||||
func (c *Client) UpdateService(svc api.Service) (result api.Service, err error) {
|
||||
var prev api.Service
|
||||
err = c.Get().Path("services").Path(svc.ID).Do().Into(&prev)
|
||||
if err != nil {
|
||||
if svc.ResourceVersion == 0 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", svc)
|
||||
return
|
||||
}
|
||||
svc.ResourceVersion = prev.ResourceVersion
|
||||
err = c.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(&result)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user