Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
2282f9ce
Commit
2282f9ce
authored
Aug 01, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #737 from brendandburns/atomic
Make updates atomic from the client side.
parents
10a577a9
1101c000
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
18 deletions
+42
-18
kubecfg.go
cmd/kubecfg/kubecfg.go
+30
-1
client.go
pkg/client/client.go
+6
-12
client_test.go
pkg/client/client_test.go
+6
-5
No files found.
cmd/kubecfg/kubecfg.go
View file @
2282f9ce
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"text/template"
"text/template"
"time"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kube_client
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
kube_client
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
...
@@ -202,6 +203,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
...
@@ -202,6 +203,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
validStorage
:=
checkStorage
(
storage
)
validStorage
:=
checkStorage
(
storage
)
verb
:=
""
verb
:=
""
setBody
:=
false
setBody
:=
false
var
version
uint64
switch
method
{
switch
method
{
case
"get"
:
case
"get"
:
verb
=
"GET"
verb
=
"GET"
...
@@ -225,6 +227,15 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
...
@@ -225,6 +227,15 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
glog
.
Fatalf
(
"usage: kubecfg [OPTIONS] %s <%s>"
,
method
,
prettyWireStorage
())
glog
.
Fatalf
(
"usage: kubecfg [OPTIONS] %s <%s>"
,
method
,
prettyWireStorage
())
}
}
case
"update"
:
case
"update"
:
obj
,
err
:=
s
.
Verb
(
"GET"
)
.
Path
(
path
)
.
Do
()
.
Get
()
if
err
!=
nil
{
glog
.
Fatalf
(
"error obtaining resource version for update: %v"
,
err
)
}
jsonBase
,
err
:=
api
.
FindJSONBase
(
obj
)
if
err
!=
nil
{
glog
.
Fatalf
(
"error finding json base for update: %v"
,
err
)
}
version
=
jsonBase
.
ResourceVersion
()
verb
=
"PUT"
verb
=
"PUT"
setBody
=
true
setBody
=
true
if
!
validStorage
||
!
hasSuffix
{
if
!
validStorage
||
!
hasSuffix
{
...
@@ -238,7 +249,25 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
...
@@ -238,7 +249,25 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
Path
(
path
)
.
Path
(
path
)
.
ParseSelector
(
*
selector
)
ParseSelector
(
*
selector
)
if
setBody
{
if
setBody
{
r
.
Body
(
readConfig
(
storage
))
if
version
!=
0
{
data
:=
readConfig
(
storage
)
obj
,
err
:=
api
.
Decode
(
data
)
if
err
!=
nil
{
glog
.
Fatalf
(
"error setting resource version: %v"
,
err
)
}
jsonBase
,
err
:=
api
.
FindJSONBase
(
obj
)
if
err
!=
nil
{
glog
.
Fatalf
(
"error setting resource version: %v"
,
err
)
}
jsonBase
.
SetResourceVersion
(
version
)
data
,
err
=
api
.
Encode
(
obj
)
if
err
!=
nil
{
glog
.
Fatalf
(
"error setting resource version: %v"
,
err
)
}
r
.
Body
(
data
)
}
else
{
r
.
Body
(
readConfig
(
storage
))
}
}
}
result
:=
r
.
Do
()
result
:=
r
.
Do
()
obj
,
err
:=
result
.
Get
()
obj
,
err
:=
result
.
Get
()
...
...
pkg/client/client.go
View file @
2282f9ce
...
@@ -192,12 +192,10 @@ func (c *Client) CreatePod(pod api.Pod) (result api.Pod, err error) {
...
@@ -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
// 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
)
{
func
(
c
*
Client
)
UpdatePod
(
pod
api
.
Pod
)
(
result
api
.
Pod
,
err
error
)
{
var
prev
api
.
Pod
if
pod
.
ResourceVersion
==
0
{
err
=
c
.
Get
()
.
Path
(
"pod"
)
.
Path
(
pod
.
ID
)
.
Do
()
.
Into
(
&
prev
)
err
=
fmt
.
Errorf
(
"invalid update object, missing resource version: %v"
,
pod
)
if
err
!=
nil
{
return
return
}
}
pod
.
ResourceVersion
=
prev
.
ResourceVersion
err
=
c
.
Put
()
.
Path
(
"pods"
)
.
Path
(
pod
.
ID
)
.
Body
(
pod
)
.
Do
()
.
Into
(
&
result
)
err
=
c
.
Put
()
.
Path
(
"pods"
)
.
Path
(
pod
.
ID
)
.
Body
(
pod
)
.
Do
()
.
Into
(
&
result
)
return
return
}
}
...
@@ -222,12 +220,10 @@ func (c *Client) CreateReplicationController(controller api.ReplicationControlle
...
@@ -222,12 +220,10 @@ func (c *Client) CreateReplicationController(controller api.ReplicationControlle
// UpdateReplicationController updates an existing replication controller
// UpdateReplicationController updates an existing replication controller
func
(
c
*
Client
)
UpdateReplicationController
(
controller
api
.
ReplicationController
)
(
result
api
.
ReplicationController
,
err
error
)
{
func
(
c
*
Client
)
UpdateReplicationController
(
controller
api
.
ReplicationController
)
(
result
api
.
ReplicationController
,
err
error
)
{
var
prev
api
.
ReplicationController
if
controller
.
ResourceVersion
==
0
{
err
=
c
.
Get
()
.
Path
(
"replicationControllers"
)
.
Path
(
controller
.
ID
)
.
Do
()
.
Into
(
&
prev
)
err
=
fmt
.
Errorf
(
"invalid update object, missing resource version: %v"
,
controller
)
if
err
!=
nil
{
return
return
}
}
controller
.
ResourceVersion
=
prev
.
ResourceVersion
err
=
c
.
Put
()
.
Path
(
"replicationControllers"
)
.
Path
(
controller
.
ID
)
.
Body
(
controller
)
.
Do
()
.
Into
(
&
result
)
err
=
c
.
Put
()
.
Path
(
"replicationControllers"
)
.
Path
(
controller
.
ID
)
.
Body
(
controller
)
.
Do
()
.
Into
(
&
result
)
return
return
}
}
...
@@ -251,12 +247,10 @@ func (c *Client) CreateService(svc api.Service) (result api.Service, err error)
...
@@ -251,12 +247,10 @@ func (c *Client) CreateService(svc api.Service) (result api.Service, err error)
// UpdateService updates an existing service.
// UpdateService updates an existing service.
func
(
c
*
Client
)
UpdateService
(
svc
api
.
Service
)
(
result
api
.
Service
,
err
error
)
{
func
(
c
*
Client
)
UpdateService
(
svc
api
.
Service
)
(
result
api
.
Service
,
err
error
)
{
var
prev
api
.
Service
if
svc
.
ResourceVersion
==
0
{
err
=
c
.
Get
()
.
Path
(
"services"
)
.
Path
(
svc
.
ID
)
.
Do
()
.
Into
(
&
prev
)
err
=
fmt
.
Errorf
(
"invalid update object, missing resource version: %v"
,
svc
)
if
err
!=
nil
{
return
return
}
}
svc
.
ResourceVersion
=
prev
.
ResourceVersion
err
=
c
.
Put
()
.
Path
(
"services"
)
.
Path
(
svc
.
ID
)
.
Body
(
svc
)
.
Do
()
.
Into
(
&
result
)
err
=
c
.
Put
()
.
Path
(
"services"
)
.
Path
(
svc
.
ID
)
.
Body
(
svc
)
.
Do
()
.
Into
(
&
result
)
return
return
}
}
...
...
pkg/client/client_test.go
View file @
2282f9ce
...
@@ -154,7 +154,7 @@ func TestCreatePod(t *testing.T) {
...
@@ -154,7 +154,7 @@ func TestCreatePod(t *testing.T) {
func
TestUpdatePod
(
t
*
testing
.
T
)
{
func
TestUpdatePod
(
t
*
testing
.
T
)
{
requestPod
:=
api
.
Pod
{
requestPod
:=
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
,
ResourceVersion
:
1
},
CurrentState
:
api
.
PodState
{
CurrentState
:
api
.
PodState
{
Status
:
"Foobar"
,
Status
:
"Foobar"
,
},
},
...
@@ -219,7 +219,7 @@ func TestGetController(t *testing.T) {
...
@@ -219,7 +219,7 @@ func TestGetController(t *testing.T) {
func
TestUpdateController
(
t
*
testing
.
T
)
{
func
TestUpdateController
(
t
*
testing
.
T
)
{
requestController
:=
api
.
ReplicationController
{
requestController
:=
api
.
ReplicationController
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
,
ResourceVersion
:
1
},
}
}
c
:=
&
testClient
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"PUT"
,
Path
:
"/replicationControllers/foo"
},
Request
:
testRequest
{
Method
:
"PUT"
,
Path
:
"/replicationControllers/foo"
},
...
@@ -388,11 +388,12 @@ func TestCreateService(t *testing.T) {
...
@@ -388,11 +388,12 @@ func TestCreateService(t *testing.T) {
}
}
func
TestUpdateService
(
t
*
testing
.
T
)
{
func
TestUpdateService
(
t
*
testing
.
T
)
{
svc
:=
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"service-1"
,
ResourceVersion
:
1
}}
c
:=
&
testClient
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"PUT"
,
Path
:
"/services/service-1"
,
Body
:
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"service-1"
}}
},
Request
:
testRequest
{
Method
:
"PUT"
,
Path
:
"/services/service-1"
,
Body
:
&
svc
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"service-1"
}}
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
&
svc
},
}
}
response
,
err
:=
c
.
Setup
()
.
UpdateService
(
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"service-1"
}}
)
response
,
err
:=
c
.
Setup
()
.
UpdateService
(
svc
)
c
.
Validate
(
t
,
&
response
,
err
)
c
.
Validate
(
t
,
&
response
,
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment